Bill Dani - 1 year ago 127

iOS Question

I would like to draw one big circle and place some smaller circles as shown in the image below

I draw the big circe in - (void)drawRect:(CGRect)rect

`CGFloat rectX = self.frame.size.width / 2;`

CGFloat rectY = self.frame.size.height / 2;

CGFloat width = self.frame.size.width-30;

CGFloat height = self.frame.size.width -30;

CGFloat centerX = rectX - width/2;

CGFloat centerY = rectY - height/2;

UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(centerX, centerY, width, height)];

[[UIColor blackColor] set];

[bezierPath stroke];

Lets say I want to find 10 equally spaced points on the circle in order to draw 10 smaller red circles. Is there any smart solution? Thank you in advance.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

The equation for a circle is:

```
x = cx + r * cos(a)
y = cy + r * sin(a)
```

where `r`

is the **radius**, `(cx, cy)`

the **origin**, and `a`

the **angle**

you can draw a circle with

```
(UIBezierPath *)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise
```

function by using a `CGPoint`

as **centre** and some value as the **radius**. You can give start angle and endangle as 0 and 360 for drawing the circle. Choose appropriate **radius** for the small circle and find the points using the equation mentioned at start and draw the circle

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**