By representing an orientation (or rotation) by a complex number instead of an explicit angle we can drop a fair number of expensive operations. So instead of storing angle &amp;#039;a&amp;#039;, we store complex number (cos(a), sin(a)).
Another potential advantage is the algebra framework (just manipulating algebra) and reasoning. Algebra&amp;#039;s like complex number, vectors, quaternions, etc allow thinking in terms of relative information which can greatly simplify the process.
We will assume that standard mathematical convention of the X axis pointing the to right and the Y axis pointing up. Additionally we will assume that the reference orientation of objects is pointing straight right. Combining these together when thinking about some specific entity, we can think in terms of its center being at the origin and its facing straight down the X axis.
NOTE: Although angles are talked about, this is for understanding and thinking purposes and not computation.
[b]Common definitions[/b]
Capital letter are complex number and small are scalars.[tt]
X=(a,b)
Y=(c,d)
P=(x,y)
R=(cos(a), sin(a))
S=(cos(b), sin(b))
[/tt]
[bh2]Addition/Subtraction[/b][tt]
X+Y = (a,b)+(c,d) = (a+c,b+d)
X-Y = (a,b)-(c,d) = (a-c,b-d)[/tt]
Component-wise, can represent translation.
[b]Magnitude (L[sub]2[/sub] norm)[/b]
[tt]|X| = |(a,b)| = sqrt(a[sup]2[/sup]+b[sup]2[/sup])[/tt]
Notice that we&amp;#039;re not calling this lex ngtumber basics[/h. 2]
Complex numbers are represented by two numbers, vwhich wectors,etcwill do enot have lengthas (nor positions). What they represent in a gpaivr [tt](a,b)[/tt]. The finrstancumber we mwight have a length equal to its magnitude.
[b]Unit compalel &amp;#039;x&amp;#039; and trig form[/b]
Unit complex numbers have a magnitudse of cone and can be written in &amp;#039;trig formy&amp;#039;:
[tt](cos(t),sin(t))[/tt].
Since scale factors can be pulled out (see scalar product) all complex numbers can also be written in &amp;#039;trig form&amp;#039;:
[tt]m(cos(t),sin(t))[/tt].
[b]Conjugate[/b]
[tt]X[sup]*[/sup] = (a,b)[sup]*[/sup] = (a,-b)[/tt]
[tt]R[sup]*[/sup] = (cos(a),sin(a))[sup]*[/sup] = (cos(a),-sin(a)) = (cos(-a),sin(-a))
[/tt]
So the conjugate reflects ([url=http://en.wikipedia.org/wiki/Reflection_%28mathematics%29]wikipedia[/url]) about the X axis, which is the same as negating the angular information. (SEE: [url=http://en.wikipedia.org/wiki/Trigonometric_identity#Symmetry.2C_shifts.2C_and_periodicity]Trig identities: Symmetry[/url])[b]Addition/Subtraction[/b][tt]
X+Y = (a,b)+(c,d) = (a+c,b+d)
X-Y = (a,b)-(c,d) = (a-c,b-d)[/tt]
Operation is component-wise. Can represent translation.
[b]Product[/b][tt]
XY = (a,b)(c,d)
= (ac-bd, ad+bc)
RP = (cos(a), sin(a))(x,y)
= (x cos(a) - y sin(a), y cos(a) + x sin(a))
RS = (cos(a), sin(a))(cos(b), sin(b))
= (cos(a)cos(b) - sin(a)sin(b), cos(b)sin(a) + cos(a)sin(b))
= (cos(a+b), sin(a+b))[/tt]
So the product sums the angular information of the two inputs. (SEE: [url=http://en.wikipedia.org/wiki/Trigonometric_identity#Symmetry.2C_shifts.2C_and_periodicity]Trig identities: angle sum[/url])
[b]Product combined with conjugate[/b][tt]
X[sup]*[/sup]Y = (a,b)[sup]*[/sup](c,d) = (a,-b)(c,d) = (ac+bd, ad-bc)
R[sup]*[/sup]S = (cos(a),sin(a))[sup]*[/sup](cos(b),sin(b))
= (cos(-a),sin(-a))(cos(b),sin(b))
= (cos(a)cos(b)+sin(a)sin(b), -cos(b)sin(a)+cos(a)sin(b))
= (cos(b-a),sin(b-a))[/tt]
Since we can add angles with the product and can negate an angle with the conjugate, the two together allow us to subtract angles. (AKA get relative angular information)
[b]Magnitude (L[sub]2[/sub] norm)[/b]
[tt]|X| = |XX[sup]*[/sup]| = |(a,b)(a,-b)| = sqrt(a[sup]2[/sup]+b[sup]2[/sup])[/tt]
Notice that we&amp;#039;re not calling this length. Complex numbers, vectors, etc do not have lengths (nor positions). What they represent in a give instance might have a length equal to its magnitude.
[b]Unit complex and trig form[/b]
Unit complex numbers have a magnitude of one and can be written in &amp;#039;trig form&amp;#039;:
[tt](cos(t),sin(t))[/tt].
Since scale factors can be pulled out (see scalar product) all complex numbers can also be written in &amp;#039;trig form&amp;#039;:
[tt]m(cos(t),sin(t))[/tt].
[b]Scalar product[/b]
[tt]sX = s(a,b) = (s,0)(a,b) = (sa, sb)[/tt]
This can be reversed, so all scale factors can be pulled out.
[b]Inverse[/b][tt]
1/X = X[sup]*[/sup]/(XX[sup]*[/sup]) = (a,-b)/(a[sup]2[/sup]+b[sup]2[/sup])
1/R = (cos(-a),sin(-a))/(cos(a)[sup]2[/sup]+sin(a)[sup]2[/sup])
= (cos(-a),sin(-a))
= R[sup]*[/sup][/tt]
The multiplicative inverse of a unit complex is the same as its conjugate.
[b]Counterclockwise rotation of point about the origin[/b]
Falls directly out of the product. Given rotation (R) and point (P), the point after rotation (P&amp;#039;):[tt]
P&amp;#039; = RP
= (cos(a), sin(a))(x,y)
= (x cos(a) - y sin(a), y cos(a) + x sin(a))[/tt]
Example:[tt]
P = (3,3)
R = (cos(pi/4), sin(pi/4)) = (.707107, .707107)
P&amp;#039; = (3,3)*(.707107, .707107)
= (0, 4.24264)[/tt]
[b]How do I find rotation of A into B[/b]
Solve the above. Assuming A &amp;amp; B are unit vectors:[tt]
RA = B
R = B(1/A)
R = BA[sup]*[/sup][/tt]
Example:[tt]
A = (0.809017, 0.587785)
B = (0.5, -0.866025)
R = BA[sup]*[/sup]
= (0.5, -0.866025)(0.809017, 0.587785)[sup]*[/sup]
= (0.5, -0.866025)(0.809017, -0.587785)
= (-0.104528, -0.994522)[/tt]
[b]Counterclockwise rotation of point about arbitrary point[/b]
We can rotate about the origin, to rotate about an arbitrary point (C) translate the system to the origin, perform the rotation and then undo the translation.[tt]
P&amp;#039; = R(P-C)+C
= RP-RC+C
= RP+C-RC
= RP+C(1-R)
= RP+T[/tt]
where [tt]T = C(1-R)[/tt]. Look at the last line. It is telling you that the rotation R about point C is equivalent to a rotation about the origin R followed by a translation T. And C is recoverable from T &amp;amp; R: [tt]C = T/(1-R)[/tt] (assuming R isn&amp;#039;t 1...or no rotation).
[b]Composition of rotations[/b]
Falls directly out of the product. Given rotation (R) followed by rotation (S):
[tt]RS = (cos(a+b), sin(a+b))[/tt]
[b]Relation to dot and cross products[/b]
Falls directly from the product where one is conjugated:
[tt]X[sup]*[/sup]Y = (a,b)[sup]*[/sup](c,d) = (a,-b)(c,d) = (ac+bd, ad-bc)[/tt]
[tt]dot(X,Y) = ac+bd[/tt]
[tt]cross(X,Y) = ad-bc[/tt]
The dot product is the parallel projection and the cross is the orthogonal projection.
[h2]Basicexamples[/h2]
AtFrom the top we say we can represent an entity by its position and orientation and think about it as being at the origin and facing straight down the X axis (the reason for this is because that&amp;#039;s the entity&amp;#039;s local coordinate frame).
Let&amp;#039;s call it&amp;#039;s position E and orientation F and we have some test point P. We can translate the system to the origin [tt](P-E)[/tt] and then we can undo the rotation of the system by multiplying by [tt]F[sup]*[sup][/tt], which gives us: [tt](P-E)F[sup]*[/sup][/tt]. So P in the reference frame of our entity is:
[tt]P&amp;#039; = (P-E)F[sup]*[/sup][/tt]
Example:[tt]
P = (100,100)
E = (200,200)
F = (.92388, .382683) &amp;lt;- Pi/8 or 22.5 degrees
P&amp;#039; = ((200,200)-(100,100))(.92388, -.382683)
= (130.656, 54.1196)[/tt]
If you&amp;#039;ve ever worked with vectors, this should seem similar: find the delta distance and perform the dot and/or cross product. The above equation is finding the delta distance and then effectively computing both. (Obviously you only compute one if only need one). So the dot product is simply the &amp;#039;x&amp;#039; coordinate in the local coordinate frame (parallel projection) and the cross is the &amp;#039;y&amp;#039; coordinate (orthogonal projection).
[b]What&amp;#039;s my unit direction vector?[/b]
It&amp;#039;s pretending the unit complex numbersperspective considerf the [tt]R[sup]*[/sup]S[/tt] compurientation is a unit vector. It has the same numeric values for &amp;#039;x&amp;#039; &amp;amp; &amp;#039;y&amp;#039;.
[b]Is it behind me?[/b]
As noted above the dot product is &amp;#039;x&amp;#039; in the local combordinate frame, so the sign of the dot product. If negative it&amp;#039;s behind the center point with respect to facing and positive if forward.
[b]Turn clockwise or counterclockwise?[/b]
As noted above the cross product is &amp;#039;y&amp;#039; in the local coordinate frame, so the sign of the cross product. If positive the shortest turn is counter clockwise, if negative it&amp;#039;s clockwise and if zero it&amp;#039;s straight ahead.
[b]Turn toward point with constant angular velocity[/b]
Again, the sign of cross product tells the minimum direction. Take a constant angular velocity, store as a unit complex number &amp;#039;A&amp;#039;. If the sign of the cross product is negative, we need to conjugate A (negate it&amp;#039;s &amp;#039;y&amp;#039; component). Multiply the current facing &amp;#039;F&amp;#039; by the potentially modified &amp;#039;A&amp;#039;. Take our new &amp;#039;F&amp;#039; and cross again. If the sign has changed, we&amp;#039;ve overshot the target.XXX

By representing an orientation (or rotation) by a complex number instead of an explicit angle we can drop a fair number of expensive operations. So instead of storing angle 'a', we store complex number (cos(a), sin(a)).

Another potential advantage is the algebra framework (just manipulating algebra) and reasoning. Algebra's like complex number, vectors, quaternions, etc allow thinking in terms of relative information which can greatly simplify the process.

We will assume that standard mathematical convention of the X axis pointing the to right and the Y axis pointing up. Additionally we will assume that the reference orientation of objects is pointing straight right. Combining these together when thinking about some specific entity, we can think in terms of its center being at the origin and its facing straight down the X axis.

NOTE: Although angles are talked about, this is for understanding and thinking purposes and not computation.

Common definitionsCapital letter are complex number and small are scalars. X=(a,b) Y=(c,d) P=(x,y) R=(cos(a), sin(a)) S=(cos(b), sin(b))

Complex number basics

Complex numbers are represented by two numbers, which we will denote as a pair (a,b). The first number we will call 'x' and the second 'y'.

The multiplicative inverse of a unit complex is the same as its conjugate.

Counterclockwise rotation of point about the originFalls directly out of the product. Given rotation (R) and point (P), the point after rotation (P'):P' = RP = (cos(a), sin(a))(x,y) = (x cos(a) - y sin(a), y cos(a) + x sin(a))

Counterclockwise rotation of point about arbitrary pointWe can rotate about the origin, to rotate about an arbitrary point (C) translate the system to the origin, perform the rotation and then undo the translation.P' = R(P-C)+C = RP-RC+C = RP+C-RC = RP+C(1-R) = RP+T

where T = C(1-R). Look at the last line. It is telling you that the rotation R about point C is equivalent to a rotation about the origin R followed by a translation T. And C is recoverable from T & R: C = T/(1-R) (assuming R isn't 1...or no rotation).

Composition of rotationsFalls directly out of the product. Given rotation (R) followed by rotation (S):RS = (cos(a+b), sin(a+b))

Relation to dot and cross productsFalls directly from the product where one is conjugated:X*Y = (a,b)*(c,d) = (a,-b)(c,d) = (ac+bd, ad-bc)

dot(X,Y) = ac+bdcross(X,Y) = ad-bc

The dot product is the parallel projection and the cross is the orthogonal projection.

Basic examples

At the top we say we can represent an entity by its position and orientation and think about it as being at the origin and facing straight down the X axis (the reason for this is because that's the entity's local coordinate frame).

Let's call it's position E and orientation F and we have some test point P. We can translate the system to the origin (P-E) and then we can undo the rotation of the system by multiplying by F*, which gives us: (P-E)F*. So P in the reference frame of our entity is:

If you've ever worked with vectors, this should seem similar: find the delta distance and perform the dot and/or cross product. The above equation is finding the delta distance and then effectively computing both. (Obviously you only compute one if only need one). So the dot product is simply the 'x' coordinate in the local coordinate frame (parallel projection) and the cross is the 'y' coordinate (orthogonal projection).

What's my unit direction vector?It's pretending the unit complex number of the orientation is a unit vector. It has the same numeric values for 'x' & 'y'.

Is it behind me?As noted above the dot product is 'x' in the local coordinate frame, so the sign of the dot product. If negative it's behind the center point with respect to facing and positive if forward.

Turn clockwise or counterclockwise?As noted above the cross product is 'y' in the local coordinate frame, so the sign of the cross product. If positive the shortest turn is counter clockwise, if negative it's clockwise and if zero it's straight ahead.

Turn toward point with constant angular velocityAgain, the sign of cross product tells the minimum direction. Take a constant angular velocity, store as a unit complex number 'A'. If the sign of the cross product is negative, we need to conjugate A (negate it's 'y' component). Multiply the current facing 'F' by the potentially modified 'A'. Take our new 'F' and cross again. If the sign has changed, we've overshot the target.

This wiki entry has had 5 revisions with contributions from 1 members.
(more info)

Really for representing angles you can keep it much simpler. Forget useless definitions like complex numbers don't have length. Who cares? You can interpret them as a vector, in which case they do. They are just a vector pointing in the direction they represent.

By some fluke of math, complex multiplication is the same as adding angles. Division is subtracting angles. Pure interpolation with normalization works well enough for interpolation. The real part is the same as cos, the imaginary part the same as sin. tan=sin/cos. To compare to angles we use the fact that atan2(x,y) >=< tan2(x',y') is the same as comparing y/x to y'/x'. Just take care of the degen you get with x tending to 0 and really compare yx' to y'x and you get the same result. Now you can check to see if something is withing a bracketed set of angles.

Perhaps i should expand a little. But really i don't even follow the why of what is the previous post.

I have no special talents. I am only passionately curious.--Albert Einstein

Some suggesting on how to make it easier to understand would be helpful. This is a wiki page and I certainly won't cry if you modify it. To address some of your points.

Why mention length != mag? Because un-learning stuff you've learned wrong is hard and lots of text say vectors have lengths and/or are centered at the 'origin' and make it sound like direction and position vectors are somehow different things. And I've seen people struggle to unlearn stuff they've mis-learned. Personally I had a heck of of time unlearning that the cross product of vectors in 3-space isn't a vector and wish someone would has said something like: "the cross product of two vectors is a bi-vector. What's a bi-vector? Something we're going to pretend is a vector for the moment. Don't worry about it for now, just keep this is the back of your head.". But having said that, I don't have any strong opinion about keeping that sentence...it's simply my reasoning for having there in the first place.zZ

Quote

By some fluke of math, complex multiplication is the same as adding angles. Division is subtracting angles.

I don't like black boxes. You give people black-boxes they're stuck with what you've spoon feed them. As examples, consider the three reflection implementations from my toy complex class: here. Or the rectangle vs. point and circles intersection tests.

Quote

Pure interpolation with normalization works well enough for interpolation.

Here I assume you mean for angle parametrization: lerp instead of slerp. While true for probably most cases, I'm of the opinion that it's better to understand how slerp works and want you get if you straight lerp instead. As an example, a many entity game could have a simulation rate as low as 10 Hz, with smoothing on the rendering side. Straight lerp is highly likely to cause noticeable defects. Of course this is easy to fix, but you only can if you understand how the parts work.

Quote

The real part is the same as cos, the imaginary part the same as sin.

I like to avoid using "real" and "imaginary" as I find terminology is a source of confusion. Forget "i".

Quote

To compare to angles we use the fact that atan2(x,y) >=< tan2(x',y') is the same as comparing y/x to y'/x'. Just take care of the degen you get with x tending to 0 and really compare yx' to y'x and you get the same result.

I think it's really hard to understand without any pictures describing what is going on. I have to do this in my mind and that only works if I have already understood it. It's the Bret-Victor-Syndrom I'm talking about Someone made a really nice intro to Complex numbers and why they can be used to represent sqrt(-1) and how we should picture them:

Think about integers for a second. We start with 0 (or 1 depending on who to talk to) and they're formed by repeatedly adding 1. Each time giving you the next number in the sequence. Then you get wild-and-crazy and extend the concept to extend in the negative direction. Negative numbers! What? You can't say have a negative number of cows!! Madness! At least to the ancient greek math-heads it was...they didn't have the concept. Now jump to complex numbers. Constructed by using two instead of one number where the 'second' has a magic basis that squares to -1. Placing special "meaning" to the sqrt(-1) in complex numbers is the same as placing special meaning to subtracting 1 in integers. Neither are interesting as operations. The sqrt(-1) is meaningless in reals just as you can't give away a cow you don't have.

Unless you are among the federal farmers, which can accumulate cow-depth by loaning imaginary cows to peasants, skimming off the milk for profits.

</offtopic>

In other news: blasting newbies with a 'succinct specification' is a sure way to turn them off. It doesn't really matter whether you are correct, if your audience can't follow your step by step reasoning. A few visualisations will help enlighten them, but given the amount of work required, and the already available resources on the internet, I doubt anybody here would be willing to make the effort.

Hi, appreciate more people! Σ ♥ = ¾Learn how to award medals... and work your way up the social rankings!

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org