Help with math formula

Blitz3D Forums/Blitz3D Beginners Area/Help with math formula

Jeeps(Posted 2007) [#1]
Hi
I know what all the varibles are in this equation except for angle. could someone help me restructure this formula to find the angle varible.

extendedpointx# = centerpointx# + ( Cos#(angle#) * distance# )
extendedpointy# = centerpointy# + ( Sin#(angle#) * distance# )

Thanks


Floyd(Posted 2007) [#2]
The angle should be

ATan2( extendedpointy - centerpointy, extendedpointx - centerpointx )


Jeeps(Posted 2007) [#3]
Thanks Floyd

This formula gave me a 0 to -180 and 0 to 180.

Do you know how to make the output 0 to 360?

Thanks for your help!


Floyd(Posted 2007) [#4]
If the result is negative then add 360.


Nexus6(Posted 2007) [#5]
Is this the same as Dot product, or is that different? The reason i ask is, I'm looking for a formula to find the angle between 3 points.

Sorry to hijack your post Jeeps


H&K(Posted 2007) [#6]
the angle between 3 vectors
There is no angle between 3 vectors, unless two of the vectors point the same way.


Nexus6(Posted 2007) [#7]
Sorry, I meant points.


Stevie G(Posted 2007) [#8]
That's effectively the same as finding the angle between 2 vectors. Dot product is what your looking for :

Angle# = Acos ( ( V1 dot V2 ) / ( Length V1 * Length V2 ) )

Where V1 dot V2 = V1\x * V2\x + V1\y * V2\y


Stevie


Nexus6(Posted 2007) [#9]
Thanks Stevie.


Jeeps(Posted 2007) [#10]
Thanks Floyd

I have incorporated the formula into my game and it works great!!!!


Mr Snidesmin(Posted 2007) [#11]
If the result is negative then add 360.


or just use Mod:

ATan2( extendedpointy - centerpointy, extendedpointx - centerpointx )  Mod 360



big10p(Posted 2007) [#12]
In that case, I think you have to add 360 to the result, before applying the Mod 360...