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

后端 未结 10 1859
后悔当初
后悔当初 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:35

    Here is the c# implementation. The method will return the circular points which takes radius, center and angle interval as parameter. Angle is passed as Radian.

    public static List getCircularPoints(double radius, PointF center, double angleInterval)
            {
                List points = new List();
    
                for (double interval = angleInterval; interval < 2 * Math.PI; interval += angleInterval)
                {
                    double X = center.X + (radius * Math.Cos(interval));
                    double Y = center.Y + (radius * Math.Sin(interval));
    
                    points.Add(new PointF((float)X, (float)Y));
                }
    
                return points;
            }
    

    and the calling example:

    List LEPoints = getCircularPoints(10.0f, new PointF(100.0f, 100.0f), Math.PI / 6.0f);
    

提交回复
热议问题