UIBezierPath 圆圈获取特定点

UIBezierPath circle get specific points

我想画一个大圆圈然后放一些小圆圈,如下图所示

我在 - (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];

假设我想在圆上找到 10 个等距点以绘制 10 个较小的红色圆圈。有什么聪明的解决办法吗?提前谢谢你。

圆的方程是:

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

其中 r 半径 (cx, cy) 原点 a 角度

你可以用

画一个圆
(UIBezierPath *)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise

函数使用 CGPoint 作为 中心 和一些值作为 半径 。您可以将开始角度和结束角度设置为 0 和 360 以绘制圆。为小圆选择合适的 半径 并使用开始提到的等式找到点并绘制圆