Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define CGPoint having angle and diameter

I believe for some could be very simple to answer and help me.

I have a circle defined in drawRect and wrote a code to define arc of the circle.

CGFloat         width           = rect.size.width-rect.origin.x;
CGFloat         height          = rect.size.height-rect.origin.y;
CGFloat         xPos            = rect.origin.x;
CGFloat         yPos            = rect.origin.y;
CGFloat         arcStake        = (width * 2) * 0.25;
CGFloat         radius          = height/2;
CGPoint         centre          = CGPointMake(xPos+width/2, yPos+height/2);
CGFloat         angle           = acos(arcStake/(2*radius));
CGFloat         startAng        = radians(180) + angle;
CGFloat         endAng          = radians(360) - angle;

// Define 2 CGPoints of arc

CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, centre.x, centre.y, radius, startAng, endAng, 0);
CGPathAddLineToPoint(path, NULL, xPos+width/2, yPos+height/2);
CGPathCloseSubpath(path);

What I want is to define 2 CGPoints of arc. Here is the image to make it clearer.

enter image description here

like image 328
sumofighter666 Avatar asked Dec 27 '22 06:12

sumofighter666


1 Answers

A point on a circle with radius r at angle a (where a is measured from the rightmost point of the circle has the following coordinates:

x = r*cos(a) + center.x
y = r*sin(a) + center.y
like image 105
Seamus Campbell Avatar answered Jan 13 '23 16:01

Seamus Campbell