   Using Quaternions for interpolating 2D rotations
  Hi,I'm programming a camera for my 2D game, and I was looking for an elegant way to handle the rotation aspect.Because it's only two-dimensional, I only need one value to represent the camera's orientation (namely, theta). But I need the camera's orientation to flow smoothly from here and there, and the discontinuity between 0 and 2*pi is causing some trouble. Does anyone here understand Quaternions enough to know if they can be applied in a 2 dimensional sense, so that the discontinuity can be handled automatically?From what I read, quaternions can do miracles in 3D space...but I was lost as soon as the article delved into complex numbers.Thanks a lot for your help.  -Cuppo   
  Yes, you can use quaternions this way, but it'd be really, really, overkill. For your 2D camera, you just need to calculate motion clockwise and counter clockwise and select the shorter route in your interpolations.   ;  It doesn't make sense to use quaternions for 2D rotations, but complex numbers will do the job. A rotation can be understood as a multiplication by a complex number of magnitude 1.However, the trigonometric approach works just fine because there is no equivalent of gimbal lock in dimension 2. Doing rotations with complex numbers can still be useful to solve certain Math problems, and also as a help to understand the relationship between quaternions and 3D rotations.;  Hi,I realize that what I'm doing is probably overkill. But I'm planning to write 3D games after I finish my 2D one, and I figured this is a good way to understand it.Alvaro, would you mind giving a quick example?ie. If I'm currently at 30 degrees and I want to rotate to 60, what complex number should I multiply to it?   ;  Rotations are represented by complex numbers with magnitude 1. In order to rotate 30 degrees you need to multiply by the complex number w = (cos(30 deg) + sin(30 deg) i) = (.8660254 + .5 i)The idea is that you use complex numbers to represent orientations. So if you are facing in the direction A=(.8660254 + .5 i) and you want to get to B=(.5 + .8660254 i), you can interpolate between those complex numbers to get intermediate positions. In order to do that, you make a parameter t go from 0 to 1, and you use the number (1-t)A+tB, which is in the segment connecting the two orientation vectors. This has the problem that the result is shorter than 1. You need to normalize the complex number (divide by its magnitude) to get to a number representing a rotation.Doing things this way is a little convoluted for 2D, but the situation with quaternions is very similar.;  Ahhhh....I see i see. It all makes sense now.Thanks for your help.PS: Just one extra consideration...If I interpolate the cos(Theta) and the sin(Theta) linearly, how does that affect Theta? Theta is not going to increase linearly. Does it look weird, or do I get special "whoosh" effect or something? =)Thanks for all your help.  -Cuppo   ;Quote:Original post by CuppoJavaIf I interpolate the cos(Theta) and the sin(Theta) linearly, how does that affect Theta? Theta is not going to increase linearly. Does it look weird, or do I get special "whoosh" effect or something? =)Well, if the initial angle and the final angle are not too far apart, you'll get something close to linear. If not, the angle will move slower at the extremes and faster in the middle.If you want to achieve linear increase in Theta (which is reasonable, but more expensive to compute), you need to use something called "slerp", which you can look up in Google or Wikipedia (or pretty much any article on using quaternions for rotations).;  Slerping in this case is NOT necessary. What you need instead is to use this observation:To interpolate from theta_1 to theta_2 smoothly without non-linear pathes in rotation rate, don't calculate an angle upfront.. Instead you can use a delta angle. The delta angle = dt * angular_velocity. So at each step you multiply your transform your view with a complex number corresponding to this delta (function of rotation rate and delta time)..This is also applicable in 3D when using matrices. As for quaternions, I am in the blur over here.