Skip to main content
gamedev.net
🔒 Locked

Matrix2.Angle -- Correct?

Started by Riddle Jan 11, 2005 at 2:23 PM 1 replies 300+ views
Original Post
Riddle
Riddle
Hello guys! I just want to know if my Matrix2.Angle property is correct. It should return the angle(rad) to the identity matrix. Thank you. :) #region Angle /// Returns the angle to the Idendity-Matrix. /// public Type Angle { get { return calc.Acos( calc.Div( m00, calc.Sqrt( calc.Add( calc.Mul( m00, m00 ), calc.Mul( m01, m01 ) )))); } } #endregion Angle I have to use a calculator because im using C# generics that don't support numeric operation on generic Types. Would look like that normally: return Acos( m00 / Sqrt( m00 * m00 + m01 * m01 ) ); Thank you very much!
blizzard999
blizzard999
In general a change base is simply a matrix in which you report the components of the new frame relative to the identity.
For example in 2D if you have

x' = vector(a, b)
y' = vector(c, d)

the matrix should be

a b
c d

if you evaluate the scalar product between x' and x you get

i) x' * x = |x'| * |x| * cos(angle)

where |.| is the len that is

|x| = 1
|x'| = sqrt(a^2 + b^2)

if we use the components we can also write

ii) x' * x = (a,b)*(1,0) = a*1 + b*0 = a

from i) and ii)

cos(angle) = a/sqrt(a^2+b^2)

that is

angle = acos(a/sqrt(a*a+b*b))

So your solution seems correct...

NOTE: I'm quite sure that the matrix is correct however it may be the transpose (in this case simply use m10 instead of m01...)

NOTE2: This may be not a problem if your vectors are normalized (no scaling)...in this case you have simply
angle = acos(a)
blizzard999
blizzard999
We can also deduce that if M is a 2D rotation matrix its form is

 c  s-s  cwhere       c = cos(angle)       s = sin(angle)  angle = "the angle between x' and x (positive if x' rotates CCW)"


so angle = acos(c) = acos(m[0][0])

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.