2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
.geom
;
9 import gov
.nasa
.worldwind
.*;
12 * A <code>Plane</code> object represents a mathematical plane in an arbitrary cartesian co-ordinate system. A
13 * <code>Plane</code> is defined by a normal vector and a distance along that vector from the origin, where the distance
14 * represents the distance from the origin to the <code>Plane</code> rather than from the <code>Plane</code> to the
18 * Instances of <code>Plane</code> are immutable. </p>
21 * @version $Id: Plane.java 1749 2007-05-06 19:48:14Z tgaskins $
23 public final class Plane
27 * Represents all the information about this <code>Plane</code>. The first three values (<code>x, y, z</code>) of
28 * <code>v</code> represent a normal <code>Vector</code> to the <code>Plane</code>, while the fourth
29 * (<code>w</code>) represents the signed distance this <code>Plane</code> has been shifted along that normal.
31 // private final Vector v;
32 private final Point n
;
35 * Obtains a new instance of a <code>Plane</code> whose information is contained in <code>Vector</code>
38 * @param vec the <code>Vector</code> containing information about this <code>Plane</code>'s normal and distance
39 * @throws IllegalArgumentException if passed a null or zero-length <code>Vector</code>
41 public Plane(Point vec
)
45 String message
= WorldWind
.retrieveErrMsg("nullValue.VectorIsNull");
46 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
47 throw new IllegalArgumentException(message
);
50 if (vec
.selfDot() == 0)
52 String message
= WorldWind
.retrieveErrMsg("geom.Plane.VectorIsZero");
53 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
54 throw new IllegalArgumentException(message
);
61 * Obtains a new <code>Plane</code> whose normal is defined by the vector (a,b,c) and whose disance from that vector
62 * is d. The vector may not have zero length.
64 * @param a the x-parameter of the normal to this <code>Plane</code>
65 * @param b the y-parameter of the normal to this <code>Plane</code>
66 * @param c the z-parameter of the normal to this <code>Plane</code>
67 * @param d the distance of this <code>Plane</code> from the origin along its normal.
68 * @throws IllegalArgumentException if <code>0==a==b==c</code>
70 public Plane(double a
, double b
, double c
, double d
)
72 if (a
== 0 && b
== 0 && c
== 0)
74 String message
= WorldWind
.retrieveErrMsg("geom.Plane.VectorIsZero");
75 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
76 throw new IllegalArgumentException(message
);
79 this.n
= new Point(a
, b
, c
, d
);
83 * Retrieves a <code>Point</code> representing the normal to this <code>Plane</code>.
85 * @return a <code>Point</code> representing the normal to this <code>Plane</code>
87 public final Point
getNormal()
89 return new Point(this.n
.x(), this.n
.y(), this.n
.z());
93 * Retrieves the distance from the origin to this <code>Plane</code>. Two options exist for defining distance - the
94 * first represents the distance from the origin to the <code>Plane</code>, the second represents the distance from
95 * the <code>Plane</code> to the origin. This function uses the first method. The outcome of this is that depending
96 * on the caller's view of this method, the sign of distances may appear to be reversed.
98 * @return the distance between this <code>Plane</code> and the origin
100 public final double getDistance()
106 * Retrieves a vector representing the normal and distance to this <code>Plane</code>. The
107 * vector has the structure (x, y, z, distance), where (x, y, z) represents the normal, and distance
108 * represents the distance from the origin.
110 * @return a <code>Vector</code> representation of this <code>Plane</code>
112 public final Point
getVector()
118 * Calculates the dot product of this <code>Plane</code> with Point <code>p</code>.
120 * @param p the Point to dot with this <code>Plane</code>
121 * @return the dot product of <code>p</code> and this <code>Plane</code>
122 * @throws IllegalArgumentException if <code>p</code> is null
124 public final double dot(Point p
)
128 String message
= WorldWind
.retrieveErrMsg("nullValue.PointIsNull");
129 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
130 throw new IllegalArgumentException(message
);
133 return this.n
.x() * p
.x() + this.n
.y() * p
.y() + this.n
.z() * p
.z() + this.n
.w() * p
.w();
137 public final String
toString()
139 return this.n
.toString();
143 public final boolean equals(Object o
)
147 if (o
== null || getClass() != o
.getClass())
150 final gov
.nasa
.worldwind
.geom
.Plane plane
= (gov
.nasa
.worldwind
.geom
.Plane
) o
;
152 //noinspection RedundantIfStatement
153 if (!this.n
.normalize().equals(plane
.n
.normalize()))
160 public final int hashCode()
162 return this.n
.hashCode();