0

我正在尝试计算圆周上的点,但没有得到预期值。

我是这样计算的:

- (NSMutableArray *) pointsForSegment:(int) segment
{
    NSLog(@"segment is %d", segment);
    NSMutableArray *points = [NSMutableArray array];
    for (int i = 0; i < self.numberOfPointsPerSegment; i++)
    {
        CGPoint point;

       double angle = self.angleIncrement * ((self.numberOfPointsPerSegment * segment) + i);
       NSLog(@"angle is %f", angle);

       point.x = self.radius * cos(angle);
       point.y = self.radius * sin(angle);

       NSLog(@"Point for segment is %@", NSStringFromCGPoint(point));

       [points addObject:[NSValue valueWithCGPoint:point]];
   }
   return points;
}

我得到以下日志输出:

// initial values
self.totalRenderCycles is 172
Circumference is 691.150384
Angle increment is 0.520871 
Number of points in segment is 4

// first 4 segments (16 point calculations)
segment is 0
angle is 0.000000
Point for segment is {110, 0}
angle is 0.520871
Point for segment is {95.4125, 54.7399}
angle is 1.041741
Point for segment is {55.5189, 94.9613}
angle is 1.562612
Point for segment is {0.900247, 109.996}

segment is 1
angle is 2.083483
Point for segment is {-53.9572, 95.8573}
angle is 2.604354
Point for segment is {-94.5037, 56.2943}
angle is 3.125224
Point for segment is {-109.985, 1.80043}
angle is 3.646095
Point for segment is {-96.2957, -53.1709}

segment is 2
angle is 4.166966
Point for segment is {-57.0658, -94.0399}
angle is 4.687837
Point for segment is {-2.7005, -109.967}
angle is 5.208707
Point for segment is {52.381, -96.7276}
angle is 5.729578
Point for segment is {93.5697, -57.8335}

segment is 3
angle is 6.250449
Point for segment is {109.941, -3.60039}
angle is 6.771319
Point for segment is {97.153, 51.5877}
angle is 7.292190
Point for segment is {58.5974, 93.0932}
angle is 7.813061
Point for segment is {4.50003, 109.908}

我尚未将这些点应用于圆心以在屏幕上显示该点,但在这些日志中我仍然看不到通过圆周路径的逻辑进展。

任何帮助将不胜感激。

4

1 回答 1

1

我认为您错误地计算了角度增量。

请记住,每个段的结束也是下一段的开始。如果我将您计算的点绘制在 Excel 中,您可以看到它们在第三段之后如何环绕,以便最后一段以轻微偏移覆盖第一段。你是用度数还是弧度?

圆圈

于 2013-04-30T12:28:00.780 回答