]> gerrit.simantics Code Review - simantics/3d.git/blob - javax.vecmath/src/javax/vecmath/Point3d.java
Included old javax.vecmath 1.5.2 to org.simantics.g3d.feature
[simantics/3d.git] / javax.vecmath / src / javax / vecmath / Point3d.java
1 /*
2  * $RCSfile: Point3d.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 double precision floating point 
38  * x,y,z coordinates.
39  *
40  */
41 public class Point3d extends Tuple3d implements java.io.Serializable {
42
43     // Compatible with 1.1
44     static final long serialVersionUID = 5718062286069042927L;
45
46     /**
47      * Constructs and initializes a Point3d from the specified xyz coordinates.
48      * @param x the x coordinate
49      * @param y the y coordinate
50      * @param z the z coordinate
51      */
52     public Point3d(double x, double y, double z)
53     {
54         super(x,y,z);
55     }
56
57
58     /**
59      * Constructs and initializes a Point3d from the array of length 3.
60      * @param p the array of length 3 containing xyz in order
61      */
62     public Point3d(double[] p)
63     {
64        super(p);
65     }
66
67
68     /**
69      * Constructs and initializes a Point3d from the specified Point3d.
70      * @param p1 the Point3d containing the initialization x y z data
71      */
72     public Point3d(Point3d p1)
73     {
74          super(p1);
75     }
76
77
78     /**
79      * Constructs and initializes a Point3d from the specified Point3f.
80      * @param p1 the Point3f containing the initialization x y z data
81      */
82     public Point3d(Point3f p1)
83     {
84        super(p1);
85     }
86
87
88     /** 
89      * Constructs and initializes a Point3d from the specified Tuple3f. 
90      * @param t1 the Tuple3f containing the initialization x y z data 
91      */  
92     public Point3d(Tuple3f t1)  
93     { 
94        super(t1); 
95     }
96  
97  
98     /** 
99      * Constructs and initializes a Point3d from the specified Tuple3d.  
100      * @param t1 the Tuple3d containing the initialization x y z data 
101      */  
102     public Point3d(Tuple3d t1)
103     {
104        super(t1);
105     }
106
107
108     /**
109      * Constructs and initializes a Point3d to (0,0,0).
110      */
111     public Point3d()
112     {
113        super();
114     }
115
116
117   /**
118    * Returns the square of the distance between this point and point p1.
119    * @param p1 the other point 
120    * @return the square of the distance
121    */
122   public final double distanceSquared(Point3d p1)
123     {
124       double dx, dy, dz;
125
126       dx = this.x-p1.x;
127       dy = this.y-p1.y;
128       dz = this.z-p1.z;
129       return (dx*dx+dy*dy+dz*dz);
130     }
131
132
133   /**
134    * Returns the distance between this point and point p1.
135    * @param p1 the other point
136    * @return the distance 
137    */
138   public final double distance(Point3d p1)
139     {
140       double dx, dy, dz;
141
142       dx = this.x-p1.x;
143       dy = this.y-p1.y;
144       dz = this.z-p1.z;
145       return Math.sqrt(dx*dx+dy*dy+dz*dz);
146     }
147
148
149     /**
150      * Computes the L-1 (Manhattan) distance between this point and
151      * point p1.  The L-1 distance is equal to:
152      *  abs(x1-x2) + abs(y1-y2) + abs(z1-z2).
153      * @param p1 the other point
154      * @return  the L-1 distance
155      */
156     public final double distanceL1(Point3d p1) {
157         return Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) +
158             Math.abs(this.z-p1.z);
159     }
160
161
162     /**
163      * Computes the L-infinite distance between this point and
164      * point p1.  The L-infinite distance is equal to
165      * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2)].
166      * @param p1 the other point
167      * @return  the L-infinite distance
168      */
169     public final double distanceLinf(Point3d p1) {
170         double tmp;
171         tmp = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y));
172
173         return Math.max(tmp,Math.abs(this.z-p1.z));
174     }
175
176
177   /**
178     *  Multiplies each of the x,y,z components of the Point4d parameter 
179     *  by 1/w and places the projected values into this point. 
180     *  @param  p1  the source Point4d, which is not modified 
181     */   
182    public final void project(Point4d p1)
183    { 
184      double oneOw;
185
186      oneOw = 1/p1.w;
187      x = p1.x*oneOw;
188      y = p1.y*oneOw;
189      z = p1.z*oneOw;
190
191    } 
192
193
194 }