kareemaismail / poly2tri

Automatically exported from code.google.com/p/poly2tri
Other
0 stars 0 forks source link

Poly2Tri.DelaunayTriangle.Area incorrect? #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a square
    [0]: {X:-3 Y:-10}
    [1]: {X:3 Y:-10}
    [2]: {X:3 Y:10}
    [3]: {X:-3 Y:10}
2. triangulate
3. evaluate area of second triangle

What is the expected output? What do you see instead?
expected 60
actual 0

What version of the product are you using? On what operating system?
c#, windows 7

Please provide any additional information below.

I believe this function is incorrect, it will return 0 where points 0 and 1 are 
on the same X or points 1 and 2 are on the same Y

        public double Area()
        {
            double b = Points[0].X - Points[1].X;
            double h = Points[2].Y - Points[1].Y;

            return Math.Abs((b * h * 0.5f));
        }

Original issue reported on code.google.com by ewa...@googlemail.com on 2 May 2011 at 7:36

GoogleCodeExporter commented 9 years ago
Yes you are right. Thats some legacy code that I haven't used myself.

The correct Area calculation code should be:

        public double Area()
        {
            double a = (Points[0].X - Points[2].X)*(Points[1].Y - Points[0].Y);
            double b = (Points[0].X - Points[1].X)*(Points[2].Y - Points[0].Y);

            return 0.5f*Math.Abs(a-b);
        }

Original comment by thahlen@gmail.com on 2 May 2011 at 8:57