Package icyllis.arc3d.core
Class Vector3
java.lang.Object
icyllis.arc3d.core.Vector3
Represents a three-dimensional vector.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd each component of a vector to this vector.@NonNull Vector3copy()voidcross(float x, float y, float z) Cross product of this vector with the given x, y and z components.voidCross product of this vector with the given vector.floatdot(float x, float y, float z) Returns the dot product of this vector with the given x, y and z components.floatReturns the dot product of this vector with the given vector.booleanbooleanequivalent(@NonNull Vector3 v) Returns whether this vector is equivalent to given vector.inthashCode()booleanReturns whether this vector is normalized.floatlength()Returns the magnitude of this vector, namely the 2-norm (euclidean norm) or the length.floatlengthSq()voidmaxComponent(@NonNull Vector3 v) Calculate component-wise maximum of this and the given vector.voidminComponent(@NonNull Vector3 v) Calculate component-wise minimum of this and the given vector.voidmultiply(float s) Multiply this vector by a factor.voidmultiply(float mx, float my, float mz) Multiply each component of the vector by given multipliersvoidMultiply each component of the vector by the given vector.voidnegate()Negate this vector[-x, -y, -z].voidNormalize this vector to unit length, or[1, 0, 0]if this is zero.voidCalculate an arbitrary unit vector perpendicular to this, this vector must be normalized.voidpreTransform(@NonNull Matrix4 mat) Pre-transform this vector by a 4x4 transformation matrix.floatproduct()Returns the product of all the vector components.voidprojection(@NonNull Vector3 v) Calculate the projection of the vector on the given vector.voidreverse()Reverse the order of components.@NonNull Quaternionrotation(float angle) Create a rotational quaternion clockwise about this axis with given angle in radians.voidset(float x, float y, float z) Set all values of this vector using the given components.voidSet all values of this vector using the given vector.voidsetZero()Set all values of this vector to zero.voidsort()Sort components of this in ascending order.voidSubtract each component of a vector from this vector.floatsum()Returns the sum of all the vector components.toString()voidTransform this vector by a 4x4 transformation matrix.voidtransform(@NonNull Quaternion q) 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:
trueif is normalized,falseotherwise
-
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:
trueif this vector is equivalent to other.
-
equals
-
hashCode
public int hashCode() -
toString
-
copy
-