dontWatchMyProfile
dontWatchMyProfile

Reputation: 46320

How to calculate end-point at a given center plus an radius and angle?

I'm trying to do some basic quartz core drawing with arcs, but have an tripple-F in math ;-)

I have a point:

CGPoint center = CGPointMake(100.0f, 100.0f);
CGFloat radius = 50.0f;
CGFloat startAngle = 20.0f / 180.0f * M_PI;
CGFloat endAngle = 150.0f / 180.0f * M_PI;
CGContextAddArc(c, center.x, center.y, radius, startAngle, endAngle, 0);

Now I want to draw a little dot on the middle of the arc. I mean, not the center point, but the little curve (arc) which is made up between the angles 20-150 degrees. I need the point which sits on the half way of that arc. I looked into quartz but unfortunately, there seems no helper function to calculate this...

Probably some hardcore trigonometric algorithm with atan and stuff of this kind needed?

Upvotes: 0

Views: 626

Answers (1)

MartinStettner
MartinStettner

Reputation: 29174

CGFloat midAngle = (startAngle + endAngle) / 2f;
CGFloat x = center.x + radius * cos(midAngle);
CGFloat y = center.y + radius * sin(midAngle);

would be the not-so-hardcore trigonometric formula for calculating your point's coordinates.

Upvotes: 3

Related Questions