Calculating point on a circle's circumference from angle in C#?

后端 未结 6 1007
故里飘歌
故里飘歌 2020-11-29 03:43

I imagine that this is a simple question, but I\'m getting some strange results with my current code and I don\'t have the math background to fully understand why. My goal

6条回答
  •  余生分开走
    2020-11-29 04:11

    -(NSMutableArray *)GetPointsForCircle
        {
           NSMutableArray *Points = [[NSMutableArray alloc] init];
           CGPoint CenterPoint = CGPointMake(160, 230);
           CGPoint Point;
           for (float Angel = 0; Angel <= 360; Angel+= 60)
             {
               Point.x = CenterPoint.x + 100 * cos(Angel);
               Point.y = CenterPoint.y + 100 * sin(Angel);
               [Points addObject:[NSValue valueWithCGPoint:Point]];
             }
           return Points;
        }
    
        - (CGPoint)pointOnCircle:(int)thisPoint withTotalPointCount:(int)totalPoints
         {
            CGPoint centerPoint = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2);
            float radius = 100.0;
            float angle = ( 2 * M_PI / (float)totalPoints ) * (float)thisPoint;
            CGPoint newPoint;
            newPoint.x = (centerPoint.x) + (radius * cosf(angle));
            newPoint.y = (centerPoint.y) + (radius * sinf(angle));
            return newPoint;   
        }
    

提交回复
热议问题