2 * $RCSfile: Point4d.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:50 $
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 Point4d extends Tuple4d implements java.io.Serializable {
43 // Compatible with 1.1
44 static final long serialVersionUID = 1733471895962736949L;
48 * Constructs and initializes a Point4d from the specified xyzw coordinates.
49 * @param x the x coordinate
50 * @param y the y coordinate
51 * @param z the z coordinate
52 * @param w the w coordinate
54 public Point4d(double x, double y, double z, double w)
60 * Constructs and initializes a Point4d from the coordinates contained
62 * @param p the array of length 4 containing xyzw in order
64 public Point4d(double[] p)
71 * Constructs and initializes a Point4d from the specified Point4d.
72 * @param p1 the Point4d containing the initialization x y z w data
74 public Point4d(Point4d p1)
81 * Constructs and initializes a Point4d from the specified Point4f.
82 * @param p1 the Point4f containing the initialization x y z w data
84 public Point4d(Point4f p1)
91 * Constructs and initializes a Point4d from the specified Tuple4f.
92 * @param t1 the Tuple4f containing the initialization x y z w data
94 public Point4d(Tuple4f t1)
101 * Constructs and initializes a Point4d from the specified Tuple4d.
102 * @param t1 the Tuple4d containing the initialization x y z w data
104 public Point4d(Tuple4d t1)
111 * Constructs and initializes a Point4d from the specified Tuple3d.
112 * The x,y,z components of this point are set to the corresponding
113 * components of tuple t1. The w component of this point
115 * @param t1 the tuple to be copied
119 public Point4d(Tuple3d t1) {
120 super(t1.x, t1.y, t1.z, 1.0);
125 * Constructs and initializes a Point4d to (0,0,0,0).
134 * Sets the x,y,z components of this point to the corresponding
135 * components of tuple t1. The w component of this point
137 * @param t1 the tuple to be copied
141 public final void set(Tuple3d t1) {
150 * Returns the square of the distance between this point and point p1.
151 * @param p1 the first point
152 * @return the square of distance between this point and point p1
154 public final double distanceSquared(Point4d p1)
156 double dx, dy, dz, dw;
162 return (dx*dx+dy*dy+dz*dz+dw*dw);
167 * Returns the distance between this point and point p1.
168 * @param p1 the first point
169 * @return the distance between these this point and point p1.
171 public final double distance(Point4d p1)
173 double dx, dy, dz, dw;
179 return Math.sqrt(dx*dx+dy*dy+dz*dz+dw*dw);
184 * Computes the L-1 (Manhattan) distance between this point and
185 * point p1. The L-1 distance is equal to:
186 * abs(x1-x2) + abs(y1-y2) + abs(z1-z2) + abs(w1-w2).
187 * @param p1 the other point
188 * @return the L-1 distance
190 public final double distanceL1(Point4d p1) {
191 return Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) +
192 Math.abs(this.z-p1.z) + Math.abs(this.w-p1.w);
196 * Computes the L-infinite distance between this point and
197 * point p1. The L-infinite distance is equal to
198 * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2), abs(w1-w2)].
199 * @param p1 the other point
200 * @return the L-infinite distance
202 public final double distanceLinf(Point4d p1) {
204 t1 = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y));
205 t2 = Math.max( Math.abs(this.z-p1.z), Math.abs(this.w-p1.w));
207 return Math.max(t1,t2);
211 * Multiplies each of the x,y,z components of the Point4d parameter
212 * by 1/w, places the projected values into this point, and places
213 * a 1 as the w parameter of this point.
214 * @param p1 the source Point4d, which is not modified
216 public final void project(Point4d p1)