Package icyllis.arc3d.core
Class Vector3
java.lang.Object
icyllis.arc3d.core.Vector3
Represents a three-dimensional vector.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add each component of a vector to this vector.copy()
void
cross
(float x, float y, float z) Cross product of this vector with the given x, y and z components.void
Cross product of this vector with the given vector.float
dot
(float x, float y, float z) Returns the dot product of this vector with the given x, y and z components.float
Returns the dot product of this vector with the given vector.boolean
boolean
Returns whether this vector is equivalent to given vector.int
hashCode()
boolean
Returns whether this vector is normalized.float
length()
Returns the magnitude of this vector, namely the 2-norm (euclidean norm) or the length.float
lengthSq()
void
Calculate component-wise maximum of this and the given vector.void
Calculate component-wise minimum of this and the given vector.void
multiply
(float s) Multiply this vector by a factor.void
multiply
(float mx, float my, float mz) Multiply each component of the vector by given multipliersvoid
Multiply each component of the vector by the given vector.void
negate()
Negate this vector[-x, -y, -z]
.void
Normalize this vector to unit length, or[1, 0, 0]
if this is zero.void
Calculate an arbitrary unit vector perpendicular to this, this vector must be normalized.void
preTransform
(Matrix4 mat) Pre-transform this vector by a 4x4 transformation matrix.float
product()
Returns the product of all the vector components.void
Calculate the projection of the vector on the given vector.void
reverse()
Reverse the order of components.rotation
(float angle) Create a rotational quaternion clockwise about this axis with given angle in radians.void
set
(float x, float y, float z) Set all values of this vector using the given components.void
Set all values of this vector using the given vector.void
setZero()
Set all values of this vector to zero.void
sort()
Sort components of this in ascending order.void
Subtract each component of a vector from this vector.float
sum()
Returns the sum of all the vector components.toString()
void
Transform this vector by a 4x4 transformation matrix.void
Transform this vector by a quaternion rotation.
-
Field Details
-
x
public float x -
y
public float y -
z
public float z
-
-
Constructor Details
-
Vector3
public Vector3()Create a zero vector -
Vector3
public Vector3(float x, float y, float z) Create a vector with given components.- Parameters:
x
- the x-component of the vectory
- the y-component of the vectorz
- the z-component of the vector
-
-
Method Details
-
set
public void set(float x, float y, float z) Set all values of this vector using the given components.- Parameters:
x
- the x-component to sety
- the y-component to setz
- the z-component to set
-
set
Set all values of this vector using the given vector.- Parameters:
v
- the vector to copy from
-
add
Add each component of a vector to this vector.- Parameters:
v
- the vector to add
-
subtract
Subtract each component of a vector from this vector.- Parameters:
v
- the vector to subtract
-
multiply
public void multiply(float s) Multiply this vector by a factor.- Parameters:
s
- the factor to multiply.
-
multiply
public void multiply(float mx, float my, float mz) Multiply each component of the vector by given multipliers- Parameters:
mx
- the x-component multipliermy
- the y-component multipliermz
- the z-component multiplier
-
multiply
Multiply each component of the vector by the given vector.- Parameters:
v
- the vector to multiply with
-
length
public float length()Returns the magnitude of this vector, namely the 2-norm (euclidean norm) or the length.- Returns:
- the magnitude of this quaternion
-
lengthSq
public float lengthSq() -
dot
public float dot(float x, float y, float z) Returns the dot product of this vector with the given x, y and z components. -
dot
Returns the dot product of this vector with the given vector.- Parameters:
v
- the vector to dot product with.
-
cross
public void cross(float x, float y, float z) Cross product of this vector with the given x, y and z components. -
cross
Cross product of this vector with the given vector.- Parameters:
v
- the vector to cross product with.
-
minComponent
Calculate component-wise minimum of this and the given vector. -
maxComponent
Calculate component-wise maximum of this and the given vector. -
isNormalized
public boolean isNormalized()Returns whether this vector is normalized.- Returns:
true
if is normalized,false
otherwise
-
normalize
public void normalize()Normalize this vector to unit length, or[1, 0, 0]
if this is zero. -
setZero
public void setZero()Set all values of this vector to zero. -
negate
public void negate()Negate this vector[-x, -y, -z]
. -
sum
public float sum()Returns the sum of all the vector components.- Returns:
- the sum of all the vector components
-
product
public float product()Returns the product of all the vector components.- Returns:
- the product of all the vector components
-
perpendicular
public void perpendicular()Calculate an arbitrary unit vector perpendicular to this, this vector must be normalized. -
projection
Calculate the projection of the vector on the given vector.- Parameters:
v
- the vector to project on
-
rotation
Create a rotational quaternion clockwise about this axis with given angle in radians. This vector must be normalized.- Parameters:
angle
- rotation angle in radians- Returns:
- a quaternion represents the rotation
-
transform
Transform this vector by a 4x4 transformation matrix.- Parameters:
mat
- the matrix to transform from
-
preTransform
Pre-transform this vector by a 4x4 transformation matrix.- Parameters:
mat
- the matrix to transform from
-
transform
Transform this vector by a quaternion rotation.- Parameters:
q
- the quaternion to rotate the vector by
-
sort
public void sort()Sort components of this in ascending order. -
reverse
public void reverse()Reverse the order of components.[z,y,x]
-
equivalent
Returns whether this vector is equivalent to given vector.- Parameters:
v
- the quaternion to compare.- Returns:
true
if this vector is equivalent to other.
-
equals
-
hashCode
public int hashCode() -
toString
-
copy
-