Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25705/src/net/sourceforge/bprocessor/model
Modified Files:
Surface.java
Log Message:
Area of a surface is now calculated and displayed in attribute view.
Index: Surface.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v
retrieving revision 1.98
retrieving revision 1.99
diff -C2 -d -r1.98 -r1.99
*** Surface.java 7 Jun 2006 08:28:13 -0000 1.98
--- Surface.java 9 Jun 2006 09:49:56 -0000 1.99
***************
*** 1062,1065 ****
--- 1062,1119 ----
}
+
+ /**
+ * Get the area of the surface
+ * @return the area
+ */
+ public double getArea() {
+ double area = 0;
+ int norm = 1;
+ double highest = normal().getX();
+ if (Math.abs(highest) < Math.abs(normal().getY())) {
+ highest = normal().getY();
+ norm = 2;
+ }
+ if (Math.abs(highest) < Math.abs(normal().getZ())) {
+ highest = normal().getZ();
+ norm = 3;
+ }
+ Iterator it = getVertices().iterator();
+ double firstx, firsty, prevx, prevy, thisx, thisy;
+ firstx = 0;
+ firsty = 0;
+ prevx = 0;
+ prevy = 0;
+ thisx = 0;
+ thisy = 0;
+ boolean first = true;
+ while (it.hasNext()) {
+ Vertex v = (Vertex) it.next();
+ if (norm == 1) {
+ thisx = v.getY();
+ thisy = v.getZ();
+ } else if (norm == 2) {
+ thisx = v.getX();
+ thisy = v.getZ();
+ } else {
+ thisx = v.getX();
+ thisy = v.getY();
+ }
+ if (first) {
+ firstx = thisx;
+ firsty = thisy;
+ prevx = thisx;
+ prevy = thisy;
+ first = false;
+ } else {
+ area = area + (prevx * thisy - thisx * prevy);
+ }
+ prevx = thisx;
+ prevy = thisy;
+ }
+ area = Math.abs(0.5 * (area + thisx * firsty - firstx * thisy)) / Math.abs(highest);
+ return area;
+ }
+
/**
* Returns the outward pointing normal to this Surface
***************
*** 1342,1345 ****
--- 1396,1400 ----
}
}
+ res.add(new Attribute("Area", new Double(getArea()), false));
if (isInner()) {
res.add(new Attribute("Exterior", getExterior(), false));
|