Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv2837/src/net/sourceforge/bprocessor/model
Modified Files:
CoordinateSystem.java
Log Message:
Implemented CoordinateSystem.systemFor(origin, normal) that returns an appropriate coordinate system
Index: CoordinateSystem.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/CoordinateSystem.java,v
retrieving revision 1.65
retrieving revision 1.66
diff -C2 -d -r1.65 -r1.66
*** CoordinateSystem.java 21 Nov 2007 13:51:01 -0000 1.65
--- CoordinateSystem.java 22 Nov 2007 10:26:00 -0000 1.66
***************
*** 144,147 ****
--- 144,185 ----
/**
+ * CoordinateSystem for specified origin and z-axis (n), where the orientation
+ * is such that x-axis points right when looking down the negative z-axis.
+ * @param origin Vertex
+ * @param n z-axis
+ * @return coordinate system
+ */
+ public static CoordinateSystem systemFor(Vertex origin, Vertex n) {
+ int index = n.largestCoefficient();
+ Vertex i = null;
+ Vertex j = null;
+ if (index == Vertex.X) {
+ i = new Vertex(0, 1, 0);
+ Vertex z = new Vertex(1, 0, 0);
+ if (n.dot(z) < 0) {
+ i = i.scale(-1);
+ }
+ }
+ if (index == Vertex.Y) {
+ i = new Vertex(-1, 0, 0);
+ Vertex z = new Vertex(0, 1, 0);
+ if (n.dot(z) < 0) {
+ i = i.scale(-1);
+ }
+ }
+ if (index == Vertex.Z) {
+ i = new Vertex(1, 0, 0);
+ }
+
+ double t = n.dot(i);
+
+ i = i.minus(n.scale(t));
+ i.normalize();
+ j = n.cross(i);
+
+ return new CoordinateSystem(i, j, n, origin);
+ }
+
+ /**
* Empty constructor for persistence only
*/
|