Package rekit.primitives.geometry
Class Vec
java.lang.Object
rekit.primitives.geometry.Vec
@ClassParser(VecParser.class)
public final class Vec
extends Object
implements Cloneable, Operable<Vec>
A three dimensional Vector with operations.
- Author:
- Angelo Aracri
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionVec()
Short-hand constructor that takes the default value (0|0).Vec
(double x, double y) Constructor that takes the initial coordinates an saves them.Vec
(float xy) Constructor that takes one initial coordinate an saves them as x and y.Vec
(float x, float y) Constructor that takes the initial coordinates an saves them.Vec
(float x, float y, float z) Constructor that takes the initial coordinates an saves them.Vec
(int x, int y) Constructor that takes the initial coordinates an saves them. -
Method Summary
Modifier and TypeMethodDescriptionabs()
ApplyMath.abs(float)
to x and y component and create new vector.Adds another vector to this vector and returns a new Vector.addX
(float deltaX) Adds a given number to the x-component and returns a new Vector.addY
(float deltaY) Adds a given number to the y-component and returns a new Vector.clone()
get()
Always ! Enter the code:return this;
float
getAngleTo
(Vec other) Get the angle to another vector.Multiplies the vectors x-component and its y-component with the x-component and y-component of another Vector and returns a new Vector.float
norm()
Calculate the 2-norm ofthis
vector.rotate
(double angle) Rotate this vector relative to (0|0).Rotate this vector relative to a vector.scalar
(float scalar) Multiplies the vector with a scalar and returns a new Vector.scalar
(float scalarX, float scalarY) Multiplies the vectors x-component and its y-component with separate scalars and returns a new Vector.setX
(float x) Sets number to the x-component and returns a new Vector.setY
(float y) Sets number to the y-component and returns a new Vector.setZ
(float z) Create a new vector with this x,y values but a new z value.sin()
Calculate the sin of x and y.Apply subtrahend.toString()
translate2D
(float offset) Translate a 3D-Vector to 2D.
-
Field Details
-
x
public final float xThe x-component of the vector. -
y
public final float yThe y-component of the vector. -
z
public final float zThe optional z-component of the vector.
-
-
Constructor Details
-
Vec
public Vec(float x, float y, float z) Constructor that takes the initial coordinates an saves them.- Parameters:
x
- the initial x-component of the vectory
- the initial y-component of the vectorz
- the initial z-component of the vector
-
Vec
public Vec(float x, float y) Constructor that takes the initial coordinates an saves them.- Parameters:
x
- the initial x-component of the vectory
- the initial y-component of the vector
-
Vec
public Vec(double x, double y) Constructor that takes the initial coordinates an saves them. Note that only floats are used internally.- Parameters:
x
- the initial x-component of the vectory
- the initial y-component of the vector
-
Vec
public Vec(int x, int y) Constructor that takes the initial coordinates an saves them.- Parameters:
x
- the initial x-component of the vectory
- the initial y-component of the vector
-
Vec
public Vec(float xy) Constructor that takes one initial coordinate an saves them as x and y.- Parameters:
xy
- the initial x- and y-component of the vector
-
Vec
public Vec()Short-hand constructor that takes the default value (0|0).
-
-
Method Details
-
setX
Sets number to the x-component and returns a new Vector.- Parameters:
x
- the new x-component of the vector- Returns:
- the vector with the new x-component
-
addX
Adds a given number to the x-component and returns a new Vector.- Parameters:
deltaX
- the number to add to the original x-component of the vector- Returns:
- the vector with the new x-component
-
setY
Sets number to the y-component and returns a new Vector.- Parameters:
y
- the new y-component of the vector- Returns:
- the vector with the new y-component
-
addY
Adds a given number to the y-component and returns a new Vector.- Parameters:
deltaY
- the number to add to the original y-component of the vector- Returns:
- the vector with the new y-component
-
add
Adds another vector to this vector and returns a new Vector. -
sub
Description copied from interface:Operable
Apply subtrahend. -
sin
Calculate the sin of x and y.- Returns:
- a new vector (sinx, siny)
-
scalar
Multiplies the vector with a scalar and returns a new Vector. -
scalar
Multiplies the vectors x-component and its y-component with separate scalars and returns a new Vector.- Parameters:
scalarX
- the scalar to multiply the vectors x-component withscalarY
- the scalar to multiply the vectors x-component with- Returns:
- the resulting vector
-
multiply
Multiplies the vectors x-component and its y-component with the x-component and y-component of another Vector and returns a new Vector. -
getAngleTo
Get the angle to another vector.- Parameters:
other
- the other vector- Returns:
- the angle (rad)
-
rotate
Rotate this vector relative to a vector.- Parameters:
angle
- the anglerelative
- the relative vector for rotation- Returns:
- the new vector
-
rotate
Rotate this vector relative to (0|0).- Parameters:
angle
- the angle- Returns:
- the new vector
-
abs
ApplyMath.abs(float)
to x and y component and create new vector.- Returns:
- the resulting vector
-
norm
public float norm()Calculate the 2-norm ofthis
vector.- Returns:
- the 2-norm
-
clone
-
toString
-
setZ
Create a new vector with this x,y values but a new z value.- Parameters:
z
- the new z value- Returns:
- a new vector (x,y,z)
-
translate2D
Translate a 3D-Vector to 2D.- Parameters:
offset
- the offset (3D)- Returns:
- the new vector
-
get
Description copied from interface:Operable
Always ! Enter the code:return this;
-