Vector direction between two arbitrary points.

View: New views
6 Messages — Rating Filter:   Alert me  

Vector direction between two arbitrary points.

by java3d-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have two points

p = {x1,y1,z1}
q = {x2,y2,z2}

Between the two points (Shape3d) I am drawing a line.

I want to add a Cone to the end of the line so show
what direction the "arrow" (=line+cone) is pointing.

How can I easily with everything included in j3d+vecmath
calculate a Rotation Matrix, quaternion(s) or rotation angles along each axis
to rotate the cone the right direction?

I have started implementing code for this but there must be an easier way
with every included.

Thanks
[Message sent by forum member 'polski' (polzki@...)]

http://forums.java.net/jive/thread.jspa?messageID=370316

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: Vector direction between two arbitrary points.

by java3d-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I found a solution. I had lost countless hours already trying to solve this.
I was close but still not there.

Credit goes to Paul Pantera
http://www.mail-archive.com/java3d-interest@.../msg24712.html
[Message sent by forum member 'polski' (polzki@...)]

http://forums.java.net/jive/thread.jspa?messageID=370509

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: Vector direction between two arbitrary points.

by java3d-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Something like :

[code]
public Transform3D rotate(Transform3D target, Tuple3d p, Tuple3d q){
               
                Vector3d vec = new Vector3d();
                vec.sub(p,q);
                vec.normalize();
               
                target.setEuler(vec);
                return target;
   }
[/code]
[Message sent by forum member 'zesharp' (zando.silva@...)]

http://forums.java.net/jive/thread.jspa?messageID=370515

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: Vector direction between two arbitrary points.

by java3d-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I wish it was as easy as you posted it. Can you get that to work?
Without doing the math, just cut and paste it does not work.

This is how I ended up doing it.

public static Transform3D rotate(double px, double py, double pz, double qx, double qy, double qz) {
                Vector3d tempVec = new Vector3d();
                Vector3d crossVec = new Vector3d();
                Vector3d YAXIS = new Vector3d(0,1,0); // Up unit vector
                Transform3D tempTrans = new Transform3D();
                Transform3D tempTrans2 = new Transform3D();
                AxisAngle4d tempAA = new AxisAngle4d();
                 
                tempVec.set(qx-px,qy-py,qz-pz);
            tempVec.normalize();
            crossVec.cross(YAXIS, tempVec);
            tempAA.set(crossVec, (double)java.lang.Math.acos(YAXIS.dot(tempVec)));
            tempTrans.set(tempAA);
               
            tempTrans2.setIdentity();
            tempTrans2.setTranslation(new Vector3d(qx,qy,qz));
            tempTrans2.mul(tempTrans);
           
                return tempTrans2;
        }

This is basically the code given in the link above in my previous post.
[Message sent by forum member 'polski' (polzki@...)]

http://forums.java.net/jive/thread.jspa?messageID=371138

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: Vector direction between two arbitrary points.

by java3d-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nice job !

>Can you get that to work?
Yes, my code snippet works for me, but it is in the middle of others transforms.
Perhaps it works because I always think about 3D rotations as Euler angles :D
But you didn't mention you like to translate it to q position ;)

I'll put you code on my code snippet libs , Thanks !
[Message sent by forum member 'zesharp' (zando.silva@...)]

http://forums.java.net/jive/thread.jspa?messageID=371140

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: Vector direction between two arbitrary points.

by Don Casteel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Try...   Transform3D.lookAt(Vector3D vec)
 
I haven't actually been following this thread, but if you don't have an acceptable solution so far, it might help to Google "transforming between coordinate systems in 3D".
 
To summarize, a 4x4 matrix transform can be defined to transform from any coordinate space to any other coordinate space.
 
 
There is a lot of good content at the above site, if you dig around enough you should be able to figure out how to create a transform to do exactly what you are trying to do.
 
 



From: "java3d-interest@..." <java3d-interest@...>
To: interest@...
Sent: Mon, November 9, 2009 6:06:52 AM
Subject: Re: Vector direction between two arbitrary points.

Nice job !

>Can you get that to work?
Yes, my code snippet works for me, but it is in the middle of others transforms.
Perhaps it works because I always think about 3D rotations as Euler angles :D
But you didn't mention you like to translate it to q position ;)

I'll put you code on my code snippet libs , Thanks !
[Message sent by forum member 'zesharp' (zando.silva@...)]

http://forums.java.net/jive/thread.jspa?messageID=371140

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...