# 3D Theory - Forum Question

 By: Martin Baker (martinbaker) - 2007-10-13 09:07 Hi Lewie,    Looks like you are nearly there, I'm not sure exactly what the problem is but a couple of things occurred to me on first reading your message:  > each triangle has an origin and two vectors (variables named “edge1” and “edge2”)    This seems to imply that you are rotating each triangle in its own axis and then adjusting the origin? I guess it could be done that way but, if I have understood correctly, I think you may be making things unnecessarily hard for yourself?    I think what is usually done is: the vertices of each triangle are stored in the coordinate system of the object you are transforming. If we assume you are modelling, say an aircraft, then choose a coordinate system, x along the fuselage, y along the wing or whatever. Then encode all the vertices for that object in that coordinate system directly. Then to rotate that object multiply each vertex(vector) by the rotation matrix to give the transformed vertex(vector). This rotates the whole object around its origin. You can then offset the aircraft to be where you want on the screen by adding a fixed vector to each vertex (or equivalently by using a 4x4 matrix as you describe).    I strongly agree with you that it is best to avoid Euler angles if possible. Sometimes there are angles implied in the situation itself, for example in the case of an aircraft, the control surfaces imply rotation around certain axis. In this case I think you are doing the right thing in converting the angle information to matrix form as soon as possible. I guess the thing to keep in mind is that, when combining rotations, order is important. So if you want yaw then roll then pitch then yaw you will need a different matrix than if you want yaw then pitch then roll, these angles are relative to the aircraft not the ground.    Rather than go on and write a long message about all the things that could be wrong, perhaps I should check with you to see if I am on the right track?    Martin

 By: Martin Baker (martinbaker) - 2007-10-14 10:54 Lewie,    > My understanding is that axis-angle is encoded as an axis, which is a 3D  > vector (x,y,z) describing the way that the object is pointed, and an angle,  > which is a rotation about the axis. If it was an aeroplane, the axis would  > run along the middle of the fuselage and the plane would be banking  > according to the angle. Am I right so far?    Yes quite right.    > Query 1:  Yes, you are right, I think the thing to keep in mind is that the quaternion defines a 3D rotation only, its not trying to store any other information. This is actually an advantage, a rotation of 0deg around the x-axis represents the same rotation as 0deg around the y-axis, so its good that they are represented by the same quaternion. In the case of axis-angle the axis is redundant when the angle is zero, so we don't have to avoid it, we can just set the axis to an arbitrary value.  If you need to know the direction of the fuselage: you take the vector representing its direction before it has been rotated say,  v = 0,0,1  (this will depend on the coordinate system and the initial orientation of the aircraft)  Its position after the rotation is:  v2 = q*v*q'      > Query (2)  > The information given is angle=90, axis=0,1,0. How is this so?    Again axis-angle is only intended to represent a 3D rotation. So this represents a ninety degree rotation around the y-axis. This rotation only defines the position of the fuselage relative to its position before rotation.    > Your next diagram is of a plane pointing left, and now the axis has not  > changed from the last one (still 0,1,0) but the angle is 180. The  > movement between the 1st and 2nd diagrams is the same as between  > the 2nd and 3rd diagrams,     The diagrams are supposed to represent the rotation relative to the aircrafts initial position (when angle = zero) not relative to the position shown next to it. I should have made that clearer on the page.    > Query (3)    Same again, each picture is relative to its position before it has been rotated.    I would welcome any ideas to improve the web pages clearer, I'll put a better explanation on the diagrams of aeroplane orientation, let me know if there is anything else that I can do?  Also I'm sure lots of people who are new to the subject will have similar questions to these, so I would like to put a link to this thread, if that's all right with you?    Martin

 By: HJL (hjl2) - 2007-10-14 11:27 By all means, you can let anyone else in on this discussion if you wish.    I understand your reply to query(1) - thanks.    I think I get the answer to my other queries... It would seem that the values describing a rotation make more sense if you know where you started from, because the end result of a rotation is always relative to some previous orientation. Any given orientation has an infinite number of possible rotations that led to that state.    Regarding the programming, what I have now is an object in space that I can rotate any way I like using the controls. Unfortunately when I try to tilt the camera is all gets a bit twisted, for reasons I have not yet figured out. But... it's sunday evening, it's time to switch off... I'll get back to this one next week.    Lewie

This site may have errors. Don't use for critical systems.