PDA

View Full Version : How to Translate and Rotate axes to match a vector



RChemuturi
02-09-2011, 08:47 PM
Hello All,

I am trying to draw an arrow to represent a vector. I have two points with (x,y,z) coordinates of the vector. I have been searching the forums to draw an arrow which suggest the best way is to draw using three lines.
Now coming to my problem, I can draw the main arrow line joining the two coordinates I have, but drawing the two small lines at the tip is challenging.
The idea I settled down with is translating and rotating the axes to match the vector as one of the axes. I can calculate the angle but without the sign of the angle, so not sure in which direction I need to rotate.
Any suggestions as to how can I do this?! My ultimate goal is to draw an arrow along the vector as a representation. Is translation & rotation a good idea or is there a better way to achieve this?

Thanks in advance

MaxH
02-09-2011, 10:56 PM
Is translation & rotation a good idea or is there a better way to achieve this? I find scaling, translating, and rotating to be an easy way to do what you're trying to do. Write a subroutine that makes a 3D arrow, one unit long, going down the X axis, with it's tail at the origin, and it's tip at (1,0,0). You can use gluCylinder twice to do that - once for the shaft and once for the tip. Then scale, rotate, and translate that arrow to go between your 2 points.

RChemuturi
02-10-2011, 09:32 PM
Thank you MaxH.
I am trying to reproduce your solution, will post back once done.

RChemuturi
02-18-2011, 06:27 AM
I did work out, but had to do some complicated math to calculate the angle of rotation.
Also there are some sites offerring ready-written code for rendering a cylinder given two points (coordinates of two points). Created the code myself, also planning to try the codes available on web to cross-check mine.
Thank you for all the help

MaxH
02-18-2011, 01:01 PM
I did work out, but had to do some complicated math to calculate the angle of rotation. You have to do some trig or some vector operations. It's good that you worked it out for yourself.