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

前端 未结 3 474
北恋
北恋 2020-12-28 17:09

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.

相关标签:
3条回答
  • 2020-12-28 17:40

    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))
    
    0 讨论(0)
  • 2020-12-28 17:53

    Your image (center) should be placed at the point (X,Y), where (x,y) are the coordinates of center point, and r is radius

    X = x + (r/2)*cos(angle);
    Y = y + (r/2)*sin(angle); 
    
    0 讨论(0)
  • 2020-12-28 18:02

    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.

    0 讨论(0)
提交回复
热议问题