sim.util
Class Double3D

java.lang.Object
  extended by sim.util.Double3D
All Implemented Interfaces:
java.io.Serializable

public final class Double3D
extends java.lang.Object
implements java.io.Serializable

Double3D is more or less the same class as javax.vecmath.Point3d, but it is immutable: once the x and y and z values are set, they cannot be changed (they're final). Why use this immutable class when you could just use Point3d? Because Point3d is broken with respect to hash tables. You use Point3d as a key in a hash table at your own peril. Try this: hash an object by a Point3d as key. Then change the x value of the original Point3d. Ta-da! The object is lost in the hash table. Additionally, Point3d is in a nonstandard package (javax.vecmath) that we may or may not distribute with.

One day in the far future, Double3D should also be HIGHLY efficient; since it is immutable, it can be passed by value rather than by pointer by a smart compiler. Not today, though. But it's not bad.

This class has an elaborate hash code generation that is much more random than Sun's standard generator, but takes more time. For very large numbers of objects, this is a good idea, but we may change it to a simpler version in the future.

Double3D.equals(...) can compare by value against other Int3Ds and Double3Ds.

See Also:
Serialized Form

Field Summary
 double x
           
 double y
           
 double z
           
 
Constructor Summary
Double3D()
           
Double3D(Double2D p)
          Explicitly assumes the z value is set to 0
Double3D(Double2D p, double z)
           
Double3D(Double3D p)
           
Double3D(double x, double y, double z)
           
Double3D(Int2D p)
          Explicitly assumes the z value is set to 0
Double3D(Int2D p, double z)
           
Double3D(Int3D p)
           
Double3D(MutableDouble2D p)
          Explicitly assumes the z value is set to 0
Double3D(MutableDouble2D p, double z)
           
Double3D(MutableDouble3D p)
           
Double3D(MutableInt2D p)
          Explicitly assumes the z value is set to 0
Double3D(MutableInt2D p, double z)
           
Double3D(MutableInt3D p)
           
 
Method Summary
 Double3D add(Double3D other)
          Adds Double3D "other" to current Double3D using vector addition
 double distance(Double3D p)
          Returns the distance FROM this Double3D TO the specified point.
 double distance(double x, double y, double z)
          Returns the distance FROM this Double3D TO the specified point
 double distance(Int3D p)
          Returns the distance FROM this Double3D TO the specified point.
 double distance(MutableInt3D p)
          Returns the distance FROM this Double3D TO the specified point.
 double distanceSq(Double3D p)
          Returns the squared distance FROM this Double3D TO the specified point.
 double distanceSq(double x, double y, double z)
          Returns the squared distance FROM this Double3D TO the specified point
 double distanceSq(Int3D p)
          Returns the squared distance FROM this Double3D TO the specified point.
 double distanceSq(MutableInt3D p)
          Returns the squared distance FROM this Double3D TO the specified point.
 double dot(Double3D other)
          Takes the dot product this Double3D with another
 boolean equals(java.lang.Object obj)
           
 double getX()
           
 double getY()
           
 double getZ()
           
 int hashCode()
           
 double length()
          Returns the vector length of the Double3D
 double lengthSq()
          Returns the vector length of the Double3D
 double manhattanDistance(Double3D p)
          Returns the manhtattan distance FROM this Double3D TO the specified point
 double manhattanDistance(double x, double y, double z)
          Returns the manhtattan distance FROM this Double3D TO the specified point
 double manhattanDistance(Int3D p)
          Returns the manhtattan distance FROM this Double3D TO the specified point
 double manhattanDistance(MutableDouble3D p)
          Returns the manhtattan distance FROM this Double3D TO the specified point
 double manhattanDistance(MutableInt3D p)
          Returns the manhtattan distance FROM this Double3D TO the specified point
 Double3D multiply(double val)
          Multiplies each element by scalar "val"
 Double3D negate()
          Returns the negation of this Double3D.
 Double3D normalize()
          Normalizes the vector (sets its length to 1).
 Double3D resize(double dist)
          Scales the vector to length "dist".
 Double3D subtract(Double3D other)
          Subtracts Double3D "other" from current Double3D using vector subtraction
 java.lang.String toCoordinates()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public final double x

y

public final double y

z

public final double z
Constructor Detail

Double3D

public Double3D()

Double3D

public Double3D(Int2D p)
Explicitly assumes the z value is set to 0


Double3D

public Double3D(Int2D p,
                double z)

Double3D

public Double3D(Int3D p)

Double3D

public Double3D(MutableInt2D p)
Explicitly assumes the z value is set to 0


Double3D

public Double3D(MutableInt2D p,
                double z)

Double3D

public Double3D(MutableInt3D p)

Double3D

public Double3D(Double2D p)
Explicitly assumes the z value is set to 0


Double3D

public Double3D(Double2D p,
                double z)

Double3D

public Double3D(Double3D p)

Double3D

public Double3D(MutableDouble2D p)
Explicitly assumes the z value is set to 0


Double3D

public Double3D(MutableDouble2D p,
                double z)

Double3D

public Double3D(MutableDouble3D p)

Double3D

public Double3D(double x,
                double y,
                double z)
Method Detail

getX

public final double getX()

getY

public final double getY()

getZ

public final double getZ()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toCoordinates

public java.lang.String toCoordinates()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

distance

public double distance(double x,
                       double y,
                       double z)
Returns the distance FROM this Double3D TO the specified point


distance

public double distance(Double3D p)
Returns the distance FROM this Double3D TO the specified point.


distance

public double distance(Int3D p)
Returns the distance FROM this Double3D TO the specified point.


distance

public double distance(MutableInt3D p)
Returns the distance FROM this Double3D TO the specified point.


distanceSq

public double distanceSq(double x,
                         double y,
                         double z)
Returns the squared distance FROM this Double3D TO the specified point


distanceSq

public double distanceSq(Double3D p)
Returns the squared distance FROM this Double3D TO the specified point.


distanceSq

public double distanceSq(Int3D p)
Returns the squared distance FROM this Double3D TO the specified point.


distanceSq

public double distanceSq(MutableInt3D p)
Returns the squared distance FROM this Double3D TO the specified point.


manhattanDistance

public double manhattanDistance(double x,
                                double y,
                                double z)
Returns the manhtattan distance FROM this Double3D TO the specified point


manhattanDistance

public double manhattanDistance(Double3D p)
Returns the manhtattan distance FROM this Double3D TO the specified point


manhattanDistance

public double manhattanDistance(Int3D p)
Returns the manhtattan distance FROM this Double3D TO the specified point


manhattanDistance

public double manhattanDistance(MutableDouble3D p)
Returns the manhtattan distance FROM this Double3D TO the specified point


manhattanDistance

public double manhattanDistance(MutableInt3D p)
Returns the manhtattan distance FROM this Double3D TO the specified point


add

public final Double3D add(Double3D other)
Adds Double3D "other" to current Double3D using vector addition


subtract

public final Double3D subtract(Double3D other)
Subtracts Double3D "other" from current Double3D using vector subtraction


length

public final double length()
Returns the vector length of the Double3D


lengthSq

public final double lengthSq()
Returns the vector length of the Double3D


multiply

public final Double3D multiply(double val)
Multiplies each element by scalar "val"


resize

public final Double3D resize(double dist)
Scales the vector to length "dist". dist must be a finite value. If the vector has NaN, zero, or infinite values, then the vector cannot be resized to any length except for 0: other lengths will throw an exception in this case.


normalize

public final Double3D normalize()
Normalizes the vector (sets its length to 1). If the vector has NaN or infinite values, or has all zero values, then an exception will be thrown.


dot

public final double dot(Double3D other)
Takes the dot product this Double3D with another


negate

public final Double3D negate()
Returns the negation of this Double3D.