Skip to content

Commit

Permalink
signed area function
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyBoivie authored and JimmyBoivie committed Dec 6, 2015
1 parent 7631a79 commit 25b9020
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
17 changes: 17 additions & 0 deletions main/CompGeo.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point> 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;
}
}
4 changes: 2 additions & 2 deletions main/FaceList.pde
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public class FaceList {
private Face unboundFace;

public FaceList() {
faces = new ArrayList<Face>();
unboundFace = new Face();
//faces = new ArrayList<Face>();
//unboundFace = new Face();
}

public ArrayList<Face> getFaces() {
Expand Down
11 changes: 11 additions & 0 deletions main/HalfEdge.pde
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ public class HalfEdge {
return "Origin: " + origin.toString() + "\nDestination: " + twin.getOrigin().toString();
}

public ArrayList<Point> getPointsNext() {
ArrayList<Point> points = new ArrayList<Point>();
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;
}
Expand Down

0 comments on commit 25b9020

Please sign in to comment.