This project is read-only.

Compute area from triangles

Oct 8, 2014 at 3:17 PM

My question is maybe naive but here it is :
How compute the whole surface of the polygon ?

Here is my code :
Public Function Compute_PolygonArea(ByVal Poly As List(Of Point)) As Double
        'Geometry construction
        Dim Geometry As New TriangleNet.Geometry.InputGeometry
        For i As Integer = 0 To Poly.Count - 1
            Geometry.AddPoint(Poly(i).X, Poly(i).Y) 'Poly is created from the points of the boundary of a polygon

        Dim mesh As New Mesh

        'Aera computation
        Dim area As Double = 0
        For Each tri In mesh.Triangles
            area += tri.Area

        Return area
        Exit Function
    End Function
The goal of my work is to compute area.
The problem is that tri.Area is equal to 0.

I think I misunderstood something.

Next, I will need to add holes (smaller polygon(s) defined by a list of point inside the polygon named poly and also defined by a list of points) but I have not seen many examples on how to do this and I must say that the InputGeometry documentation did not help me a lot. Is there any other documentation ?
Thank you very much for your help.
Oct 8, 2014 at 5:37 PM
Edited Oct 8, 2014 at 6:09 PM
Documentation of the ITriangle.Area property may be a bit sparse here, but it says "Triangle area constraint". This means that it is used as input, e.g. you have a mesh and want to refine a selected set of triangles, you can set the area constraint for those triangles and refine the mesh.

You will have to write the code by yourself, but it's fairly easy. This is the C# version:
/// <summary>
/// Compute area of given triangle.
/// </summary>
public double GetTriangleArea(ITriangle tri)
    var a = tri.GetVertex(0);
    var b = tri.GetVertex(1);
    var c = tri.GetVertex(2);

    return 0.5 * Math.Abs(a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y));
Could you explain what's unclear about the InputGeometry documentation?

Regarding your code above: You will have to add segments using the AddSegment method and AddHole for the holes. It's the way the original Triangle code works and it's straightforward ...
Marked as answer by Dreamskid on 10/8/2014 at 11:44 AM
Oct 8, 2014 at 7:43 PM
Thanks for your help.

I will first try by myself to understand how everything works (segment, marker, ...).

Thanks again.