Class Vector
java.lang.Object
xyz.jeremynoesen.pseudo3d.core.util.Vector
public class Vector
extends java.lang.Object
Immutable Vector with vector mathematical operators
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Vectoradd(Vector... vector)Add together this Vector and other VectorsfloatangleBetween(Vector vector)Get the angle between two Vectors in degreesVectorcross(Vector vector)Cross multiply two Vectorsfloatdistance(Vector vector)Calculate the distance between the ends of two VectorsVectordivide(float scale)Divide a Vector's magnitude by a scalar, which divides each component by the scalarVectordivide(Vector... vector)Divide Vector components by other Vectors' componentsfloatdot(Vector vector)Calculate the dot product of two Vectorsbooleanequals(java.lang.Object vector)Check if two Vectors are equalfloatget(Axis axis)Get a specified component of the VectorfloatgetMagnitude()Get the magnitude of the VectorfloatgetX()Get the x component of the VectorfloatgetY()Get the y component of the VectorfloatgetZ()Get the z component of the VectorVectormultiply(float scale)Multiply a Vector's magnitude by a scalar, which multiplies each component by the scalarVectormultiply(Vector... vector)Multiply vector Components by other Vectors' componentsVectornormalize()Normalize the Vector (a Vector of magnitude 1)Vectorset(Axis axis, float value)Set a specified component of the VectorVectorsetX(float x)Set the x component of the VectorVectorsetY(float y)Set the y component of the VectorVectorsetZ(float z)Set the z component of the VectorVectorsubtract(Vector... vector)Subtract Vectors from this Vectorjava.lang.StringtoString()Get the Vector as a StringMethods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
Vector
public Vector()Create a new Vector -
Vector
public Vector(float x, float y, float z)Create a new 3D Vector with components x, y, and z- Parameters:
x- X component of Vectory- Y component of Vectorz- Z component of Vector
-
Vector
public Vector(float x, float y)Create a new 2D Vector with components x and y- Parameters:
x- X component of Vectory- Y component of Vector
-
Vector
Copy constructor for Vector- Parameters:
vector- Vector to copy
-
-
Method Details
-
getX
public float getX()Get the x component of the Vector- Returns:
- X component
-
setX
Set the x component of the Vector- Parameters:
x- X component- Returns:
- Vector with modified x component
-
getY
public float getY()Get the y component of the Vector- Returns:
- Y component
-
setY
Set the y component of the Vector- Parameters:
y- Y component- Returns:
- Vector with modified y component
-
getZ
public float getZ()Get the z component of the Vector- Returns:
- Z component
-
setZ
Set the z component of the Vector- Parameters:
z- Z component- Returns:
- Vector with modified y component
-
get
Get a specified component of the Vector- Parameters:
axis- Axis to get value for- Returns:
- Component of Vector based on Axis
-
set
Set a specified component of the Vector- Parameters:
axis- Axis to set value tovalue- Value to set- Returns:
- Modified Vector
-
getMagnitude
public float getMagnitude()Get the magnitude of the Vector- Returns:
- Magnitude of Vector
-
add
Add together this Vector and other Vectors- Parameters:
vector- Vectors to add- Returns:
- Vector from the sum of the Vectors
-
subtract
Subtract Vectors from this Vector- Parameters:
vector- Vectors to subtract- Returns:
- Vector from subtraction of the Vectors
-
multiply
Multiply vector Components by other Vectors' components- Parameters:
vector- Vectors to multiply- Returns:
- Vector from multiplication of the Vectors
-
multiply
Multiply a Vector's magnitude by a scalar, which multiplies each component by the scalar- Parameters:
scale- What to scale the Vector by- Returns:
- Scaled Vector
-
divide
Divide Vector components by other Vectors' components- Parameters:
vector- Vectors to divide- Returns:
- Vector from division of the Vectors
-
divide
Divide a Vector's magnitude by a scalar, which divides each component by the scalar- Parameters:
scale- What to scale the Vector by- Returns:
- Scaled Vector
-
dot
Calculate the dot product of two Vectors- Parameters:
vector- Vector to dot product- Returns:
- Value of the dot product
-
cross
Cross multiply two Vectors- Parameters:
vector- Vector to cross multiply- Returns:
- Vector calculated from cross multiplication
-
distance
Calculate the distance between the ends of two Vectors- Parameters:
vector- Vector to calculate distance to- Returns:
- Distance to location
-
normalize
Normalize the Vector (a Vector of magnitude 1)- Returns:
- Normalized Vector
-
angleBetween
Get the angle between two Vectors in degrees- Parameters:
vector- Vector to get angle between- Returns:
- Angle between two Vectors
-
toString
public java.lang.String toString()Get the Vector as a String- Overrides:
toStringin classjava.lang.Object- Returns:
- Vector as a String in vector format
-
equals
public boolean equals(java.lang.Object vector)Check if two Vectors are equal- Overrides:
equalsin classjava.lang.Object- Parameters:
vector- Vector to compare to this Vector- Returns:
- True if the Vectors are equal
-