I Need a math formula for this issue.
-
I'm creating a game and I need to rotate this object. Ok i'll make my explanation simple, I have Object1 and Object2.. Let's say Object1 is at coordinates 0,0 (x,y) and Object 2 is at coordinates 10,10... Object 1 is currently facing south, Now I need object 1 to be facing Object 2 so I need the "degree" value from object 1 to object 2. Does anyone have a math formula for getting the degree? or an alternative solution can help.
-
I'm creating a game and I need to rotate this object. Ok i'll make my explanation simple, I have Object1 and Object2.. Let's say Object1 is at coordinates 0,0 (x,y) and Object 2 is at coordinates 10,10... Object 1 is currently facing south, Now I need object 1 to be facing Object 2 so I need the "degree" value from object 1 to object 2. Does anyone have a math formula for getting the degree? or an alternative solution can help.
Hi, imagine a rectangular triangle with your two points on the hypotenuse, and the two perpendicular sides parallel to the axes. The angles you want have tangent or cotangent equal to deltaY/deltaX, so you need something similar to
Math.Atan2(deltaY,deltaX)
. However, are you sure you need the angle? Trigonometric functions are rather expensive, and a lot of graphic stuff does not need them after all, often something much simpler can do the trick as in Math.Sqrt(deltaX*deltaX+deltaY*deltaY) for the distance, and similar stuff for projections and stuff. :)Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
-
Hi, imagine a rectangular triangle with your two points on the hypotenuse, and the two perpendicular sides parallel to the axes. The angles you want have tangent or cotangent equal to deltaY/deltaX, so you need something similar to
Math.Atan2(deltaY,deltaX)
. However, are you sure you need the angle? Trigonometric functions are rather expensive, and a lot of graphic stuff does not need them after all, often something much simpler can do the trick as in Math.Sqrt(deltaX*deltaX+deltaY*deltaY) for the distance, and similar stuff for projections and stuff. :)Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
-
Luc Pattyn wrote:
imagine a rectangular triangle
I'm trying - really I am.
If I knew then what I know today, then I'd know the same now as I did then - then what would be the point? .\\axxx (That's an 'M')