Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

c# - I want to keep the points on the circle in a sequence, regardless of the starting point

my program is creating random points on the circle. And I want to keep these points in a array respectively. For example, first I choose a random points (for example , let it be p1) and then I will sort them clockwise and I will add in a array.

This my program output example

And also I am sharing my program codes, may be you want to see that.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...