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.
40 public class A4 implements JSONEncodable, Serializable {
43 * I assumed that the length of the axis vector is not significant.
49 private static final long serialVersionUID = 1L;
72 * Constructs and initializes a AxisAngle4f to (0,0,1,0).
79 * Constructs and initializes an AxisAngle4f from the specified x, y, z, and
92 public static A4 new4(float x, float y, float z, float angle) {
94 a.set4(x, y, z, angle);
99 * Constructs and initializes a AxisAngle4f from the specified AxisAngle4f.
102 * the AxisAngle4f containing the initialization x y z angle data
105 public static A4 newAA(A4 a1) {
107 a.set4(a1.x, a1.y, a1.z, a1.angle);
112 * Constructs and initializes an AxisAngle4f from the specified axis and
121 public static A4 newVA(V3 axis, float angle) {
123 a.setVA(axis, angle);
128 * Sets the value of this AxisAngle4f to the specified axis and angle.
136 public final void setVA(V3 axis, float angle) {
144 * Sets the value of this axis angle to the specified x,y,z,angle.
155 public final void set4(float x, float y, float z, float angle) {
163 * Sets the value of this axis angle to the value of axis angle t1.
166 * the axis angle to be copied
168 public final void setAA(A4 a) {
177 * Sets the value of this axis-angle to the rotational component of the passed
183 public final void setM(M3 m1) {
184 setFromMat(m1.m00, m1.m01, m1.m02, m1.m10, m1.m11, m1.m12, m1.m20, m1.m21,
189 private void setFromMat(double m00, double m01, double m02, double m10,
190 double m11, double m12, double m20, double m21,
192 // assuming M is normalized.
194 double cos = (m00 + m11 + m22 - 1.0) * 0.5;
195 x = (float) (m21 - m12);
196 y = (float) (m02 - m20);
197 z = (float) (m10 - m01);
198 double sin = 0.5 * Math.sqrt(x * x + y * y + z * z);
199 if (sin == 0 && cos == 1) {
204 angle = (float) Math.atan2(sin, cos);
207 // no need to normalize
214 * Returns a hash number based on the data values in this object. Two
215 * different AxisAngle4f objects with identical data values (ie, returns true
216 * for equals(AxisAngle4f) ) will return the same hash number. Two vectors
217 * with different data members may return the same hash value, although this
221 public int hashCode() {
222 return T3.floatToIntBits(x) ^ T3.floatToIntBits(y)
223 ^ T3.floatToIntBits(z) ^ T3.floatToIntBits(angle);
227 * Returns true if the Object o is of type AxisAngle4f and all of the data
228 * members of o1 are equal to the corresponding data members in this
232 * the object with which the comparison is made.
236 public boolean equals(Object o) {
237 if (!(o instanceof A4))
240 return x == a1.x && y == a1.y && z == a1.z && angle == a1.angle;
244 * Returns a string that contains the values of this AxisAngle4f. The form is
247 * @return the String representation
250 public String toString() {
251 return "(" + x + ", " + y + ", " + z + ", " + angle + ")";
255 public String toJSON() {
256 return "[" + x + "," + y + "," + z + "," + (float) (angle * 180.0 / Math.PI) + "]";