Basic question, a beginner !

Hi,

can somebody tell me when this formula can be used, where can I get more information about it?

dir_x = Math.cos(alpha*(Math.PI/180));
dir_y = Math.sin(alpha*(Math.PI/180));

ball.pos_x+=dir_x …
ball.pos_y+=dir_y …

regards
Alvaro

Looks like an equation to generate a unit circle, what do you actually want it to do?

You use it when calculating the x/y translation when you have a angle of direction given in degrees [0,360].

Did I get the question right?

/me slaps forehead
Oh yeah, convert an angle to a vector, that makes more sense. I had assumed that the alpha meant it was being interpolated over, instead its actually an input angle.

Guessing the question is still the tricky part though :wink:

Okay, while we’re playing some kind of bizzare Jeopardy, try this:

Programmer Tom is writing some code and uses the decimal number 1597463007. What is his method likely intended to do? ;D

Random number generator :slight_smile:

Kev

Thats fundemental trig. Try any trigonometry textbook.

Alpha is your angle of direction in degrees. pi/180 is a conversion from degress to radians, which is what all of the trig functions want.

sin == opposite/hypotenuse == Y part of that angle (assuming a total movement of 1, hypotenuse is actually the total distance moved, opposite is the Y component.) Note that this assumes a
trig style coordinate system where poitive Y is at the top and negative Y at the bottom. if you are working in screen space you’ll need to reverse it.

cos == adjacent/hypotenuse == X part of that component.

So your simple answer is. given a ship position x,y and angle of motion alpha, that math calculates the new position if the ship moves 1 unit in alpha direction.

Basic trig. if you can’t handle this you will have a LOT of “fun” trying to write game code…

Btw…

This question has nothing to do with physcis and really belongs in “Newless Clubies” which is our total beginner topic.

thank Jeff, you give me the answer I was looking for. Your answer about radians makes completly sence.

regards

Glad I could help.

JK