Angle issue

BlitzMax Forums/BlitzMax Beginners Area/Angle issue

Kanati(Posted 2011) [#1]
I've been trying to find the problem here for a while and I don't get it...

        X = X + (Velocity * Cos(Direction / 180.0 * Pi))
        Y = Y + (Velocity * Sin(Direction / 180.0 * Pi))



I've used the above formula in vb.net to update a sprite's position. But in bmax instead of 360 degrees for a circle, my direction variable goes to somewhere around 20500 for a full circle.

I don't get it. All variables, btw are doubles, though I've used floats as well.


col(Posted 2011) [#2]
Looks like you're converting from Degress to Radians, but BlitzMax trigonimic functions take Degrees as the parameter, not Radians.

Is 'Direction' representing radians or degress in your code?

If its Degrees then use :-
X = X + (Velocity * Cos(Direction))
Y = Y + (Velocity * Sin(Direction))


Otherwise if its Radians then use this to convert to degrees -
X = X + ( Velocity * ( Cos( Direction * 180.0 / Pi ) )
Y = Y + ( Velocity * ( Sin( Direction * 180.0 / Pi ) )

Although I suspect there may errors elsewhere in your code ( maybe still the same issue ) as using the correct value for the parameter will actually make the X and Y values even higher.

Last edited 2011


Kanati(Posted 2011) [#3]
Nope that was it. I was using radians.

I'm definitely not a math guy. I learn as much math as I need for the task at hand. :)


dynaman(Posted 2011) [#4]
Don't feel bad, I had this same problem a few times. Other languages expect Radians where Blitz expects degrees - I prefer degrees - but it still throws me from time to time.


Kanati(Posted 2011) [#5]
Yeah I prefer degrees as well. And it's been too long since I was using BMax or I would have known better. :D


col(Posted 2011) [#6]
Hehe
I reckon this one must have caught EVERY Blitz programmer at least once!

:D