datagridview point Coordinates Area calc

datagridview point Coordinates Area calc

k005
Advisor Advisor
294 Views
1 Reply
Message 1 of 2

datagridview point Coordinates Area calc

k005
Advisor
Advisor

I want to make an account in datagridview. datagridview consists of 4 columns Point No X Y Z shape...
In the data below, there is not only Z information. we don't need it either.

 

No X Y
------------------
1 389.634 209.299
2 337.222 92.005
3 179.626 116.397
4 223.063 242.658

 

Now, according to these data, Area: 21121.97 m² should be obtained.

 

Our formula is as follows:

 

2F = Yn x ( Xn -1 - Xn + 1)  

 

Cross Method...

 

Thanks in advance for the help

0 Likes
Accepted solutions (1)
295 Views
1 Reply
Reply (1)
Message 2 of 2

k005
Advisor
Advisor
Accepted solution

******** This issue has been resolved. ********

            int n = dataGridView1.RowCount - 1;
            double area = 0;

            List<double> Xs = new List<double>();
            List<double> Ys = new List<double>();

            foreach (DataGridViewRow dgvr in dataGridView1.Rows)
            {
                Xs.Add(Convert.ToDouble(dgvr.Cells[1].Value));
                Ys.Add(Convert.ToDouble(dgvr.Cells[2].Value));
            }

         

            for (var i = 0; i < n - 1; i++)
            {
                area = area + Xs[i] * Ys[i + 1] - Ys[i] * Xs[i + 1];
            }

            area = Math.Abs(area + Xs[n - 1] * Ys[0] - Ys[n - 1] * Xs[0]) / 2;

            MessageBox.Show("Alan : " + area.ToString());

 

0 Likes