Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've read this one, but I need more info: rotating an object from sourceAngle to destAngle, both 0-359, clockwise or counter clockwise?

I have a ball. The user is able to drag the ball in any direction clockwise/anticlockwise around a circle. I need to know whether or not the ball was dragged clockwise or anticlockwise.

I'd like to get both vector/non-vector methods.

share|improve this question
If the angle was 90 one frame, and 270 the next, which way is it rotating? i.e. you'd have to assume it moved in the direction of the minimum rotation, then have some default for 180 degree turns. – George Duckett Jan 9 '12 at 11:52
please see edit – Vishnu Jan 9 '12 at 11:55
i also have a middle point – Vishnu Jan 9 '12 at 14:21
I'm a little confused here, what data do you have? You talk about both angles and points, one must be derived from the other. Don't tell us about derived data, just the data that you have and the result you need. Anyone can compute the middle point between two points, but that doesn't actually solve the problem @GeorgeDuckett states. In any case the answer to that is that this question probably calls for 4 different outputs, right rotation, left rotation, no rotation and exactly 180 degrees rotation. – aaaaaaaaaaaa Jan 9 '12 at 14:39
@eBusiness: Well, simple take this as I have user dragging a ball around a circle. I need to know in which direction clockwise/anticlockwise he did drag it – Vishnu Jan 9 '12 at 15:01
up vote 4 down vote accepted

Keep track of the position of the ball on the previous frame. Then let's say we have:

|\                // A = Rotation Center
| \               // B = Previous Frame Position
|  C              // C = Current Frame Position

You need to check using the 2D analog of a cross product whether C lies to the left or to the right of the AB line segment. If it's to the right, then it's rotating clockwise. If it's to the left, then it's rotating counter-clockwise.

You can use this method to check:

bool isLeft(Vector2 a, Vector2 b, Vector2 c)
     return ((b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x)) > 0;
share|improve this answer
+1Thankyou for this useful and simple interpretation – Vishnu Jan 10 '12 at 6:24
I find a problem arising sometimes though, now ! can you brief. Some times it shows 1 when I really require -1 – Vishnu Jan 10 '12 at 9:01
What if user drags the ball 270 degree clockwise? In this case, your solution will determinates that the ball rotate reverse clockwise 90 degree, Right? – Nguyen Minh Binh May 30 '13 at 17:13

Given the points Source, Destination and Centre, where a move has happened from Source to Destination first compute the vectors:

CentreSource = Source - Centre
CentreDestination = Destination - Centre

Compute the dot product of the tværvector of CentreSource and CentreDestination:

RorL = CentreSourceX * CentreDestinationY - CentreSourceY * CentreDestinationX

Now RorL should be positive if the point is moving counterclockwise around the centre, negative in case of clockwise, and 0 if the move was either 0 or 180 degrees.

You can further check if the move was above or below 90 degrees by computing the dot product of CentreSource and CentreDestination:

AorB = CentreSourceX * CentreSourceY + CentreDestinationX * CentreDestinationY

If AorB is positive then the move was below 90 degrees, if it is negative the move was above 90 degrees, and if it is 0 then the move was either exactly 90 degrees or it either started or ended in the point Centre.

share|improve this answer
What's a tværvector? Can't seem to find any reference to it online, besides your posts. – David Gouveia Jan 9 '12 at 15:43
There are no other references. First hit on Google gives you the definition (unless of course if this post should overtake it). No one by the way seems to be using the term 2D cross product either, the page you link to call it a determinant, then you can follow a link to a a page about determinants where it is written that "Determinants are defined only for square matrices.". That is not exactly coherent. Using the word tværvector we can at least talk about the maths without having to touch this linguistic mess. – aaaaaaaaaaaa Jan 9 '12 at 16:14

How I would achieve this is to have a stack of 3 positions and use these to determine rotation of the object.


double[] position = new double[2];

double[][] positions = new double[3][2];
void bool clockwise () {
     for (int i = 0; i < 2; i++) {
          positions[i + 1][0] = positions[i][0];
          positions[i + 1][1] = positions[i][1];
     positions[0][0] = position[0];
     positions[0][1] = position[1];
     double[] averageOfEnds = new double[]{ (positions[0][0] + position[2][0]) / 2, (positions[0][1] + position[2][1]) / 2 };
     if (positions[2][0] < averageOfEnds[0] || positions[2][1] > averageOfEnds[1]) {
          return true;
     return false;

this assumes you axes are like

- ------ +
share|improve this answer

The easiest solution would be to keep a reference to the object's previous and current or previous, current and extrapolated next positions and do a simple compare.

share|improve this answer
Can you explain at least a little more. Thanks for the effort, though – Vishnu Jan 9 '12 at 11:42

Your Answer


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.