0

I have a circle CGRectMake(0.0, 0.0, 100.0, 100.0) with cornerRadius = 100;

I want to move an image around that circle. The image should move around the circle and point to the north. In other words it's a compass, just the heading doesn't rotate, but moves around the circle. Also I need the animation to move forwards and backwards just like on a compass.

Has anyone implemented something like this or have any suggestions or ideas?

spacecash21
  • 1,331
  • 1
  • 19
  • 41

1 Answers1

1

Instead of trying to work out the coors of it I'd just have an image that is the same size as the entire compass but completely transparent apart from the pointer which will sit on the top edge.

Then put a UIImageView with this image over your compass and just rotate the image around its centre point.

That way the pointer will always follow a circle and it's easier to point north because you're just dealing with an angle of rotation instead of coordinates.

For calculating the x,y coords for the circle...

  • You know the radius of the circle = radius.
  • You know the angle of rotation = theta. (angle is always in rads 2Pi rads = one full turn).

x coord = radius * cos(theta).

y coord = radius * sin(theta).

That should do it.

You may have to convert from RADs into degrees.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • A good idea, but this won't work as later I need to transform the circle to an ellipse, therefore the image pointing to the north would be squashed. – spacecash21 Nov 15 '12 at 10:49
  • In that case I'd write a function that turns the angle you need into x, y coordinates. You'll need to use trig functions to convert it. Elliptical coords might be a bit harder. – Fogmeister Nov 15 '12 at 10:53
  • You can do all the calculations on a circle and later transform it to the ellipse. But at the moment I'm struggling with the circle part. – spacecash21 Nov 15 '12 at 10:54
  • Edited with the maths for calculating the coords on the circle. – Fogmeister Nov 15 '12 at 11:03