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!
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)
With your permission, GameDev.net uses analytics cookies to understand how people use the platform.
You can accept analytics or continue with necessary cookies only.
Learn more