首页 > 解决方案 > 无论起点如何,我都想按顺序保持圆上的点

问题描述

我的程序正在圆上创建随机点。我想将这些点分别保存在一个数组中。例如,首先我选择一个随机点(例如,让它是 p1),然后我将它们顺时针排序并添加到一个数组中。

这是我的程序输出示例

而且我正在分享我的程序代码,你可能想看看。

    public void producePoint()
    {
        double angle;
        PointF org = new PointF(250, 250);
        float rad = 250;       
        for (int i = 0; i < Int32.Parse(totalTextBox.Text); i++)
        {
            points[i] = new Points();
            angle = random.Next(0, 360);
            points[i].name = "P" + i.ToString();
            points[i].coordX = (float)(rad * Math.Cos(angle * Math.PI / 180F)) + org.X + area.X+10;
            points[i].coordY = (float)(rad * Math.Sin(angle * Math.PI / 180F)) + org.Y + area.Y+10;
        }
     }
public void DrawLine(string a , string b)
    {
        Points point1 = new Points();
        Points point2 = new Points();

        for (int i = 0; i < Int32.Parse(totalTextBox.Text); i++)
        {
            if (points[i].name == a)
            {
                point1 = points[i];
            }
            if (points[i].name == b)
            {
                point2 = points[i];
            }
            if (a == b)
            {
                point1 = point2;
            }             
        }
private void drawL_Click(object sender, EventArgs e)
    {
        if (firstPointComboBox.SelectedItem == null || secondPointComboBox.SelectedItem == null)
        {
            MessageBox.Show("Please,choose points");
        }
        else
        {
            DrawLine(firstPointComboBox.SelectedItem.ToString(), secondPointComboBox.SelectedItem.ToString());
        }
        
    }

标签: c#convex-hull

解决方案


推荐阅读