Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am simply trying to make an object move in a circle around a point. Let's say I have an object with a position vector going from that point to the object, and also the angle of the object with the x axis.

What is the equation I can use to obtain a velocity vector for that object so that it continues to move in a circle? What other information do I need?

share|improve this question
    
In order to move in a circle, you must constantly accelerate sideways. –  Jari Komppa Jan 29 '11 at 11:40
    
maybe you can check this answer: gamedev.stackexchange.com/questions/7365/… –  Notabene Jan 29 '11 at 11:43
    
@notabene Thanks, I actually read that before posting, I'm interested in velocity though instead of position and I don't know how to go from one to the other –  Kryptic Jan 29 '11 at 12:03
1  
A velocity vector is just the difference between two positions. –  user744 Jan 29 '11 at 13:22
add comment

3 Answers

up vote 5 down vote accepted

The velocity vector should be tangent to the circle, that is, perpendicular to the vector from the center to the current position. IIRC, the vector perpendicular to (u, v) is (-v, u).

Note that the perpendicular vector changes constantly as the object moves, so you need a new velocity vector after each update.

share|improve this answer
    
Thanks, I'm accepting this answer because I just implemented it and it works for my (probably simple) case –  Kryptic Jan 30 '11 at 2:18
add comment

I would use a vector that I call angularVelocity where the direction the vector is pointing represents the axis of rotation (orbital axis, in your case) and the magnitude represents the angular change per second. I can feed that vector to a matrix that is set up to perform an axis, angle rotation. All that is left is to offset this mechanism by the point that you want to orbit around. In pseudo code, it would look like this to orbit the moon around the earth assuming the sun was the gameworld origin:

angularVelocity = /*arbitrary*/ new Vector(0, 1, 0) * 3.14; //orbits 2 rev/sec

Matrix rotation = CreateARotationMatrix(angularVelocity);

moonPosition = ((moonPosition - earthPosition) * rotation) + earthPosition; //assuming your code library has a way to transform a vector by a matrix there.

public Matrix CreateARotationMatrix(Vector av)
{
   float angle = av.Length();
   Vector axis = av.Normalize;
   axisAngle4d.X = av.X;
   axisAngle4d.Y = av.Y;
   axisAngle4d.Z = av.Z;
   axisAngle4d.W = angle * elapsedTimeSinceLastFrame;

   //plug above into code found here to finish matrix: [http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToMatrix/index.htm][1]

}

The speed that the object orbits (the mood in our case here) can be related directly to whatever linear velocity you want by factoring in the orbital radius.

Note: You only have to build that matrix once, not every frame, unless the axis or the angular rate changes.

share|improve this answer
add comment

There is no single vector in Cartesian coordinates that will keep an object moving in a circle, as a single vector can only represent a straight line in the given system. However, you can express this motion in polar coordinates, where a straight line can actually represent circular motion in the equivalent Cartesian coordinate system.

For example, the polar vector (r=0,θ=5) rotates you 5 units around the origin (where a unit is typically a degree or a radian).

The rotation is done around the origin of the coordinate system, so you need to factor that in when converting between the 2 coordinate systems, typically as a translation done in Cartesian space I would expect.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.