【问题标题】:UIBezierPath circle get specific pointsUIBezierPath 圆圈获取特定点
【发布时间】:2015-05-26 12:32:28
【问题描述】:

我想画一个大圆圈并放置一些较小的圆圈,如下图所示

我在 - (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 个较小的红色圆圈。有什么聪明的解决办法吗?提前谢谢你。

【问题讨论】:

    标签: ios uikit core-graphics uibezierpath


    【解决方案1】:

    圆的方程是:

    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 以绘制圆。为小圆选择合适的半径,并使用开头提到的等式找到点并绘制圆

    【讨论】:

      猜你喜欢
      • 2014-06-06
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      • 2019-04-13
      相关资源
      最近更新 更多