NASA World Wind

gov.nasa.worldwind.geom
Class Point

java.lang.Object
  extended by gov.nasa.worldwind.geom.Point
All Implemented Interfaces:
Cacheable

public class Point
extends Object
implements Cacheable

Point represents an homogeneous cartesian point in 3 dimensional space.

Instances of Point are immutable.


Field Summary
static Point UNIT_X
          Value of UNIT_X is (1,0,0)
static Point UNIT_Y
          Value of UNIT_Y is (0,1,0)
static Point UNIT_Z
          Value of UNIT_Z is (0,0,1)
static Point ZERO
          Value of ZERO is (0,0,0)
 
Constructor Summary
Point(double x, double y, double z)
          Constructs a new Point from three parameters.
Point(double x, double y, double z, double w)
          Constructs a new Point from four parameters.
 
Method Summary
 Point add(Point p)
          Calculates the sum of these two Points.
static Point[] composeExtrema(Point[] points)
          Calculate the extrema of a given array of Points.
 Point cross(Point that)
          Determines the cross product of these two Points.
 double distanceTo(Point p)
          Calculates the unsigned distance between this Point and p.
 double distanceToSquared(Point p)
          Calculates the squared unsigned distance between this Point and p.
 double dot(Point p)
          Performs a dot product of the x, y and z coorinates of this and p.
 double dot4(Point p)
          Performs a dot product of all four components of this and p.
 boolean equals(Object o)
          Compares this Point to o for equality.
static Point fromOriginAndDirection(double scale, Point direction, Point origin)
          Scales a Point along a vector.
 long getSizeInBytes()
          Obtains the amount of memory this Point consumes.
 double getW()
          Returns the w element of this Point.
 double getX()
          Returns the x element of this Point.
 double getY()
          Returns the y element of this Point.
 double getZ()
          Returns the y element of this Point.
 int hashCode()
          Generates an integer that is always the same for identical objects, but usually different for different objects.
 double length()
          Calculates the distance between this Point and the origin.
static Point midPoint(Point p1, Point p2)
          Determines the midpoint of two Points.
 Point multiply(double s)
          Multiplies this Point by a scalar quantity.
 Point normalize()
           
 Point scale(double sx, double sy, double sz)
           
 double selfDot()
          Performs a dot product of the x, y and z coorinates of this with itself.
 Point subtract(Point p)
          Calculates the difference between these two Points.
 String toString()
          Generates a string representation of this object.
 double w()
          Returns the w element of this Point.
 double x()
          Returns the x element of this Point.
 double y()
          Returns the y element of this Point.
 double z()
          Returns the z element of this Point.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNIT_X

public static final Point UNIT_X
Value of UNIT_X is (1,0,0)


UNIT_Y

public static final Point UNIT_Y
Value of UNIT_Y is (0,1,0)


UNIT_Z

public static final Point UNIT_Z
Value of UNIT_Z is (0,0,1)


ZERO

public static final Point ZERO
Value of ZERO is (0,0,0)

Constructor Detail

Point

public Point(double x,
             double y,
             double z)
Constructs a new Point from three parameters. The w field is set to 1.

Parameters:
x - the x position of the Point
y - the y position of the Point
z - the z position of the Point

Point

public Point(double x,
             double y,
             double z,
             double w)
Constructs a new Point from four parameters.

Parameters:
x - the x position of the Point
y - the y position of the Point
z - the z position of the Point
w - the w position of the Point
Method Detail

add

public final Point add(Point p)
Calculates the sum of these two Points. The resulting Point has x value equivalent to this.x + p.x, the results for y,z and w are calculated in the same way.

Parameters:
p - the Point to be added to this Point
Returns:
a Point resulting from the algebraic operation this + p
Throws:
IllegalArgumentException - if p is null

composeExtrema

public static Point[] composeExtrema(Point[] points)
Calculate the extrema of a given array of Points. The resulting array is always of length 2, with the first element containing the minimum extremum, and the second containing the maximum. The minimum extremum is composed by taking the smallest x, y and z values from all the Points in the array. These values are not necessarily taken from the same Point. The maximum extrema is composed in the same fashion.

Parameters:
points - any array of Points
Returns:
a array with length of 2, comprising the most extreme values in the given array
Throws:
IllegalArgumentException - if points is null

cross

public Point cross(Point that)
Determines the cross product of these two Points. This is post multiplied by that.

Parameters:
that - the second Point
Returns:
the cross product of two Points
Throws:
IllegalArgumentException - if that is null

distanceTo

public final double distanceTo(Point p)
Calculates the unsigned distance between this Point and p.

Parameters:
p - the Point to find the distance from
Returns:
the distance between these two Points
Throws:
IllegalArgumentException - if p is null

distanceToSquared

public final double distanceToSquared(Point p)
Calculates the squared unsigned distance between this Point and p. This method is useful when actual distances are not required, but some measure is needed for comparison purposes. It avoids the square root required for computing actual distance.

Parameters:
p - the Point to find the square distance from
Returns:
the square of the distance between these two Points
Throws:
IllegalArgumentException - if p is null

dot

public final double dot(Point p)
Performs a dot product of the x, y and z coorinates of this and p.

Parameters:
p - the Point to perform a dot product with
Returns:
the scalar product of this and p
Throws:
IllegalArgumentException - if p is null

dot4

public final double dot4(Point p)
Performs a dot product of all four components of this and p.

Parameters:
p - the Point to perform a dot product with
Returns:
the scalar product of this and p
Throws:
IllegalArgumentException - if p is null

equals

public boolean equals(Object o)
Compares this Point to o for equality.

This method makes comparisons on private fields; overriding implementations should include a call to super.equals().

Overrides:
equals in class Object
Parameters:
o - the Object to be compared to for equality.
Returns:
true if the contents are equal, false otherwise

fromOriginAndDirection

public static Point fromOriginAndDirection(double scale,
                                           Point direction,
                                           Point origin)
Scales a Point along a vector. The resulting Point is affected by both the scale factor and the size of the vector direction. For example, a vector (2,2,2) and a vector (1,1,1) would produce a different result, if all other variables remain constant. For this reason, programmers may wish to normalize direction before calling this function.

Parameters:
scale - the factor to be scaled by
direction - the direction of scaling
origin - the original Point
Returns:
origin scaled by scale in the direction specified
Throws:
IllegalArgumentException - if direction or origin is null

getSizeInBytes

public final long getSizeInBytes()
Obtains the amount of memory this Point consumes.

Specified by:
getSizeInBytes in interface Cacheable
Returns:
the memory footprint of this Point in bytes.

getW

public double getW()
Returns the w element of this Point. This method differs from w() in that subclasses may override it.

Returns:
the w element of this Point
See Also:
w()

getX

public double getX()
Returns the x element of this Point. This method differs from x() in that subclasses may override it.

Returns:
the x element of this Point
See Also:
x()

getY

public double getY()
Returns the y element of this Point. This method differs from y() in that subclasses may override it.

Returns:
the y element of this Point
See Also:
y()

getZ

public double getZ()
Returns the y element of this Point. This method differs from y() in that subclasses may override it.

Returns:
the y element of this Point
See Also:
z()

hashCode

public int hashCode()
Generates an integer that is always the same for identical objects, but usually different for different objects. This method overrides the one in Object.

This method makes comparisons on private fields; overriding implementations should include a call to super.hashCode().

Overrides:
hashCode in class Object
Returns:
the hashCode for this Point.

length

public final double length()
Calculates the distance between this Point and the origin.

Returns:
the distance between this Point and ZERO
See Also:
ZERO

midPoint

public static Point midPoint(Point p1,
                             Point p2)
Determines the midpoint of two Points.

Parameters:
p1 - the first Point
p2 - the second Point
Returns:
the midpoint of these two Points
Throws:
IllegalArgumentException - if either p1 or p2 is null

multiply

public final Point multiply(double s)
Multiplies this Point by a scalar quantity. This method simply returns a new Point whose values each equal the old Point's corresponding value multiplied by this scalar.

Parameters:
s - the scalar to be multiplied by
Returns:
a Point resulting from the scalar multiplication of this and s

normalize

public final Point normalize()

scale

public final Point scale(double sx,
                         double sy,
                         double sz)

selfDot

public final double selfDot()
Performs a dot product of the x, y and z coorinates of this with itself. This method is equivalent to this.dot(this).

A useful characteristic of this method is that the resulting value is the square of this Point's distance from ZERO. Finding the square of the distance from the origin in this manner is preferred over finding the square by first finding the length and then squaring it because this is faster and less prone to loss of precision.

Returns:
this Point dotted with itself
See Also:
ZERO

subtract

public final Point subtract(Point p)
Calculates the difference between these two Points. The resulting Point is equivalent to this.x - p.x, the results for y, z and w are calculated in the same way.

Parameters:
p - the Point to subtract from this Point
Returns:
a Point resulting from the algebraic operationthis - p
Throws:
IllegalArgumentException - if p is null

toString

public final String toString()
Generates a string representation of this object. The returned string has the format "(x, y, z, w)" where x, y, z and w correspond to their respective values in this Point.

Overrides:
toString in class Object
Returns:
a string representation of this Point

w

public final double w()
Returns the w element of this Point.

Returns:
the w element of this Point

x

public final double x()
Returns the x element of this Point.

Returns:
the x element of this Point

y

public final double y()
Returns the y element of this Point.

Returns:
the y element of this Point

z

public final double z()
Returns the z element of this Point.

Returns:
the z element of this Point

NASA World Wind