2 Copyright (C) 1997,1998,1999
3 Kenji Hiranabe, Eiwa System Management, Inc.
5 This program is free software.
6 Implemented by Kenji Hiranabe(hiranabe@esm.co.jp),
7 conforming to the Java(TM) 3D API specification by Sun Microsystems.
9 Permission to use, copy, modify, distribute and sell this software
10 and its documentation for any purpose is hereby granted without fee,
11 provided that the above copyright notice appear in all copies and
12 that both that copyright notice and this permission notice appear
13 in supporting documentation. Kenji Hiranabe and Eiwa System Management,Inc.
14 makes no representations about the suitability of this software for any
15 purpose. It is provided "AS IS" with NO WARRANTY.
21 * A 3-element vector that is represented by single precision floating point
22 * x,y,z coordinates. If this value represents a normal, then it should be
25 * @version specification 1.1, implementation $Revision: 1.10 $, $Date:
26 * 2006/10/03 19:52:30 $
27 * @author Kenji hiranabe
29 * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012
30 * for unique constructor and method names
31 * for the optimization of compiled JavaScript using Java2Script
33 public class V3 extends T3 {
38 public static V3 newV(T3 t) {
39 return V3.new3(t.x, t.y, t.z);
42 public static V3 newVsub(T3 t1, T3 t2) {
43 return V3.new3(t1.x - t2.x, t1.y - t2.y,t1.z - t2.z);
46 public static V3 new3(float x, float y, float z) {
55 * Returns the angle in radians between this vector and the vector parameter;
56 * the return value is constrained to the range [0,PI].
60 * @return the angle in radians in the range [0,PI]
62 public final float angle(V3 v1) {
63 // return (double)Math.acos(dot(v1)/v1.length()/v.length());
64 // Numerically, near 0 and PI are very bad condition for acos.
65 // In 3-space, |atan2(sin,cos)| is much stable.
67 double xx = y * v1.z - z * v1.y;
68 double yy = z * v1.x - x * v1.z;
69 double zz = x * v1.y - y * v1.x;
70 double cross = Math.sqrt(xx * xx + yy * yy + zz * zz);
72 return (float) Math.abs(Math.atan2(cross, dot(v1)));