Skip to content

Commit 20532a6

Browse files
committed
V3d adds cross(a,b)
1 parent d33d07d commit 20532a6

File tree

1 file changed

+13
-0
lines changed
  • sources/net.sf.j2s.java.core/src/javajs/util

1 file changed

+13
-0
lines changed

sources/net.sf.j2s.java.core/src/javajs/util/V3d.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,17 @@ public final double length() {
9090
return Math.sqrt(lengthSquared());
9191
}
9292

93+
public final double angle(V3d v1) {
94+
// return (double)Math.acos(dot(v1)/v1.length()/v.length());
95+
// Numerically, near 0 and PI are very bad condition for acos.
96+
// In 3-space, |atan2(sin,cos)| is much stable.
97+
98+
double xx = y * v1.z - z * v1.y;
99+
double yy = z * v1.x - x * v1.z;
100+
double zz = x * v1.y - y * v1.x;
101+
double cross = Math.sqrt(xx * xx + yy * yy + zz * zz);
102+
103+
return Math.abs(Math.atan2(cross, dot(v1)));
104+
}
105+
93106
}

0 commit comments

Comments
 (0)