Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate a point with an given center, angle and radius?

In this SO question, someone asked for calculating an angle from three points. I need to do the opposite thing.

I want to draw a clock, and I have tiny tick images. An art dude made 60 of them, each with an individual and accurate shadow. So there are 60 distinct images at 10x10 points in size, already correctly rotated in the center of that square.

So every 6 degrees one tick image has to be placed. I would just need to calculate the x/y coordinate based on a center point, an radius and an angle.

So I have:

  • an center point
  • an radius
  • an angle

Is there an easy way to calculate the x/y coordinate with this? Maybe cocoa-touch already has a useful function or method for this?

like image 293
dontWatchMyProfile Avatar asked May 26 '10 12:05

dontWatchMyProfile


People also ask

How do you find the coordinates when given the radius and angle?

Typically, to find the x, y coordinates on a circle with a known radius and angle you could simply use the formula x = r(cos(degrees‎°)), y = r(sin(degrees‎°)).

How do you find a point on a circle given the center?

Distance Formula for a Point and the Center of a Circle: d=√(x−h)2+(y−k)2 d = ( x − h ) 2 + ( y − k ) 2 , where (x, y) is the point and (h,k) is the center of the circle. This formula is derived from the Pythagorean Theorem.

How do you find a point with a point and an angle?

If your starting point is (0,0), and your new point is r units away at an angle of θ, you can find the coordinates of that point using the equations x = r cosθ and y = r sinθ.


2 Answers

let a be the angle, (x,y) the center point and r the radius, then your point will be at

(x + r*cos(a), y + r*sin(a))
like image 148
unbeli Avatar answered Oct 18 '22 20:10

unbeli


In mathematics, to calculate the Cartesian coordinates from the polar coordinates:

x = r * cos(A) + x0;
y = r * sin(A) + y0;

where (x0, y0) is the centre of your circle, r is the radius and A is the angle.

But that assumes the mathematics coordinate convention i.e. x increases as you move rightwards, y increases as you move upwards. This is the default for views on Mac OS X Cocoa but I don't know if it is the same on the iPhone.

Also angles start at 3 o clock and go anti-clockwise i.e. 3 o clock is 0 degrees, 12 o clock is 90 degrees, 9 o clock is 180 degrees and 6 o clock is 270 degrees.

Also, the C sine and cosine functions work in radians.

like image 37
JeremyP Avatar answered Oct 18 '22 22:10

JeremyP