2 * $RCSfile: Point3f.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 3 element point that is represented by single precision floating point
41 public class Point3f extends Tuple3f implements java.io.Serializable {
44 // Compatible with 1.1
45 static final long serialVersionUID = -8689337816398030143L;
48 * Constructs and initializes a Point3f from the specified xyz coordinates.
49 * @param x the x coordinate
50 * @param y the y coordinate
51 * @param z the z coordinate
53 public Point3f(float x, float y, float z)
60 * Constructs and initializes a Point3f from the array of length 3.
61 * @param p the array of length 3 containing xyz in order
63 public Point3f(float[] p)
70 * Constructs and initializes a Point3f from the specified Point3f.
71 * @param p1 the Point3f containing the initialization x y z data
73 public Point3f(Point3f p1)
80 * Constructs and initializes a Point3f from the specified Point3d.
81 * @param p1 the Point3d containing the initialization x y z data
83 public Point3f(Point3d p1)
90 * Constructs and initializes a Point3f from the specified Tuple3f.
91 * @param t1 the Tuple3f containing the initialization x y z data
93 public Point3f(Tuple3f t1)
100 * Constructs and initializes a Point3f from the specified Tuple3d.
101 * @param t1 the Tuple3d containing the initialization x y z data
103 public Point3f(Tuple3d t1)
110 * Constructs and initializes a Point3f to (0,0,0).
119 * Computes the square of the distance between this point and
121 * @param p1 the other point
122 * @return the square of the distance
124 public final float distanceSquared(Point3f p1)
131 return dx*dx+dy*dy+dz*dz;
136 * Computes the distance between this point and point p1.
137 * @param p1 the other point
138 * @return the distance
140 public final float distance(Point3f p1)
147 return (float) Math.sqrt(dx*dx+dy*dy+dz*dz);
152 * Computes the L-1 (Manhattan) distance between this point and
153 * point p1. The L-1 distance is equal to:
154 * abs(x1-x2) + abs(y1-y2) + abs(z1-z2).
155 * @param p1 the other point
156 * @return the L-1 distance
158 public final float distanceL1(Point3f p1)
160 return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + Math.abs(this.z-p1.z));
165 * Computes the L-infinite distance between this point and
166 * point p1. The L-infinite distance is equal to
167 * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2)].
168 * @param p1 the other point
169 * @return the L-infinite distance
171 public final float distanceLinf(Point3f p1)
174 tmp = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y));
175 return(Math.max(tmp,Math.abs(this.z-p1.z)));
181 * Multiplies each of the x,y,z components of the Point4f parameter
182 * by 1/w and places the projected values into this point.
183 * @param p1 the source Point4f, which is not modified
185 public final void project(Point4f p1)