2 * $RCSfile: Vector4d.java,v $
4 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 * This code is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 only, as
9 * published by the Free Software Foundation. Sun designates this
10 * particular file as subject to the "Classpath" exception as provided
11 * by Sun in the LICENSE file that accompanied this code.
13 * This code is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * version 2 for more details (a copy is included in the LICENSE file that
17 * accompanied this code).
19 * You should have received a copy of the GNU General Public License version
20 * 2 along with this work; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24 * CA 95054 USA or visit www.sun.com if you need additional information or
28 * $Date: 2008/02/28 20:18:51 $
32 package javax.vecmath;
34 import java.lang.Math;
37 * A 4-element vector represented by double-precision floating point
38 * x,y,z,w coordinates.
41 public class Vector4d extends Tuple4d implements java.io.Serializable {
43 // Compatible with 1.1
44 static final long serialVersionUID = 3938123424117448700L;
47 * Constructs and initializes a Vector4d from the specified xyzw coordinates.
48 * @param x the x coordinate
49 * @param y the y coordinate
50 * @param z the z coordinate
51 * @param w the w coordinate
53 public Vector4d(double x, double y, double z, double w)
59 * Constructs and initializes a Vector4d from the coordinates contained
61 * @param v the array of length 4 containing xyzw in order
63 public Vector4d(double[] v)
69 * Constructs and initializes a Vector4d from the specified Vector4d.
70 * @param v1 the Vector4d containing the initialization x y z w data
72 public Vector4d(Vector4d v1)
78 * Constructs and initializes a Vector4d from the specified Vector4f.
79 * @param v1 the Vector4f containing the initialization x y z w data
81 public Vector4d(Vector4f v1)
87 * Constructs and initializes a Vector4d from the specified Tuple4f.
88 * @param t1 the Tuple4f containing the initialization x y z w data
90 public Vector4d(Tuple4f t1)
96 * Constructs and initializes a Vector4d from the specified Tuple4d.
97 * @param t1 the Tuple4d containing the initialization x y z w data
99 public Vector4d(Tuple4d t1)
106 * Constructs and initializes a Vector4d from the specified Tuple3d.
107 * The x,y,z components of this vector are set to the corresponding
108 * components of tuple t1. The w component of this vector
110 * @param t1 the tuple to be copied
114 public Vector4d(Tuple3d t1) {
115 super(t1.x, t1.y, t1.z, 0.0);
120 * Constructs and initializes a Vector4d to (0,0,0,0).
129 * Sets the x,y,z components of this vector to the corresponding
130 * components of tuple t1. The w component of this vector
132 * @param t1 the tuple to be copied
136 public final void set(Tuple3d t1) {
145 * Returns the length of this vector.
146 * @return the length of this vector
148 public final double length()
150 return Math.sqrt(this.x*this.x + this.y*this.y +
151 this.z*this.z + this.w*this.w);
156 * Returns the squared length of this vector.
157 * @return the squared length of this vector
159 public final double lengthSquared()
161 return (this.x*this.x + this.y*this.y +
162 this.z*this.z + this.w*this.w);
167 * Returns the dot product of this vector and vector v1.
168 * @param v1 the other vector
169 * @return the dot product of this vector and vector v1
171 public final double dot(Vector4d v1)
173 return (this.x*v1.x + this.y*v1.y + this.z*v1.z + this.w*v1.w);
178 * Sets the value of this vector to the normalization of vector v1.
179 * @param v1 the un-normalized vector
181 public final void normalize(Vector4d v1)
185 norm = 1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z + v1.w*v1.w);
194 * Normalizes this vector in place.
196 public final void normalize()
200 norm = 1.0/Math.sqrt(this.x*this.x + this.y*this.y +
201 this.z*this.z + this.w*this.w);
210 * Returns the (4-space) angle in radians between this vector and
211 * the vector parameter; the return value is constrained to the
213 * @param v1 the other vector
214 * @return the angle in radians in the range [0,PI]
216 public final double angle(Vector4d v1)
218 double vDot = this.dot(v1) / ( this.length()*v1.length() );
219 if( vDot < -1.0) vDot = -1.0;
220 if( vDot > 1.0) vDot = 1.0;
221 return((double) (Math.acos( vDot )));