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.
19 import java.io.Serializable;
21 import javajs.api.JSONEncodable;
22 import javajs.util.T3;
27 * A 4 element axis angle represented by single precision floating point
28 * x,y,z,angle components. An axis angle is a rotation of angle (radians) about
31 * @version specification 1.1, implementation $Revision: 1.9 $, $Date:
32 * 2006/07/28 17:01:32 $
33 * @author Kenji hiranabe
35 * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012
36 * for unique constructor and method names
37 * for the optimization of compiled JavaScript using Java2Script
39 public class A4 implements JSONEncodable, Serializable {
42 * I assumed that the length of the axis vector is not significant.
66 * Constructs and initializes a AxisAngle4f to (0,0,1,0).
73 * Constructs and initializes an AxisAngle4f from the specified x, y, z, and
86 public static A4 new4(float x, float y, float z, float angle) {
88 a.set4(x, y, z, angle);
93 * Constructs and initializes a AxisAngle4f from the specified AxisAngle4f.
96 * the AxisAngle4f containing the initialization x y z angle data
99 public static A4 newAA(A4 a1) {
101 a.set4(a1.x, a1.y, a1.z, a1.angle);
106 * Constructs and initializes an AxisAngle4f from the specified axis and
115 public static A4 newVA(V3 axis, float angle) {
117 a.setVA(axis, angle);
122 * Sets the value of this AxisAngle4f to the specified axis and angle.
130 public final void setVA(V3 axis, float angle) {
138 * Sets the value of this axis angle to the specified x,y,z,angle.
149 public final void set4(float x, float y, float z, float angle) {
157 * Sets the value of this axis angle to the value of axis angle t1.
160 * the axis angle to be copied
162 public final void setAA(A4 a) {
171 * Sets the value of this axis-angle to the rotational component of the passed
177 public final void setM(M3 m1) {
178 setFromMat(m1.m00, m1.m01, m1.m02, m1.m10, m1.m11, m1.m12, m1.m20, m1.m21,
183 private void setFromMat(double m00, double m01, double m02, double m10,
184 double m11, double m12, double m20, double m21,
186 // assuming M is normalized.
188 double cos = (m00 + m11 + m22 - 1.0) * 0.5;
189 x = (float) (m21 - m12);
190 y = (float) (m02 - m20);
191 z = (float) (m10 - m01);
192 double sin = 0.5 * Math.sqrt(x * x + y * y + z * z);
193 if (sin == 0 && cos == 1) {
198 angle = (float) Math.atan2(sin, cos);
201 // no need to normalize
208 * Returns a hash number based on the data values in this object. Two
209 * different AxisAngle4f objects with identical data values (ie, returns true
210 * for equals(AxisAngle4f) ) will return the same hash number. Two vectors
211 * with different data members may return the same hash value, although this
215 public int hashCode() {
216 return T3.floatToIntBits(x) ^ T3.floatToIntBits(y)
217 ^ T3.floatToIntBits(z) ^ T3.floatToIntBits(angle);
221 * Returns true if the Object o is of type AxisAngle4f and all of the data
222 * members of o1 are equal to the corresponding data members in this
226 * the object with which the comparison is made.
230 public boolean equals(Object o) {
231 if (!(o instanceof A4))
234 return x == a1.x && y == a1.y && z == a1.z && angle == a1.angle;
238 * Returns a string that contains the values of this AxisAngle4f. The form is
241 * @return the String representation
244 public String toString() {
245 return "(" + x + ", " + y + ", " + z + ", " + angle + ")";
249 public String toJSON() {
250 return "[" + x + "," + y + "," + z + "," + (float) (angle * 180.0 / Math.PI) + "]";