Package jsl.modeling.elements.spatial
Class Vector3D
- java.lang.Object
-
- jsl.modeling.elements.spatial.Vector3D
-
- All Implemented Interfaces:
CoordinateIfc
public class Vector3D extends java.lang.Object implements CoordinateIfc
The Vector3D class implements a 3D vector with the double values x1, x2, x3. Vectors can be thought of as either a (x1, x2, x3) point or at a vector from (0.0, 0.0, 0.0) to (x1, x2, x3)
-
-
Constructor Summary
Constructors Constructor Description Vector3D()Create a new Vector3D at (0.0, 0.0, 0.0)Vector3D(double x1, double x2)Create a new Vector3D at (x, y, 0.0)Vector3D(double x1, double x2, double x3)Create a new Vector3D at (x, y, z)Vector3D(CoordinateIfc v)Create a new Vector3D with the same values as the specfied vector, v
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(double x1, double x2, double x3)Adds the given values from the vectorvoidadd(CoordinateIfc v)Adds the given vector to this vectorvoiddivide(double s)Divides each element by sbooleanequals(double x1, double x2, double x3)Checks if this vector is equal to the specified coordinatesbooleanequals(java.lang.Object obj)Checks if this vector is equal to the specified Object They are equal if the specified Object is a Vector3D and the two vectors x, y, z coordinates are equaldoublegetX1()doublegetX2()doublegetX3()inthashcode()doublelength()The length of the vectorvoidmultiply(double s)Multiplies each element by sstatic Vector3DnewInstance(CoordinateIfc c)Returns a new instance of a Coordinate at the same underlying coordinates as the given coordinatevoidnormalize()Converts the vector to a unit vectorvoidsetCoordinates(double x1, double x2)Sets the coordinates of the vector to the values given, x3 is assumed 0.0voidsetCoordinates(double x1, double x2, double x3)Sets the coordinates of the vector to the values givenvoidsetCoordinates(CoordinateIfc c)Sets the coordinates of this vector to those given by the CoordinateIfcvoidsubtract(double x1, double x2, double x3)Subtracts the given values from the vectorvoidsubtract(CoordinateIfc v)Subtracts the given vector from this vectorjava.lang.StringtoString()Returns the (x,y,z) coordinates as a string "(x1,x2,x3)=(" + x1 + "," + x2 + "," + x3 +")"
-
-
-
Constructor Detail
-
Vector3D
public Vector3D()
Create a new Vector3D at (0.0, 0.0, 0.0)
-
Vector3D
public Vector3D(CoordinateIfc v)
Create a new Vector3D with the same values as the specfied vector, v- Parameters:
v- the vector to replicate
-
Vector3D
public Vector3D(double x1, double x2)Create a new Vector3D at (x, y, 0.0)- Parameters:
x1- the 1st coordinatex2- the 2nd coordinate
-
Vector3D
public Vector3D(double x1, double x2, double x3)Create a new Vector3D at (x, y, z)- Parameters:
x1- the 1st coordinatex2- the 2nd coordinatex3- the 3rd coordinate
-
-
Method Detail
-
newInstance
public static final Vector3D newInstance(CoordinateIfc c)
Returns a new instance of a Coordinate at the same underlying coordinates as the given coordinate- Parameters:
c-- Returns:
-
equals
public final boolean equals(java.lang.Object obj)
Checks if this vector is equal to the specified Object They are equal if the specified Object is a Vector3D and the two vectors x, y, z coordinates are equal- Overrides:
equalsin classjava.lang.Object
-
hashcode
public final int hashcode()
-
equals
public final boolean equals(double x1, double x2, double x3)Checks if this vector is equal to the specified coordinates- Parameters:
x1- the 1st coordinatex2- the 2nd coordinatex3- the 3rd coordinate
-
setCoordinates
public final void setCoordinates(double x1, double x2, double x3)Sets the coordinates of the vector to the values given- Parameters:
x1- the 1st coordinatex2- the 2nd coordinatex3- the 3rd coordinate
-
setCoordinates
public final void setCoordinates(double x1, double x2)Sets the coordinates of the vector to the values given, x3 is assumed 0.0- Parameters:
x1- the 1st coordinatex2- the 2nd coordinate
-
setCoordinates
public final void setCoordinates(CoordinateIfc c)
Sets the coordinates of this vector to those given by the CoordinateIfc- Parameters:
c-
-
add
public final void add(double x1, double x2, double x3)Adds the given values from the vector- Parameters:
x1- the 1st coordinatex2- the 2nd coordinatex3- the 3rd coordinate
-
subtract
public final void subtract(double x1, double x2, double x3)Subtracts the given values from the vector- Parameters:
x1- the 1st coordinatex2- the 2nd coordinatex3- the 3rd coordinate
-
add
public final void add(CoordinateIfc v)
Adds the given vector to this vector- Parameters:
v-
-
subtract
public final void subtract(CoordinateIfc v)
Subtracts the given vector from this vector- Parameters:
v-
-
multiply
public final void multiply(double s)
Multiplies each element by s- Parameters:
s-
-
divide
public final void divide(double s)
Divides each element by s- Parameters:
s- Must not be zero
-
length
public final double length()
The length of the vector- Returns:
- the length
-
normalize
public final void normalize()
Converts the vector to a unit vector
-
toString
public java.lang.String toString()
Returns the (x,y,z) coordinates as a string "(x1,x2,x3)=(" + x1 + "," + x2 + "," + x3 +")"- Overrides:
toStringin classjava.lang.Object
-
getX1
public final double getX1()
- Specified by:
getX1in interfaceCoordinateIfc- Returns:
- Returns the x1.
-
getX2
public final double getX2()
- Specified by:
getX2in interfaceCoordinateIfc- Returns:
- Returns the x2.
-
getX3
public final double getX3()
- Specified by:
getX3in interfaceCoordinateIfc- Returns:
- Returns the x3.
-
-