Oh, and from what I interpreted, I came up with the three sides and their length:
proc/get_angle(atom/A,atom/B)
var {X=abs(A.x-B.x);Y=abs(A.y-B.y)}
var/Hypotenuse=round(sqrt((X*X)+(Y*Y)))
var/Adjacent=X
var/Opposite=Y
Is that correct?
ID:169218
Jul 19 2005, 2:14 am
|
|
I've been trying to write a procedure for getting the angle from point A to point B, but I haven't been able to find any decent tutorials/formulas/graphs on the web. Well, I did find one but I had accidently closed it and could not find it again. So if anyone would teach me right-angle trigonometry it'd be great. :-)
Oh, and from what I interpreted, I came up with the three sides and their length: proc/get_angle(atom/A,atom/B) Is that correct? |
In response to Dark Weasel
|
|
So arcsin(o/h) would return my angle? Thanks. :-)
|
In response to Crashed
|
|
Yeah that sounds like what I used to use when calculating the turn points for my units in the old Battle System add on for AD&D, back when I used to play.
|
In response to Crashed
|
|
I just tried, and it nearly works. I had edited atom/Click() to show the angle get_angle returns, when I click at the top of the screen in a straight line infront of me it'll return 90 (which is good), and in a straight line to the right it returns 0 (good), but when I click at the top right corner, it should return 45 degrees but instead it returns 48.5904. What would be my problem?
Edit: Actually, this isn't working properly. I'll click on an area that should equal to about 80ish degrees but it's still 90, and I'll click on a tile over that one and it's still 90. For about 4 tiles it'll still return 90 degrees. |
In response to Crashed
|
|
Take out the round(). You can add a round() when you display the angle, if you don't want decimals.
If you compared 1,1 and 2,2, you'd come out with 2.236 as a hypotenuse. Then you'd divide 2 by it, which'd give you .894. You'll get an angle of 63.438 when arcsin()ing that, but if you rounded the hypotenuse to 2, you'd come out with 1, and you'd get a 90 degree angle when arcsin()ing it. |
The sin of an angle is the value of the opposite/hypontenuse
Arcsin is the opposite function of sin. So you would do...
return arcsin(Opposite/Hypotenuse)
I think that should do it. I've only learned basic trig so far.