From 25b90203f0fb99c2ef80671b4e15e4880ee948cf Mon Sep 17 00:00:00 2001 From: JimmyBoivie Date: Sat, 5 Dec 2015 20:42:51 -0500 Subject: [PATCH] signed area function --- main/CompGeo.pde | 17 +++++++++++++++++ main/FaceList.pde | 4 ++-- main/HalfEdge.pde | 11 +++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/main/CompGeo.pde b/main/CompGeo.pde index cc8bcf5..bb7bef0 100644 --- a/main/CompGeo.pde +++ b/main/CompGeo.pde @@ -50,4 +50,21 @@ public static class CompGeo { if ((nis % 2) == 0) { return false; } else { return true; } } + + public static float signedArea(HalfEdge h) { + return signedArea(h.getPointsNext()); + } + + public static float signedArea(ArrayList points) { + int num = points.size(); + Point p = null; + Point q = null; + float sum = 0; + for (int i = 0; i < num; i++) { + p = points.get(i); + q = points.get((i+1)%num); + sum += (p.getX()*q.getY() - q.getX()*p.getY()); + } + return sum; + } } \ No newline at end of file diff --git a/main/FaceList.pde b/main/FaceList.pde index e49033e..fe30fc9 100644 --- a/main/FaceList.pde +++ b/main/FaceList.pde @@ -4,8 +4,8 @@ public class FaceList { private Face unboundFace; public FaceList() { - faces = new ArrayList(); - unboundFace = new Face(); + //faces = new ArrayList(); + //unboundFace = new Face(); } public ArrayList getFaces() { diff --git a/main/HalfEdge.pde b/main/HalfEdge.pde index 6ec6181..55982c7 100644 --- a/main/HalfEdge.pde +++ b/main/HalfEdge.pde @@ -278,6 +278,17 @@ public class HalfEdge { return "Origin: " + origin.toString() + "\nDestination: " + twin.getOrigin().toString(); } + public ArrayList getPointsNext() { + ArrayList points = new ArrayList(); + points.add(this.getOrigin()); + HalfEdge temp = this.getnext(); + while (temp != this) { + points.add(temp.getOrigin()); + temp = temp.getnext(); + } + return points; + } + public HalfEdge gettwin() { return twin; }