Find the point on a circle with given center point, radius, and degree

后端 未结 10 1839
后悔当初
后悔当初 2020-12-02 06:57

It\'s been 10 years since I did any math like this... I am programming a game in 2D and moving a player around. As I move the player around I am trying to calculate the poin

10条回答
  •  情歌与酒
    2020-12-02 07:25

    I highly suggest using matrices for this type of manipulations. It is the most generic approach, see example below:

    // The center point of rotation
    var centerPoint = new Point(0, 0);
    // Factory method creating the matrix                                        
    var matrix = new RotateTransform(angleInDegrees, centerPoint.X, centerPoint.Y).Value;
    // The point to rotate
    var point = new Point(100, 0);
    // Applying the transform that results in a rotated point                                      
    Point rotated = Point.Multiply(point, matrix); 
    
    • Side note, the convention is to measure the angle counter clockwise starting form (positive) X-axis

提交回复
热议问题