Package sim.util
Class Double3D
java.lang.Object
sim.util.NumberND
sim.util.Number3D
sim.util.Double3D
- All Implemented Interfaces:
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:
-
Field Summary
Fields inherited from class sim.util.NumberND
TYPE_DOUBLE_2D, TYPE_DOUBLE_3D, TYPE_INT_2D, TYPE_INT_3D, TYPE_MUTABLE_DOUBLE_2D, TYPE_MUTABLE_DOUBLE_3D, TYPE_MUTABLE_INT_2D, TYPE_MUTABLE_INT_3D
-
Constructor Summary
ConstructorDescriptionDouble3D()
Double3D
(double x, double y, double z) Explicitly assumes the z value is set to 0Explicitly assumes the z value is set to 0Explicitly assumes the z value is set to 0Double3D
(MutableDouble2D p, double z) Explicitly assumes the z value is set to 0Double3D
(MutableInt2D p, double z) -
Method Summary
Modifier and TypeMethodDescriptionadd
(double dx, double dy, double dz) add
(int dx, int dy, int dz) final Double3D
Adds Double3D "other" to current Double3D using vector additiondouble
distance
(double x, double y, double z) Returns the distance FROM this Double3D TO the specified pointdouble
Returns the distance FROM this Double3D TO the specified point.double
Returns the distance FROM this Double3D TO the specified point.double
Returns the 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 pointdouble
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
Returns the squared distance FROM this Double3D TO the specified point.final double
Takes the dot product this Double3D with anotherboolean
Returns whether this NumberND is equivalent to some other NumberND.double
getVal
(int val) Returns the value at position VAL in this NumberND (val should 0, 1, or sometimes 2)final double
getX()
final double
getY()
final double
getZ()
int
hashCode()
Provides a hashcode for this NumberND.final double
length()
Returns the vector length of the Double3Dfinal double
lengthSq()
Returns the vector length of the Double3Ddouble
manhattanDistance
(double x, double y, double z) Returns the manhtattan distance FROM this Double3D TO the specified pointdouble
Returns the manhtattan distance FROM this Double3D TO the specified pointdouble
Returns the manhtattan distance FROM this Double3D TO the specified pointdouble
Returns the manhtattan distance FROM this Double3D TO the specified pointdouble
Returns the manhtattan distance FROM this Double3D TO the specified pointfinal Double3D
multiply
(double val) Multiplies each element by scalar "val"final Double3D
negate()
Returns the negation of this Double3D.final Double3D
Normalizes the vector (sets its length to 1).int
Returns the number of dimensions of this NumberND (normally 2 or 3)final Double3D
resize
(double dist) Scales the vector to length "dist".final Double3D
Subtracts Double3D "other" from current Double3D using vector subtractiondouble[]
byte[]
toBytes()
Flattens out the NumberND to an array of bytes, including the NumberND subtype.Returns this NumberND in mathematical coordinates as a formatted String.toString()
Returns this NumberND as a nicely formatted String.Methods inherited from class sim.util.NumberND
doubleFromBytes, doubleToBytes, fromBytes, getDistanceSq, getOffsets, intFromBytes, intToBytes, main, mutable
-
Field Details
-
x
public final double x -
y
public final double y -
z
public final double z
-
-
Constructor Details
-
Double3D
public Double3D() -
Double3D
Explicitly assumes the z value is set to 0 -
Double3D
-
Double3D
-
Double3D
Explicitly assumes the z value is set to 0 -
Double3D
-
Double3D
-
Double3D
Explicitly assumes the z value is set to 0 -
Double3D
-
Double3D
-
Double3D
Explicitly assumes the z value is set to 0 -
Double3D
-
Double3D
-
Double3D
public Double3D(double x, double y, double z)
-
-
Method Details
-
numDimensions
public int numDimensions()Description copied from class:NumberND
Returns the number of dimensions of this NumberND (normally 2 or 3)- Specified by:
numDimensions
in classNumberND
-
getVal
public double getVal(int val) Description copied from class:NumberND
Returns the value at position VAL in this NumberND (val should 0, 1, or sometimes 2) -
toBytes
public byte[] toBytes()Description copied from class:NumberND
Flattens out the NumberND to an array of bytes, including the NumberND subtype. -
getX
public final double getX() -
getY
public final double getY() -
getZ
public final double getZ() -
toString
Description copied from class:NumberND
Returns this NumberND as a nicely formatted String. -
toCoordinates
Description copied from class:NumberND
Returns this NumberND in mathematical coordinates as a formatted String.- Specified by:
toCoordinates
in classNumberND
-
toArrayAsDouble
public double[] toArrayAsDouble()- Specified by:
toArrayAsDouble
in classNumberND
-
hashCode
public int hashCode()Description copied from class:NumberND
Provides a hashcode for this NumberND. -
equals
Description copied from class:NumberND
Returns whether this NumberND is equivalent to some other NumberND. -
distance
public double distance(double x, double y, double z) Returns the distance FROM this Double3D TO the specified point -
distance
Returns the distance FROM this Double3D TO the specified point. -
distance
Returns the distance FROM this Double3D TO the specified point. -
distance
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
Returns the squared distance FROM this Double3D TO the specified point. -
distanceSq
Returns the squared distance FROM this Double3D TO the specified point. -
distanceSq
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
Returns the manhtattan distance FROM this Double3D TO the specified point -
manhattanDistance
Returns the manhtattan distance FROM this Double3D TO the specified point -
manhattanDistance
Returns the manhtattan distance FROM this Double3D TO the specified point -
manhattanDistance
Returns the manhtattan distance FROM this Double3D TO the specified point -
add
Adds Double3D "other" to current Double3D using vector addition -
subtract
Subtracts Double3D "other" from current Double3D using vector subtraction -
add
-
subtract
-
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
Multiplies each element by scalar "val" -
resize
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
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
Takes the dot product this Double3D with another -
negate
Returns the negation of this Double3D. -
add
-
add
-