周长中的点不正确

时间:2013-04-30 12:01:57

标签: objective-c math geometry trigonometry

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

我正在计算它:

- (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}

我还没有将这些点应用到圆心,但是我还是没有看到这些日志中圆周路径的逻辑进展。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

我认为你错误估算了你的角度增量。

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

circle