我想在我的iOS应用中创建下面的圈子.我知道如何制作圆圈,但我不完全确定如何获得圆弧上的点数.它必须是代码而不是图像.下面是我目前的代码.
- (void)drawRect:(CGRect)rect { CGPoint point; point.x = self.bounds.origin.x + self.bounds.size.width/2; point.y = self.bounds.origin.y + self.bounds.size.height/2; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context,2.0); CGContextSetStrokeColorWithColor(context,[UIColor blueColor].CGColor); CGRect circle = CGRectMake(point.x/2,point.y-point.x/2,point.x,point.x); CGContextAddEllipseInRect(context,circle); CGContextStrokePath(context); for (int i = 0; i<8; i++) { CGRect circleMini = CGRectMake(??????,??????,point.x/4,point.x/4); CGContextAddEllipseInRect(context,circleMini); CGContextStrokePath(context); } }
更新到答案@H_403_5@
float cita = 0; for (int i = 0; i<8; i++) { CGPoint pointCir = CGPointMake(point.x/2 + radius * cos(cita),(point.y-point.x/2) + radius * sin(cita) ); CGRect circleMini = CGRectMake(pointCir.x,pointCir.y,radius/4,radius/4); CGContextAddEllipseInRect(context,circleMini); CGContextStrokePath(context); cita += M_PI / 4.0; }
解决方法
如果(x,y)是中心而r是大圆的半径,则第i个外圆的中心将是:
center(i) = ( x + r * cos(cita),y + r * sin(cita) )
在0开始cita并为下一个圆(或45度)增加PI / 4弧度@H_403_5@
工作实施@H_403_5@
CGFloat cita = 0; CGFloat bigCircleRadius = point.x / 2.0; CGFloat smallCircleRadius = bigCircleRadius / 4.0; for (int i = 0; i < 8; i++) { CGPoint smallCircleCenter = CGPointMake(point.x + bigCircleRadius * cos(cita) - smallCircleRadius/2.0,point.y + bigCircleRadius * sin(cita) - smallCircleRadius / 2.0 ); CGRect smallCircleRect = CGRectMake(smallCircleCenter.x,smallCircleCenter.y,smallCircleRadius,smallCircleRadius); CGContextAddEllipseInRect(context,smallCircleRect); CGContextStrokePath(context); cita += M_PI / 4.0; }