Finding Angles
BlitzMax Forums/BlitzMax Programming/Finding Angles
| ||
Hello. I need to find an angle to the top-left part of my screen from a random point on the screen. I believe that this should work:Angle = PosY/PosX Angle = 180-ATan(Angle) but doesnt :( The reason for what i have done is that i worked out from anywhere on the screen i have a triangle like: ____ \ | \ | \x| \| And the opposite and adjacent sides are my x and y co-ords. So i use the Tan-1 funtion to work out angle x which is the angle if you start at the top of the screen anti-clockwise. So as angles start from the bottom of the screen clockwise i get the angle i need (y) by taking the angle away from 180: \x| \| y| | But this doesn't work. I'm not very good at this sort of stuff so there may be something i've done wrong in he calculations. If there is anyone good at maths out at there that can help me i'd be very grateful. (and i hoped my diagrams helped :)) |
| ||
this might help: http://homeworktips.about.com/library/weekly/aa120497.htm http://www.mathstutor.com/Trigonometry(i).html http://sacademy.cbv.ns.ca/grsrts/protec12.2/math.htm |
| ||
Basic trigonomotry remember the great Indian cheif SOHCAHTOA: Sine Opposite Hypotinus Cosine Adjacent Hypotinus Tangent Opposite Adjacent Sin( a ) = Opposite / Hypotinus Cos( a ) = Adjacent / Hypotinus Tan( a ) = Opposite / Adjacent look up trigonomitry stuff on google if i am incomprehensible. |
| ||
ATan2( y, x ) gives the angle for a vector from 0,0 to x,y. The assumption is that the X axis is 0° and Y is 90°. Compared to this you have X,Y swapped: X axis is 90° and Y is 0°. And you are going the opposite way, from x,y to 0,0. So you want ATan2( -x, -y ). Or something. Just tinker with it until you get the effect you want. |
| ||
Ok, thanks for all the help. Btw, we were taugh it as: Some Old Hippos Can Always Have Tons Of Apples |
| ||
Here's the Function I use for calculating the angle from one point to another:Function calcAngle2D( x1, y1, x2, y2 ) Local angle:Int=ATan2( ( y2 - y1 ), ( x2 - x1 ) ) + 180 Return angle:Int End Function Muttley |