bearings

BlitzMax Forums/BlitzMax Beginners Area/bearings

Cruis.In(Posted 2006) [#1]
how would I find the bearing of object B, from object A
without using a protractor. :)
I mean code in blitz. Do I have to find the sin cosin of the angle of that line between A and B?


A


B


bradford6(Posted 2006) [#2]
yes.

what you need to learn about is vectors.

I'll post a little demo program that might help you out. it is fairly straightforward.

first, when you say 'bearing' i take that to mean
" what angle would Object A be rotated to if Object A were Pointing at Object B"

give me 5 mins... maybe 10 :)


Cruis.In(Posted 2006) [#3]
yep that is what I mean.

so find the sin, cosin of that imaginary line between a and b then take it away from 360?


bradford6(Posted 2006) [#4]
this might be what you need:

blitzmax angles are -180 to 180 (360 degrees)


EDIT:



Cruis.In(Posted 2006) [#5]
ah yes, excellent, except that. it should calculate the A as zero all the time. because I want to get the bearing of B from A.

So when i move the pointer exact to the left of A it should read 270 degrees. Exactly above = zero, to the right of A = 90.

your code there is seeming to do it in half circles, as in from the right of A all the way to the left side of A = 180. But it should include the 90 degrees from the top of A until it reached the right of A.

so 90 + 180 = 270.


skidracer(Posted 2006) [#6]
for that result modify line 31:
		Local angle = ATan2(x2-x1,y1-y2)+180


The problem is computer graphics have y axis going down the screen where as usual cartesian graphs have the positive y axis pointing up.


bradford6(Posted 2006) [#7]
Thanks skid. I updated it in the codebox above.


Cruis.In(Posted 2006) [#8]
thanks guys :)

darn gurus... :P


Booticus(Posted 2006) [#9]
God I love it when folks post complete code examples!!! Thanks Skid and bradford6!!