Package com.github.stephengold.joltjni
Class Vec3
java.lang.Object
com.github.stephengold.joltjni.Vec3
- All Implemented Interfaces:
Vec3Arg
A vector composed of 3 single-precision components, used to represent
directions, extents, forces, impulses, offsets, scaling factors, torques, and
velocities in 3-dimensional space.
-
Constructor Summary
ConstructorsConstructorDescriptionVec3()Instantiate an all-zero vector (0,0,0).Vec3(double x, double y, double z) Instantiate a vector with specified components.Vec3(float[] array) Instantiate a vector from the specified array.Vec3(float x, float y, float z) Instantiate a vector with specified components.Instantiate from a location vector.Instantiate a copy of the argument. -
Method Summary
Modifier and TypeMethodDescriptionstatic Vec3Return the component-wise sum of the specified vectors.Return the cross product with the specified vector.floatReturn the dot product with the specified vector.booleanTests for exact equality with the argument, distinguishing -0 from 0.floatget(int index) Return the specified component.Return an arbitrary unit vector perpendicular to the current vector.floatgetX()Return the first (X) component in single precision.floatgetY()Return the 2nd (Y) component in single precision.floatgetZ()Return the 3rd (Z) component in single precision.inthashCode()Return a hash code.booleanTest whether the vector is zero to within a tolerance of 10^-12.booleanisNearZero(float tolerance) Test whether the vector is zero to within the specified tolerance.booleanTest whether the vector is normalized to within a tolerance of 10^-6.booleanisNormalized(float tolerance) Test whether the vector is normalized to within the specified tolerance.floatlength()Return the length.floatlengthSq()Return the squared length.Generate a normalized vector with the same direction.normalizedOr(Vec3Arg zeroValue) Return a copy of the argument if the length of the current vector is zero.Generate the component-wise reciprocal.static Vec3Return the bitwise AND of the specified vectors.static Vec3sAxisX()Create a unit vector along the 1st (X) principal axis.static Vec3sAxisY()Create a unit vector along the 2nd (Y) principal axis.static Vec3sAxisZ()Create a unit vector along the 3rd (Z) principal axis.voidset(float[] array) Set all 3 components from the specified array.voidset(float x, float y, float z) Set all 3 components to specified values.voidsetX(float x) Alter the first (X) component.voidsetY(float y) Alter the 2nd (Y) component.voidsetZ(float z) Alter the 3rd (Z) component.voidsplatX()Copy the X component to all components.voidsplatY()Copy the Y component to all components.voidsplatZ()Copy the Z component to all components.static Vec3sRandom(DefaultRandomEngine engine) Generate a pseudo-random unit vector.static Vec3sReplicate(float value) Create a vector with all components identical.static Vec3sUnitSpherical(float theta, float phi) Generate a unit vector with the specified spherical coordinates.static Vec3sZero()Create a vector with all components zero.float[]toArray()Copy the components to an array.toString()Return a string representation of the vector, which is unaffected.
-
Constructor Details
-
Vec3
public Vec3()Instantiate an all-zero vector (0,0,0). -
Vec3
public Vec3(double x, double y, double z) Instantiate a vector with specified components.- Parameters:
x- the desired X componenty- the desired Y componentz- the desired Z component
-
Vec3
public Vec3(float x, float y, float z) Instantiate a vector with specified components.- Parameters:
x- the desired X componenty- the desired Y componentz- the desired Z component
-
Vec3
public Vec3(float[] array) Instantiate a vector from the specified array.- Parameters:
array- the desired component values (not null, length≥3, unaffected)
-
Vec3
Instantiate from a location vector.- Parameters:
vec- the vector to copy (not null, unaffected)
-
Vec3
Instantiate a copy of the argument.- Parameters:
vec- the vector to copy (not null, unaffected)
-
-
Method Details
-
add
Return the component-wise sum of the specified vectors.- Parameters:
v1- the first vector (not null, unaffected)v2- the 2nd vector (not null, unaffected)v3- the 3nd vector (not null, unaffected)- Returns:
- a new vector
-
sAnd
Return the bitwise AND of the specified vectors.- Parameters:
v1- the first vector (not null, unaffected)v2- the 2nd vector (not null, unaffected)- Returns:
- a new vector
-
sAxisX
Create a unit vector along the 1st (X) principal axis.- Returns:
- a new vector
-
sAxisY
Create a unit vector along the 2nd (Y) principal axis.- Returns:
- a new vector
-
sAxisZ
Create a unit vector along the 3rd (Z) principal axis.- Returns:
- a new vector
-
set
public void set(float x, float y, float z) Set all 3 components to specified values.- Parameters:
x- the desired X componenty- the desired Y componentz- the desired Z component
-
set
public void set(float[] array) Set all 3 components from the specified array.- Parameters:
array- the desired component values (not null, length≥3, unaffected)
-
setX
public void setX(float x) Alter the first (X) component.- Parameters:
x- the desired value
-
setY
public void setY(float y) Alter the 2nd (Y) component.- Parameters:
y- the desired value
-
setZ
public void setZ(float z) Alter the 3rd (Z) component.- Parameters:
z- the desired value
-
splatX
public void splatX()Copy the X component to all components. -
splatY
public void splatY()Copy the Y component to all components. -
splatZ
public void splatZ()Copy the Z component to all components. -
sRandom
Generate a pseudo-random unit vector.The results are not uniformly distributed over the unit sphere.
- Parameters:
engine- the generator to use (not null)- Returns:
- a new unit vector
-
sReplicate
Create a vector with all components identical.- Parameters:
value- the desired component value- Returns:
- a new vector
-
sUnitSpherical
Generate a unit vector with the specified spherical coordinates.- Parameters:
theta- angle from the +Z axis (in radians)phi- angle from the +X axis in the X-Y plane (in radians)- Returns:
- a new unit vector
-
sZero
Create a vector with all components zero.- Returns:
- a new vector
-
cross
Return the cross product with the specified vector. The current vector is unaffected. -
dot
Return the dot product with the specified vector. The current vector is unaffected. -
get
public float get(int index) Return the specified component. The vector is unaffected.- Specified by:
getin interfaceVec3Arg- Parameters:
index- 0, 1, or 2- Returns:
- the X component if index=0, the Y component if index=1, or the Z component if index=2
- Throws:
IllegalArgumentException- if index is not 0, 1, or 2
-
getNormalizedPerpendicular
Return an arbitrary unit vector perpendicular to the current vector. The current vector is unaffected.- Specified by:
getNormalizedPerpendicularin interfaceVec3Arg- Returns:
- a new vector
-
getX
public float getX()Return the first (X) component in single precision. The vector is unaffected. -
getY
public float getY()Return the 2nd (Y) component in single precision. The vector is unaffected. -
getZ
public float getZ()Return the 3rd (Z) component in single precision. The vector is unaffected. -
isNearZero
public boolean isNearZero()Test whether the vector is zero to within a tolerance of 10^-12. The vector is unaffected.- Specified by:
isNearZeroin interfaceVec3Arg- Returns:
- true if near zero, otherwise false
-
isNearZero
public boolean isNearZero(float tolerance) Test whether the vector is zero to within the specified tolerance. The vector is unaffected.- Specified by:
isNearZeroin interfaceVec3Arg- Parameters:
tolerance- the desired tolerance (default=1e-12)- Returns:
- true if near zero, otherwise false
-
isNormalized
public boolean isNormalized()Test whether the vector is normalized to within a tolerance of 10^-6. The vector is unaffected.- Specified by:
isNormalizedin interfaceVec3Arg- Returns:
- true if normalized, otherwise false
-
isNormalized
public boolean isNormalized(float tolerance) Test whether the vector is normalized to within the specified tolerance. The vector is unaffected.- Specified by:
isNormalizedin interfaceVec3Arg- Parameters:
tolerance- the desired tolerance (default=1e-6)- Returns:
- true if normalized, otherwise false
-
length
public float length()Return the length. The vector is unaffected. -
lengthSq
public float lengthSq()Return the squared length. The vector is unaffected. -
normalized
Generate a normalized vector with the same direction. The current vector is unaffected.- Specified by:
normalizedin interfaceVec3Arg- Returns:
- a new vector
-
normalizedOr
Return a copy of the argument if the length of the current vector is zero. Otherwise, generate a normalized vector with the same direction as the current vector. The current vector is unaffected.- Specified by:
normalizedOrin interfaceVec3Arg- Parameters:
zeroValue- the value to return if the length is zero (not null, unaffected)- Returns:
- a new vector
-
reciprocal
Generate the component-wise reciprocal. The current vector is unaffected.- Specified by:
reciprocalin interfaceVec3Arg- Returns:
- a new vector
-
toArray
public float[] toArray()Copy the components to an array. The vector is unaffected. -
equals
Tests for exact equality with the argument, distinguishing -0 from 0. Ifotheris null, false is returned. Either way, the current instance is unaffected. -
hashCode
public int hashCode()Return a hash code. If two vectors have identical values, they will have the same hash code. The vector is unaffected. -
toString
Return a string representation of the vector, which is unaffected. For example, a zero vector is represented by:Vec3(0.0 0.0 0.0)
-