]> gerrit.simantics Code Review - simantics/3d.git/blob - javax.vecmath/src/javax/vecmath/Point3f.java
Included old javax.vecmath 1.5.2 to org.simantics.g3d.feature
[simantics/3d.git] / javax.vecmath / src / javax / vecmath / Point3f.java
1 /*
2  * $RCSfile: Point3f.java,v $
3  *
4  * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
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.
12  *
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).
18  *
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.
22  *
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
25  * have any questions.
26  *
27  * $Revision: 1.5 $
28  * $Date: 2008/02/28 20:18:50 $
29  * $State: Exp $
30  */
31
32 package javax.vecmath;
33
34 import java.lang.Math;
35
36 /**
37  * A 3 element point that is represented by single precision floating point 
38  * x,y,z coordinates.
39  *
40  */
41 public class Point3f extends Tuple3f implements java.io.Serializable {
42
43
44     // Compatible with 1.1
45     static final long serialVersionUID = -8689337816398030143L;
46
47     /**
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
52      */
53     public Point3f(float x, float y, float z)
54     {
55         super(x,y,z);
56     }
57
58
59     /**
60      * Constructs and initializes a Point3f from the array of length 3.
61      * @param p the array of length 3 containing xyz in order
62      */
63     public Point3f(float[] p)
64     {
65        super(p);
66     }
67
68
69     /**
70      * Constructs and initializes a Point3f from the specified Point3f.
71      * @param p1 the Point3f containing the initialization x y z data
72      */
73     public Point3f(Point3f p1)
74     {
75        super(p1);
76     }
77
78
79     /**
80      * Constructs and initializes a Point3f from the specified Point3d.
81      * @param p1 the Point3d containing the initialization x y z data
82      */
83     public Point3f(Point3d p1)
84     {
85        super(p1);
86     }
87
88
89     /**
90      * Constructs and initializes a Point3f from the specified Tuple3f.
91      * @param t1 the Tuple3f containing the initialization x y z data
92      */ 
93     public Point3f(Tuple3f t1) 
94     {
95        super(t1);
96     }
97
98
99     /**
100      * Constructs and initializes a Point3f from the specified Tuple3d.
101      * @param t1 the Tuple3d containing the initialization x y z data
102      */ 
103     public Point3f(Tuple3d t1) 
104     {
105        super(t1);
106     }
107
108
109     /**
110      * Constructs and initializes a Point3f to (0,0,0).
111      */
112     public Point3f()
113     {
114         super();
115     }
116
117
118  /**
119    * Computes the square of the distance between this point and 
120    * point p1.
121    * @param p1 the other point
122    * @return  the square of the distance
123    */
124   public final float distanceSquared(Point3f p1)
125     {
126       float dx, dy, dz;
127
128       dx = this.x-p1.x;
129       dy = this.y-p1.y;
130       dz = this.z-p1.z;
131       return dx*dx+dy*dy+dz*dz;
132     }
133
134
135   /**
136    * Computes the distance between this point and point p1.
137    * @param p1 the other point
138    * @return the distance
139    */
140   public final float distance(Point3f p1)
141     {
142       float  dx, dy, dz;
143
144       dx = this.x-p1.x;
145       dy = this.y-p1.y;
146       dz = this.z-p1.z;
147       return (float) Math.sqrt(dx*dx+dy*dy+dz*dz);
148     }
149
150
151   /**
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
157     */
158   public final float distanceL1(Point3f p1)
159     {
160        return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + Math.abs(this.z-p1.z));
161     }
162
163
164   /**
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
170     */
171   public final float distanceLinf(Point3f p1)
172     {
173        float tmp;
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)));
176
177     }
178
179
180   /**
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
184     */
185    public final void project(Point4f p1)
186    {
187      float oneOw;
188
189      oneOw = 1/p1.w;
190      x = p1.x*oneOw;
191      y = p1.y*oneOw;
192      z = p1.z*oneOw;
193
194    }
195
196
197 }