Class Vector
- java.lang.Object
-
- com.apogames.kitchenchef.game.entity.Vector
-
- All Implemented Interfaces:
java.io.Serializable
public final class Vector extends java.lang.Object implements java.io.SerializableA class for defining a 2-dimensional vector. With different helpful methods to work with and manipulate vectors.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vectoradd(float x, float y)Adds vector component-wise to a copy of this instance.Vectoradd(Vector vec)Adds vectors component-wise and returns a new instance.floatdistance(Vector p)Computes the Euclidean distance between two vectors.floatdistanceSqr(Vector p)Computes the squared Euclidean distance between two vectors.Vectordiv(float a)Divides both components of a copy of this instance by dividend.Vectordiv(float x, float y)Divides vectors component-wise and returns a new instance.Vectordiv(Vector vec)Divides vectors component-wise and returns a new instance.floatdot(Vector vec)Returns dot product (scalar product) of vectors.booleanequals(Vector other)Checks if vectors have same values.VectorgetNormalized()Get the normalized vector.floatgetX()Get the x component from the vector.floatgetY()Get the x component from the vector.floatlength()Returns the length of this vector.floatlengthSqr()Returns the squared length of this vector.Vectorlerp(Vector vec, float t)Performs linear interpolation between two vectors.Vectormult(float a)Multiplies both components of a copy of this instance with factor.Vectormult(float x, float y)Multiplies vectors component-wise and returns a new instance.Vectormult(Vector vec)Multiplies vectors component-wise and returns a new instance.voidnormalize()Normalize this vector.Vectorsub(float x, float y)Subtracts vector component-wise from a copy of this instance.Vectorsub(Vector vec)Subtracts vectors component-wise and returns a new instance.java.lang.StringtoString()
-
-
-
Constructor Detail
-
Vector
public Vector()
Instantiates a new Vector.
-
Vector
public Vector(Vector vec)
Instantiates a new Vector.- Parameters:
vec- the vec
-
Vector
public Vector(float x, float y)Instantiates a new Vector.- Parameters:
x- the xy- the y
-
-
Method Detail
-
getX
public float getX()
Get the x component from the vector.- Returns:
- the float
-
getY
public float getY()
Get the x component from the vector.- Returns:
- the float
-
add
public Vector add(Vector vec)
Adds vectors component-wise and returns a new instance. (Won't change this instance)- Parameters:
vec- incoming vector to add- Returns:
- new resulting vector
-
add
public Vector add(float x, float y)
Adds vector component-wise to a copy of this instance. (Won't change this instance)- Parameters:
x- incoming x-Value to addy- incoming y-Value to add- Returns:
- new resulting vector
-
sub
public Vector sub(Vector vec)
Subtracts vectors component-wise and returns a new instance. (Won't change this instance)- Parameters:
vec- incoming vector to subtract- Returns:
- new resulting vector
-
sub
public Vector sub(float x, float y)
Subtracts vector component-wise from a copy of this instance. (Won't change this instance)- Parameters:
x- incoming x-Value to subtracty- incoming y-Value to subtract- Returns:
- new resulting vector
-
mult
public Vector mult(float a)
Multiplies both components of a copy of this instance with factor. (Won't change this instance)- Parameters:
a- incoming factor to multiply- Returns:
- new resulting vector
-
mult
public Vector mult(float x, float y)
Multiplies vectors component-wise and returns a new instance. (Won't change this instance)- Parameters:
x- incoming x-Value to multiplyy- incoming y-Value to multiply- Returns:
- new resulting vector
-
mult
public Vector mult(Vector vec)
Multiplies vectors component-wise and returns a new instance. (Won't change this instance)- Parameters:
vec- incoming vector to multiply- Returns:
- new resulting vector
-
div
public Vector div(float a)
Divides both components of a copy of this instance by dividend. (Won't change this instance)- Parameters:
a- incoming dividend for division- Returns:
- new resulting vector
-
div
public Vector div(float x, float y)
Divides vectors component-wise and returns a new instance. (Won't change this instance)- Parameters:
x- incoming x-Value to dividey- incoming y-Value to divide- Returns:
- new resulting vector
-
div
public Vector div(Vector vec)
Divides vectors component-wise and returns a new instance. (Won't change this instance)- Parameters:
vec- incoming vector to divide- Returns:
- new resulting vector
-
dot
public float dot(Vector vec)
Returns dot product (scalar product) of vectors.- Parameters:
vec- incoming vector- Returns:
- dot product (scalar product)
-
length
public float length()
Returns the length of this vector.- Returns:
- length float
-
lengthSqr
public float lengthSqr()
Returns the squared length of this vector.- Returns:
- squared length
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
lerp
public Vector lerp(Vector vec, float t)
Performs linear interpolation between two vectors.- Parameters:
vec- second vectort- interpolation value [0,1]- Returns:
- interpolated vector rounded integers
-
distance
public float distance(Vector p)
Computes the Euclidean distance between two vectors.- Parameters:
p- second vector- Returns:
- the Euclidean distance between this and the second vector
-
distanceSqr
public float distanceSqr(Vector p)
Computes the squared Euclidean distance between two vectors.- Parameters:
p- second vector- Returns:
- squared Euclidean distance between this and the second vector
-
equals
public boolean equals(Vector other)
Checks if vectors have same values.- Parameters:
other- vector to be checked for equality- Returns:
- if vectors have same values
-
normalize
public void normalize()
Normalize this vector. If this is a Zero-Vector, components will be set to NaN.
-
getNormalized
public Vector getNormalized()
Get the normalized vector. (Won't change this instance)- Returns:
- This vector scaled to the length of 1. If this is a Zero-Vector, components will be set to NaN.
-
-