Trig and Invert question

BlitzMax Forums/BlitzMax Beginners Area/Trig and Invert question

Ant(Posted 2005) [#1]
Basically what I am trying to do is calculate the angle between an origin point and the mouse position.

I have a function which declares an origin and establishes the opposite and adjacent (and therefore you can calculate the hypotenuse) of the triangle.

I then divide the opposite by the hypotenuse to give me the sine of the angle I ma trying to get. I then want to invert this to give me the actual angle, but there is no invert function in BMax?

Does anyone have any suggestions or easier ways to achieve this?
cheers


FlameDuck(Posted 2005) [#2]
I then want to invert this to give me the actual angle, but there is no invert function in BMax?
Yeah, there is. It's called ASin (arcus sinus).

Does anyone have any suggestions or easier ways to achieve this?
ATan((y1-y0)/(x1-x0)), or ATan2((y1-y0),(x1-x0)).


Diablo(Posted 2005) [#3]
working example of flame ducks suggestion:
Graphics 800, 600, 0, 60

SeedRnd(MilliSecs())

Global oy = Rand(0, GraphicsHeight())
Global ox = Rand(0, GraphicsWidth())

While Not KeyHit(KEY_ESCAPE)
	Cls
	
	DrawOval ox - 5, oy - 5, 10, 10
	
	angle = ATan2(ox - MouseX(), oy - MouseY()) + 180
	DrawLine ox, oy, MouseX(), MouseY()
	DrawText angle, 10, 10
	
	Flip
Wend



Ant(Posted 2005) [#4]
Thanks fellas, fantastic