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 Vector
add(Vector... vector)
Add together this Vector and other Vectorsfloat
angleBetween(Vector vector)
Get the angle between two Vectors in degreesVector
cross(Vector vector)
Cross multiply two Vectorsfloat
distance(Vector vector)
Calculate the distance between the ends of two VectorsVector
divide(float scale)
Divide a Vector's magnitude by a scalar, which divides each component by the scalarVector
divide(Vector... vector)
Divide Vector components by other Vectors' componentsfloat
dot(Vector vector)
Calculate the dot product of two Vectorsboolean
equals(java.lang.Object vector)
Check if two Vectors are equalfloat
get(Axis axis)
Get a specified component of the Vectorfloat
getMagnitude()
Get the magnitude of the Vectorfloat
getX()
Get the x component of the Vectorfloat
getY()
Get the y component of the Vectorfloat
getZ()
Get the z component of the VectorVector
multiply(float scale)
Multiply a Vector's magnitude by a scalar, which multiplies each component by the scalarVector
multiply(Vector... vector)
Multiply vector Components by other Vectors' componentsVector
normalize()
Normalize the Vector (a Vector of magnitude 1)Vector
set(Axis axis, float value)
Set a specified component of the VectorVector
setX(float x)
Set the x component of the VectorVector
setY(float y)
Set the y component of the VectorVector
setZ(float z)
Set the z component of the VectorVector
subtract(Vector... vector)
Subtract Vectors from this Vectorjava.lang.String
toString()
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:
toString
in 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:
equals
in classjava.lang.Object
- Parameters:
vector
- Vector to compare to this Vector- Returns:
- True if the Vectors are equal
-