Recommended Posts

nGamer    184
I am attempting to program the physics into my game by first implementing velocity. I will have velocity as a vector, position as the x and y components, and I am using radians as the angle measure of the orientation of the objects. Now, in terms of trigonometry, velocity would be the length of the radius in a circle. However, if I am using radians, doesn't the angle measurement require a unit circle? That is, half of the circle is pi radians and one revolution is 2(pi) radians only if the radius is one. However, that would mean that the maximum speed I would be able to implement is one and that is not desirable. If a measure of one radian is equal to the angle measure of the arc that subtends the radius of any circle, and if that radian will revolve around the circumference of the circle 2(pi) times within a unit circle, can this apply also to a circle such that the radius is not one?

Share on other sites
jyk    2094

A radian is simply the angle swept out by a segment of a circle, the length of which is equal to the circle's radius; the exact value of the radius doesn't really matter. The length of the segment is proportional to the angle, but they're not the same thing; '2pi radians' is a full revolution whether the circle has a radius of one, or one thousand.

Again though, I'm not quite clear on how this relates to linear velocity (linear velocity is a vector value, and typically doesn't involve angles in any way).

Share on other sites
nGamer    184
Sorry about that, you see, in my game, objects have a speed. I could have implemented speed like this,

int speed = 4 ;

xPosition = xPosition -= speed ; // moving left
xPosition = xPosition += speed ; // moving right
yPosition = yPosition += speed ; // moving down
yPosition = yPosition -= speed ; // moving up

but I decided to have full 360 degrees-of-freedom movement.

So now, all that I have to do to calculate position is provide the direction (angle of the object) and the speed (length of the velocity vector) and

int speed = 4 ;
int objectAngle = 34 ;

xPosition = speed * (cos (objectAngle)) ;
yPosition = speed * (sin (objectAngle)) ;

Share on other sites
jyk    2094
Quote:
 xPosition = speed * (cos (objectAngle)) ;yPosition = speed * (sin (objectAngle)) ;
Did you mean '+='? (Also, '34' is an atypical value for an angle in radians - are you working in degrees?)

You can certainly do it that way, but again, the value of 'speed' (the 'radius' that you speak of) doesn't matter; the above method will work fine for any value of 'speed' (it can even be negative in the given context, which would result in 'backwards' motion).

[Edit: I see you're using ints for your variables. Typically you would floats for these kinds of computations, but maybe there are factors involved that aren't evident from your post.]

Share on other sites
Iirc, a unit circle is used in conjunction with the identity principle. X * 1 = X. Maximum speed would not be limited to one. You wrote "velocity would be the length of the radius in a circle" - iirc, velocity is the magnitude of the vector. The unit circle (et al) pertains to the direction of the vector, not it's magnitude.

Share on other sites
nGamer    184
Quote:
Original post by jyk
Quote:
 xPosition = speed * (cos (objectAngle)) ;yPosition = speed * (sin (objectAngle)) ;
Did you mean '+='? (Also, '34' is an atypical value for an angle in radians - are you working in degrees?)

You can certainly do it that way, but again, the value of 'speed' (the 'radius' that you speak of) doesn't matter; the above method will work fine for any value of 'speed' (it can even be negative in the given context, which would result in 'backwards' motion).

[Edit: I see you're using ints for your variables. Typically you would floats for these kinds of computations, but maybe there are factors involved that aren't evident from your post.]

For the case of the use of '34', I was just giving an example. In practice, I would do this in radians. And I would also use floats.

Quote:
 Original post by LessBreadIirc, a unit circle is used in conjunction with the identity principle. X * 1 = X. Maximum speed would not be limited to one. You wrote "velocity would be the length of the radius in a circle" - iirc, velocity is the magnitude of the vector. The unit circle (et al) pertains to the direction of the vector, not it's magnitude.

I understand now. Thanks for your help, guys.