2 * $RCSfile: Point4f.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 point represented by single precision floating point x,y,z,w
41 public class Point4f extends Tuple4f implements java.io.Serializable {
44 // Compatible with 1.1
45 static final long serialVersionUID = 4643134103185764459L;
48 * Constructs and initializes a Point4f 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 Point4f(float x, float y, float z, float w)
61 * Constructs and initializes a Point4f from the array of length 4.
62 * @param p the array of length 4 containing xyzw in order
64 public Point4f(float[] p)
71 * Constructs and initializes a Point4f from the specified Point4f.
72 * @param p1 the Point4f containing the initialization x y z w data
74 public Point4f(Point4f p1)
81 * Constructs and initializes a Point4f from the specified Point4d.
82 * @param p1 the Point4d containing the initialization x y z w data
84 public Point4f(Point4d p1)
91 * Constructs and initializes a Point4f from the specified Tuple4f.
92 * @param t1 the Tuple4f containing the initialization x y z w data
94 public Point4f(Tuple4f t1)
101 * Constructs and initializes a Point4f from the specified Tuple4d.
102 * @param t1 the Tuple4d containing the initialization x y z w data
104 public Point4f(Tuple4d t1)
111 * Constructs and initializes a Point4f from the specified Tuple3f.
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 Point4f(Tuple3f t1) {
120 super(t1.x, t1.y, t1.z, 1.0f);
125 * Constructs and initializes a Point4f 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(Tuple3f t1) {
150 * Computes the square of the distance between this point and point p1.
151 * @param p1 the other point
152 * @return the square of distance between these two points as a float
154 public final float distanceSquared(Point4f p1)
156 float dx, dy, dz, dw;
162 return (dx*dx+dy*dy+dz*dz+dw*dw);
167 * Computes the distance between this point and point p1.
168 * @param p1 the other point
169 * @return the distance between the two points
171 public final float distance(Point4f p1)
173 float dx, dy, dz, dw;
179 return (float) 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 float distanceL1(Point4f p1)
192 return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + Math.abs(this.z-p1.z) + Math.abs(this.w-p1.w));
197 * Computes the L-infinite distance between this point and
198 * point p1. The L-infinite distance is equal to
199 * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2), abs(w1-w2)].
200 * @param p1 the other point
201 * @return the L-infinite distance
203 public final float distanceLinf(Point4f p1)
206 t1 = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y));
207 t2 = Math.max( Math.abs(this.z-p1.z), Math.abs(this.w-p1.w));
209 return(Math.max(t1,t2));
214 * Multiplies each of the x,y,z components of the Point4f parameter
215 * by 1/w, places the projected values into this point, and places
216 * a 1 as the w parameter of this point.
217 * @param p1 the source Point4f, which is not modified
219 public final void project(Point4f p1)