获取五角星的坐标
//获取十个点得坐标:从最上面顺时针
radius:半径
center:中心点坐标
CGFloat radius = 130;
CGFloat angle = 2 * M_PI / 5;
CGPoint center=CGPointMake(160, 240);
NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:10];
for (NSInteger i = 0; i < 10; i++) {
if (i%2 == 0) {
// cosf()返回参数的余弦值
CGFloat x = cosf(i/2 * angle - M_PI_2) * radius;
// sinf()返回参数的正弦值
CGFloat y = sinf(i/2 * angle - M_PI_2) * radius;
CGPoint point = CGPointMake(x+ center.x, y+ center.y);
[arrayM addObject:[NSValue valueWithCGPoint:point]];
}else
{
CGFloat l = radius*(sinf(15/180.0*M_PI)/sinf(135/180.0*M_PI));
CGFloat x = cosf(i/2 * angle + 1/6.0*M_PI - M_PI_2) * l;
// sinf()返回参数的正弦值
CGFloat y = sinf(i/2 * angle + 1/6.0*M_PI - M_PI_2) * l;
CGPoint point = CGPointMake(x+ center.x, y+ center.y);
[arrayM addObject:[NSValue valueWithCGPoint:point]];
}
}
获取五个点坐标画五角星(交叉获取)
//画图时直接用这五个点就可以画图(交叉连接)
CGFloat radius = 130;
CGFloat angle = 4 * M_PI / 5;
CGPoint center=CGPointMake(160, 240);
NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:5];
for (NSInteger i = 0; i < 5; i++) {
// cosf()返回参数的余弦值
CGFloat x = cosf(i/2 * angle - M_PI_2) * radius;
// sinf()返回参数的正弦值
CGFloat y = sinf(i/2 * angle - M_PI_2) * radius;
CGPoint point = CGPointMake(x+ center.x, y+ center.y);
[arrayM addObject:[NSValue valueWithCGPoint:point]];
}
//将NSValue类型转换成CGPoint
CGPoint point = [value CGPointValue];