Package toxi.geom
Class Vec3D
java.lang.Object
toxi.geom.Vec3D
- All Implemented Interfaces:
Comparable<ReadonlyVec3D>,ReadonlyVec3D
- Direct Known Subclasses:
AABB,AudioSource,Cone,DLAParticle,Plane,Ray3D,SoundListener,Sphere,VerletParticle3D,Vertex
Comprehensive 3D vector class with additional basic intersection and
collision detection features.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ReadonlyVec3DDefines vector with all coords set to Float.MAX_VALUE.static final ReadonlyVec3DDefines vector with all coords set to Float.MIN_VALUE.static final ReadonlyVec3DfloatX coordinate.static final ReadonlyVec3DDefines positive X axis.floatY coordinate.static final ReadonlyVec3DDefines positive Y axis.floatZ coordinate.static final ReadonlyVec3DDefines positive Z axis.static final ReadonlyVec3DDefines the zero vector. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Vec3Dabs()Abs.final Vec3Dadd(float a, float b, float c) Adds vector {a,b,c} and returns result as new vector.add(ReadonlyVec3D v) final Vec3DAdd vector v and returns result as new vector.final Vec3DaddSelf(float a, float b, float c) Adds vector {a,b,c} and overrides coordinates with result.final Vec3Dfinal Vec3DAdds vector v and overrides coordinates with result.final floatComputes the angle between this vector and vector V.final floatangleBetween(ReadonlyVec3D v, boolean forceNormalize) Computes the angle between this vector and vector V.final ReadonlyVec3Dclear()Sets all vector components to 0.intCompares the length of the vector with another one.Forcefully fits the vector in the given AABB.Forcefully fits the vector in the given AABB specified by the 2 given points.copy()Copy.final Vec3DCalculates cross-product with vector v.final Vec3Dfinal Vec3DcrossInto(ReadonlyVec3D v, Vec3D result) Calculates cross-product with vector v.final Vec3DCalculates cross-product with vector v.final floatCalculates distance to another vector.final floatCalculates the squared distance to another vector.final floatdot(ReadonlyVec3D v) Computes the scalar product (dot product) with the given vector.final floatbooleanReturns true if the Object v is of type ReadonlyVec3D and all of the data members of v are equal to the corresponding data members in this vector.booleanReturns true if the Object v is of type ReadonlyVec3D and all of the data members of v are equal to the corresponding data members in this vector.booleanequalsWithTolerance(ReadonlyVec3D v, float tolerance) Compares this vector with the one given.final Vec3Dfloor()Replaces the vector components with integer values of their current values.final Vec3Dfrac()Replaces the vector components with the fractional part of their current values.static final Vec3DfromXYTheta(float theta) Creates a new vector from the given angle in the XY plane.static final Vec3DfromXZTheta(float theta) Creates a new vector from the given angle in the XZ plane.static final Vec3DfromYZTheta(float theta) Creates a new vector from the given angle in the YZ plane.final Vec3DgetAbs()Gets the abs.Converts the spherical vector back into cartesian coordinates.final Vec3D.AxisIdentifies the closest cartesian axis to this vector.final floatgetComponent(int id) final floatfinal Vec3DgetConstrained(AABB box) Creates a copy of the vector which forcefully fits in the given AABB.final Vec3DCreates a new vector whose components are the integer value of their current values.final Vec3DgetFrac()Creates a new vector whose components are the fractional part of their current values.final Vec3DScales vector uniformly by factor -1 ( v = -v ).final Vec3DgetLimited(float lim) Creates a copy of the vector with its magnitude limited to the length given.Produces a new vector with its coordinates passed through the givenScaleMap.final Vec3DProduces the normalized version as a new vector.final Vec3DgetNormalizedTo(float len) Produces a new vector normalized to the given length.final Vec3DReturns a multiplicative inverse copy of the vector.final Vec3DgetReflected(ReadonlyVec3D normal) final Vec3DgetRotatedAroundAxis(ReadonlyVec3D axis, float theta) Gets the rotated around axis.final Vec3DgetRotatedX(float theta) Creates a new vector rotated by the given angle around the X axis.final Vec3DgetRotatedY(float theta) Creates a new vector rotated by the given angle around the Y axis.final Vec3DgetRotatedZ(float theta) Creates a new vector rotated by the given angle around the Z axis.getRoundedTo(float prec) Creates a new vector with its coordinates rounded to the given precision (grid alignment).final Vec3DCreates a new vector in which all components are replaced with the signum of their original values.Converts the vector into spherical coordinates.inthashCode()Returns a hash code value based on the data values in this object.final floatComputes the vector's direction in the XY plane (for example for 2D points).final floatComputes the vector's direction in the XZ plane.final floatComputes the vector's direction in the YZ plane.final Vec3DinterpolateTo(ReadonlyVec3D v, float f) Interpolates the vector towards the given target vector, using linear interpolation.final Vec3DinterpolateTo(ReadonlyVec3D v, float f, InterpolateStrategy s) Interpolates the vector towards the given target vector, using the givenInterpolateStrategy.final Vec3DinterpolateTo(Vec3D v, float f) final Vec3DinterpolateTo(Vec3D v, float f, InterpolateStrategy s) final Vec3DinterpolateToSelf(ReadonlyVec3D v, float f) Interpolates the vector towards the given target vector, using linear interpolation.final Vec3DinterpolateToSelf(ReadonlyVec3D v, float f, InterpolateStrategy s) Interpolates the vector towards the given target vector, using the givenInterpolateStrategy.final Vec3Dinvert()Scales vector uniformly by factor -1 ( v = -v ), overrides coordinates with result.booleanChecks if the point is inside the given AABB.booleanChecks if the point is inside the given axis-aligned bounding box.final booleanisMajorAxis(float tol) Checks if the vector is parallel with either the X or Y axis (any direction).final booleanChecks if vector has a magnitude equals or close to zero (tolerance used isMathUtils.EPS).final Vec3Djitter(float j) Add random jitter to the vector in the range -j ...final Vec3Djitter(float jx, float jy, float jz) Adds random jitter to the vector in the range -j ...final Vec3Dfinal Vec3Dfinal Vec3Dfinal Vec3Dfinal Vec3Dlimit(float lim) Limits the vector's magnitude to the length given.final floatCalculates the magnitude/eucledian length of the vector.final floatCalculates only the squared magnitude/length of the vector.static final Vec3Dmax(ReadonlyVec3D a, ReadonlyVec3D b) Constructs a new vector consisting of the largest components of both vectors.final Vec3DMax self.static final Vec3Dmin(ReadonlyVec3D a, ReadonlyVec3D b) Constructs a new vector consisting of the smallest components of both vectors.final Vec3DMin self.final Vec3DmodSelf(float base) Applies a uniform modulo operation to the vector, using the same base for all components.final Vec3DmodSelf(float bx, float by, float bz) Calculates modulo operation for each vector component separately.final Vec3DNormalizes the vector so that its magnitude = 1.final Vec3DnormalizeTo(float len) Normalizes the vector to the given length.static final Vec3DStatic factory method.static final Vec3DrandomVector(Random rnd) Static factory method.final Vec3DReplaces the vector components with their multiplicative inverse.final Vec3Dreflect(ReadonlyVec3D normal) final Vec3DrotateAroundAxis(ReadonlyVec3D axis, float theta) Rotates the vector around the giving axis.final Vec3DrotateX(float theta) Rotates the vector by the given angle around the X axis.final Vec3DrotateY(float theta) Rotates the vector by the given angle around the Y axis.final Vec3DrotateZ(float theta) Rotates the vector by the given angle around the Z axis.roundTo(float prec) scale(float s) Scales vector uniformly and returns result as new vector.scale(float a, float b, float c) Scales vector non-uniformly and returns result as new vector.Scales vector non-uniformly by vector v and returns result as new vector.scaleSelf(float s) Scales vector uniformly and overrides coordinates with result.scaleSelf(float a, float b, float c) Scales vector non-uniformly by vector {a,b,c} and overrides coordinates with result.Scales vector non-uniformly by vector v and overrides coordinates with result.set(float x, float y, float z) Overrides coordinates with the given values.set(ReadonlyVec3D v) Overrides coordinates with the ones of the given vector.final Vec3DsetComponent(int id, float val) final Vec3DsetComponent(Vec3D.Axis id, float val) setX(float x) Overrides XY coordinates with the ones of the given 2D vector.setY(float y) setZ(float z) shuffle(int iterations) signum()Replaces all vector components with the signum of their original values.final Vec3DRounds the vector to the closest major axis.final Vec3Dsub(float a, float b, float c) Subtracts vector {a,b,c} and returns result as new vector.final Vec3Dsub(ReadonlyVec3D v) Subtracts vector v and returns result as new vector.final Vec3Dfinal Vec3DsubSelf(float a, float b, float c) Subtracts vector {a,b,c} and overrides coordinates with result.final Vec3Dfinal Vec3DSubtracts vector v and overrides coordinates with result.final Vec2Dto2DXY()Creates a new 2D vector of the XY components.final Vec2Dto2DXZ()Creates a new 2D vector of the XZ components.final Vec2Dto2DYZ()Creates a new 2D vector of the YZ components.to4D()Creates a Vec4D instance of this vector with the w component set to 1.0to4D(float w) Creates a Vec4D instance of this vector with it w component set to the given value.float[]toArray()float[]toArray4(float w) final Vec3Dfinal Vec3DtoString()final floatx()final floaty()final floatz()
-
Field Details
-
X_AXIS
Defines positive X axis. -
Y_AXIS
Defines positive Y axis. -
Z_AXIS
Defines positive Z axis. -
ZERO
Defines the zero vector. -
MIN_VALUE
Defines vector with all coords set to Float.MIN_VALUE. Useful for bounding box operations. -
MAX_VALUE
Defines vector with all coords set to Float.MAX_VALUE. Useful for bounding box operations. -
NEG_MAX_VALUE
-
x
public float xX coordinate. -
y
public float yY coordinate. -
z
public float zZ coordinate.
-
-
Constructor Details
-
Vec3D
public Vec3D()Creates a new zero vector. -
Vec3D
public Vec3D(float x, float y, float z) Creates a new vector with the given coordinates.- Parameters:
x- the xy- the yz- the z
-
Vec3D
public Vec3D(float[] v) -
Vec3D
Creates a new vector with the coordinates of the given vector.- Parameters:
v- vector to be copied
-
-
Method Details
-
fromXYTheta
Creates a new vector from the given angle in the XY plane. The Z component of the vector will be zero. The resulting vector for theta=0 is equal to the positive X axis.- Parameters:
theta- the theta- Returns:
- new vector in the XY plane
-
fromXZTheta
Creates a new vector from the given angle in the XZ plane. The Y component of the vector will be zero. The resulting vector for theta=0 is equal to the positive X axis.- Parameters:
theta- the theta- Returns:
- new vector in the XZ plane
-
fromYZTheta
Creates a new vector from the given angle in the YZ plane. The X component of the vector will be zero. The resulting vector for theta=0 is equal to the positive Y axis.- Parameters:
theta- the theta- Returns:
- new vector in the YZ plane
-
max
Constructs a new vector consisting of the largest components of both vectors.- Parameters:
b- the ba- the a- Returns:
- result as new vector
-
min
Constructs a new vector consisting of the smallest components of both vectors.- Parameters:
b- comparing vectora- the a- Returns:
- result as new vector
-
randomVector
Static factory method. Creates a new random unit vector using the Random implementation set as default for theMathUtilsclass.- Returns:
- a new random normalized unit vector.
-
randomVector
Static factory method. Creates a new random unit vector using the given Random generator instance. I recommend to have a look at the https://uncommons-maths.dev.java.net library for a good choice of reliable and high quality random number generators.- Parameters:
rnd- the rnd- Returns:
- a new random normalized unit vector.
-
abs
Abs.- Returns:
- the vec3 d
-
add
Description copied from interface:ReadonlyVec3DAdds vector {a,b,c} and returns result as new vector.- Specified by:
addin interfaceReadonlyVec3D- Parameters:
a- X coordinateb- Y coordinatec- Z coordinate- Returns:
- result as new vector
-
add
- Specified by:
addin interfaceReadonlyVec3D
-
add
Description copied from interface:ReadonlyVec3DAdd vector v and returns result as new vector.- Specified by:
addin interfaceReadonlyVec3D- Parameters:
v- vector to add- Returns:
- result as new vector
-
addSelf
Adds vector {a,b,c} and overrides coordinates with result.- Parameters:
a- X coordinateb- Y coordinatec- Z coordinate- Returns:
- itself
-
addSelf
-
addSelf
Adds vector v and overrides coordinates with result.- Parameters:
v- vector to add- Returns:
- itself
-
angleBetween
Description copied from interface:ReadonlyVec3DComputes the angle between this vector and vector V. This function assumes both vectors are normalized, if this can't be guaranteed, use the alternative implementationReadonlyVec3D.angleBetween(ReadonlyVec3D, boolean)- Specified by:
angleBetweenin interfaceReadonlyVec3D- Parameters:
v- vector- Returns:
- angle in radians, or NaN if vectors are parallel
-
angleBetween
Description copied from interface:ReadonlyVec3DComputes the angle between this vector and vector V.- Specified by:
angleBetweenin interfaceReadonlyVec3D- Parameters:
v- vectorforceNormalize- true, if normalized versions of the vectors are to be used (Note: only copies will be used, original vectors will not be altered by this method)- Returns:
- angle in radians, or NaN if vectors are parallel
-
clear
Sets all vector components to 0.- Returns:
- itself
-
compareTo
Description copied from interface:ReadonlyVec3DCompares the length of the vector with another one.- Specified by:
compareToin interfaceComparable<ReadonlyVec3D>- Specified by:
compareToin interfaceReadonlyVec3D- Parameters:
v- vector to compare with- Returns:
- -1 if other vector is longer, 0 if both are equal or else +1
-
constrain
Forcefully fits the vector in the given AABB.- Parameters:
box- the box- Returns:
- itself
-
constrain
Forcefully fits the vector in the given AABB specified by the 2 given points.- Parameters:
min-max-- Returns:
- itself
-
copy
Description copied from interface:ReadonlyVec3DCopy.- Specified by:
copyin interfaceReadonlyVec3D- Returns:
- a new independent instance/copy of a given vector
-
cross
Description copied from interface:ReadonlyVec3DCalculates cross-product with vector v. The resulting vector is perpendicular to both the current and supplied vector.- Specified by:
crossin interfaceReadonlyVec3D- Parameters:
v- vector to cross- Returns:
- cross-product as new vector
-
cross
-
crossInto
Description copied from interface:ReadonlyVec3DCalculates cross-product with vector v. The resulting vector is perpendicular to both the current and supplied vector and stored in the supplied result vector.- Specified by:
crossIntoin interfaceReadonlyVec3D- Parameters:
v- vector to crossresult- result vector- Returns:
- result vector
-
crossSelf
Calculates cross-product with vector v. The resulting vector is perpendicular to both the current and supplied vector and overrides the current.- Parameters:
v- the v- Returns:
- itself
-
distanceTo
Description copied from interface:ReadonlyVec3DCalculates distance to another vector.- Specified by:
distanceToin interfaceReadonlyVec3D- Parameters:
v- non-null vector- Returns:
- distance or Float.NaN if v=null
-
distanceToSquared
Description copied from interface:ReadonlyVec3DCalculates the squared distance to another vector.- Specified by:
distanceToSquaredin interfaceReadonlyVec3D- Parameters:
v- non-null vector- Returns:
- distance or NaN if v=null
- See Also:
-
dot
Description copied from interface:ReadonlyVec3DComputes the scalar product (dot product) with the given vector.- Specified by:
dotin interfaceReadonlyVec3D- Parameters:
v- the v- Returns:
- dot product
- See Also:
-
dot
-
equals
Returns true if the Object v is of type ReadonlyVec3D and all of the data members of v are equal to the corresponding data members in this vector.- Specified by:
equalsin interfaceReadonlyVec3D- Overrides:
equalsin classObject- Parameters:
v- the Object with which the comparison is made- Returns:
- true or false
-
equals
Returns true if the Object v is of type ReadonlyVec3D and all of the data members of v are equal to the corresponding data members in this vector.- Parameters:
v- the vector with which the comparison is made- Returns:
- true or false
-
equalsWithTolerance
Description copied from interface:ReadonlyVec3DCompares this vector with the one given. The vectors are deemed equal if the individual differences of all component values are within the given tolerance.- Specified by:
equalsWithTolerancein interfaceReadonlyVec3D- Parameters:
v- the vtolerance- the tolerance- Returns:
- true, if equal
-
floor
Replaces the vector components with integer values of their current values.- Returns:
- itself
-
frac
Replaces the vector components with the fractional part of their current values.- Returns:
- itself
-
getAbs
Description copied from interface:ReadonlyVec3DGets the abs.- Specified by:
getAbsin interfaceReadonlyVec3D- Returns:
- the abs
-
getCartesian
Description copied from interface:ReadonlyVec3DConverts the spherical vector back into cartesian coordinates.- Specified by:
getCartesianin interfaceReadonlyVec3D- Returns:
- new vector
-
getClosestAxis
Identifies the closest cartesian axis to this vector. If at leat two vector components are equal, no unique decision can be made and the method returns null.- Specified by:
getClosestAxisin interfaceReadonlyVec3D- Returns:
- Axis enum or null
-
getComponent
- Specified by:
getComponentin interfaceReadonlyVec3D
-
getComponent
public final float getComponent(int id) - Specified by:
getComponentin interfaceReadonlyVec3D
-
getConstrained
Description copied from interface:ReadonlyVec3DCreates a copy of the vector which forcefully fits in the given AABB.- Specified by:
getConstrainedin interfaceReadonlyVec3D- Parameters:
box- the box- Returns:
- fitted vector
-
getFloored
Description copied from interface:ReadonlyVec3DCreates a new vector whose components are the integer value of their current values.- Specified by:
getFlooredin interfaceReadonlyVec3D- Returns:
- result as new vector
-
getFrac
Description copied from interface:ReadonlyVec3DCreates a new vector whose components are the fractional part of their current values.- Specified by:
getFracin interfaceReadonlyVec3D- Returns:
- result as new vector
-
getInverted
Description copied from interface:ReadonlyVec3DScales vector uniformly by factor -1 ( v = -v ).- Specified by:
getInvertedin interfaceReadonlyVec3D- Returns:
- result as new vector
-
getLimited
Description copied from interface:ReadonlyVec3DCreates a copy of the vector with its magnitude limited to the length given.- Specified by:
getLimitedin interfaceReadonlyVec3D- Parameters:
lim- new maximum magnitude- Returns:
- result as new vector
-
getMapped
Description copied from interface:ReadonlyVec3DProduces a new vector with its coordinates passed through the givenScaleMap.- Specified by:
getMappedin interfaceReadonlyVec3D- Returns:
- mapped vector
-
getNormalized
Description copied from interface:ReadonlyVec3DProduces the normalized version as a new vector.- Specified by:
getNormalizedin interfaceReadonlyVec3D- Returns:
- new vector
-
getNormalizedTo
Description copied from interface:ReadonlyVec3DProduces a new vector normalized to the given length.- Specified by:
getNormalizedToin interfaceReadonlyVec3D- Parameters:
len- new desired length- Returns:
- new vector
-
getReciprocal
Description copied from interface:ReadonlyVec3DReturns a multiplicative inverse copy of the vector.- Specified by:
getReciprocalin interfaceReadonlyVec3D- Returns:
- new vector
-
getReflected
- Specified by:
getReflectedin interfaceReadonlyVec3D
-
getRotatedAroundAxis
Description copied from interface:ReadonlyVec3DGets the rotated around axis.- Specified by:
getRotatedAroundAxisin interfaceReadonlyVec3D- Parameters:
axis- the axistheta- the theta- Returns:
- new result vector
-
getRotatedX
Description copied from interface:ReadonlyVec3DCreates a new vector rotated by the given angle around the X axis.- Specified by:
getRotatedXin interfaceReadonlyVec3D- Parameters:
theta- the theta- Returns:
- rotated vector
-
getRotatedY
Description copied from interface:ReadonlyVec3DCreates a new vector rotated by the given angle around the Y axis.- Specified by:
getRotatedYin interfaceReadonlyVec3D- Parameters:
theta- the theta- Returns:
- rotated vector
-
getRotatedZ
Description copied from interface:ReadonlyVec3DCreates a new vector rotated by the given angle around the Z axis.- Specified by:
getRotatedZin interfaceReadonlyVec3D- Parameters:
theta- the theta- Returns:
- rotated vector
-
getRoundedTo
Description copied from interface:ReadonlyVec3DCreates a new vector with its coordinates rounded to the given precision (grid alignment).- Specified by:
getRoundedToin interfaceReadonlyVec3D- Returns:
- grid aligned vector
-
getSignum
Description copied from interface:ReadonlyVec3DCreates a new vector in which all components are replaced with the signum of their original values. In other words if a components value was negative its new value will be -1, if zero => 0, if positive => +1- Specified by:
getSignumin interfaceReadonlyVec3D- Returns:
- result vector
-
getSpherical
Description copied from interface:ReadonlyVec3DConverts the vector into spherical coordinates. After the conversion the vector components are to be interpreted as:- x = radius
- y = azimuth
- z = theta
- Specified by:
getSphericalin interfaceReadonlyVec3D- Returns:
- new vector
-
hashCode
public int hashCode()Returns a hash code value based on the data values in this object. Two different Vec3D objects with identical data values (i.e., Vec3D.equals returns true) will return the same hash code value. Two objects with different data members may return the same hash value, although this is not likely. -
headingXY
public final float headingXY()Description copied from interface:ReadonlyVec3DComputes the vector's direction in the XY plane (for example for 2D points). The positive X axis equals 0 degrees.- Specified by:
headingXYin interfaceReadonlyVec3D- Returns:
- rotation angle
-
headingXZ
public final float headingXZ()Description copied from interface:ReadonlyVec3DComputes the vector's direction in the XZ plane. The positive X axis equals 0 degrees.- Specified by:
headingXZin interfaceReadonlyVec3D- Returns:
- rotation angle
-
headingYZ
public final float headingYZ()Description copied from interface:ReadonlyVec3DComputes the vector's direction in the YZ plane. The positive Z axis equals 0 degrees.- Specified by:
headingYZin interfaceReadonlyVec3D- Returns:
- rotation angle
-
immutable
-
interpolateTo
Description copied from interface:ReadonlyVec3DInterpolates the vector towards the given target vector, using linear interpolation.- Specified by:
interpolateToin interfaceReadonlyVec3D- Parameters:
v- target vectorf- interpolation factor (should be in the range 0..1)- Returns:
- result as new vector
-
interpolateTo
Description copied from interface:ReadonlyVec3DInterpolates the vector towards the given target vector, using the givenInterpolateStrategy.- Specified by:
interpolateToin interfaceReadonlyVec3D- Parameters:
v- target vectorf- interpolation factor (should be in the range 0..1)s- InterpolateStrategy instance- Returns:
- result as new vector
-
interpolateTo
-
interpolateTo
-
interpolateToSelf
Interpolates the vector towards the given target vector, using linear interpolation.- Parameters:
v- target vectorf- interpolation factor (should be in the range 0..1)- Returns:
- itself, result overrides current vector
-
interpolateToSelf
Interpolates the vector towards the given target vector, using the givenInterpolateStrategy.- Parameters:
v- target vectorf- interpolation factor (should be in the range 0..1)s- InterpolateStrategy instance- Returns:
- itself, result overrides current vector
-
invert
Scales vector uniformly by factor -1 ( v = -v ), overrides coordinates with result.- Returns:
- itself
-
isInAABB
Description copied from interface:ReadonlyVec3DChecks if the point is inside the given AABB.- Specified by:
isInAABBin interfaceReadonlyVec3D- Parameters:
box- bounding box to check- Returns:
- true, if point is inside
-
isInAABB
Description copied from interface:ReadonlyVec3DChecks if the point is inside the given axis-aligned bounding box.- Specified by:
isInAABBin interfaceReadonlyVec3D- Parameters:
boxOrigin- bounding box origin/centerboxExtent- bounding box extends (half measure)- Returns:
- true, if point is inside the box
-
isMajorAxis
public final boolean isMajorAxis(float tol) Description copied from interface:ReadonlyVec3DChecks if the vector is parallel with either the X or Y axis (any direction).- Specified by:
isMajorAxisin interfaceReadonlyVec3D- Returns:
- true, if parallel within the given tolerance
-
isZeroVector
public final boolean isZeroVector()Description copied from interface:ReadonlyVec3DChecks if vector has a magnitude equals or close to zero (tolerance used isMathUtils.EPS).- Specified by:
isZeroVectorin interfaceReadonlyVec3D- Returns:
- true, if zero vector
-
jitter
Add random jitter to the vector in the range -j ... +j using the defaultRandomgenerator ofMathUtils.- Parameters:
j- the j- Returns:
- the vec3 d
-
jitter
Adds random jitter to the vector in the range -j ... +j using the defaultRandomgenerator ofMathUtils.- Parameters:
jx- maximum x jitterjy- maximum y jitterjz- maximum z jitter- Returns:
- itself
-
jitter
-
jitter
-
jitter
-
jitter
Adds random jitter to the vector in the range defined by the given vector components and using the defaultRandomgenerator ofMathUtils.- Parameters:
jitterVec- the jitter vec- Returns:
- itself
-
limit
Limits the vector's magnitude to the length given.- Parameters:
lim- new maximum magnitude- Returns:
- itself
-
magnitude
public final float magnitude()Description copied from interface:ReadonlyVec3DCalculates the magnitude/eucledian length of the vector.- Specified by:
magnitudein interfaceReadonlyVec3D- Returns:
- vector length
-
magSquared
public final float magSquared()Description copied from interface:ReadonlyVec3DCalculates only the squared magnitude/length of the vector. Useful for inverse square law applications and/or for speed reasons or if the real eucledian distance is not required (e.g. sorting).- Specified by:
magSquaredin interfaceReadonlyVec3D- Returns:
- squared magnitude (x^2 + y^2 + z^2)
-
maxSelf
Max self.- Parameters:
b- the b- Returns:
- the vec3 d
-
minSelf
Min self.- Parameters:
b- the b- Returns:
- the vec3 d
-
modSelf
Applies a uniform modulo operation to the vector, using the same base for all components.- Parameters:
base- the base- Returns:
- itself
-
modSelf
Calculates modulo operation for each vector component separately.- Parameters:
bx- the bxby- the bybz- the bz- Returns:
- itself
-
normalize
Normalizes the vector so that its magnitude = 1.- Returns:
- itself
-
normalizeTo
Normalizes the vector to the given length.- Parameters:
len- desired length- Returns:
- itself
-
reciprocal
Replaces the vector components with their multiplicative inverse.- Returns:
- itself
-
reflect
-
rotateAroundAxis
Rotates the vector around the giving axis.- Parameters:
axis- rotation axis vectortheta- rotation angle (in radians)- Returns:
- itself
-
rotateX
Rotates the vector by the given angle around the X axis.- Parameters:
theta- the theta- Returns:
- itself
-
rotateY
Rotates the vector by the given angle around the Y axis.- Parameters:
theta- the theta- Returns:
- itself
-
rotateZ
Rotates the vector by the given angle around the Z axis.- Parameters:
theta- the theta- Returns:
- itself
-
roundTo
-
scale
Description copied from interface:ReadonlyVec3DScales vector uniformly and returns result as new vector.- Specified by:
scalein interfaceReadonlyVec3D- Parameters:
s- scale factor- Returns:
- new vector
-
scale
Description copied from interface:ReadonlyVec3DScales vector non-uniformly and returns result as new vector.- Specified by:
scalein interfaceReadonlyVec3D- Parameters:
a- scale factor for X coordinateb- scale factor for Y coordinatec- scale factor for Z coordinate- Returns:
- new vector
-
scale
Description copied from interface:ReadonlyVec3DScales vector non-uniformly by vector v and returns result as new vector.- Specified by:
scalein interfaceReadonlyVec3D- Parameters:
s- scale vector- Returns:
- new vector
-
scale
-
scaleSelf
Scales vector uniformly and overrides coordinates with result.- Parameters:
s- scale factor- Returns:
- itself
-
scaleSelf
Scales vector non-uniformly by vector {a,b,c} and overrides coordinates with result.- Parameters:
a- scale factor for X coordinateb- scale factor for Y coordinatec- scale factor for Z coordinate- Returns:
- itself
-
scaleSelf
-
scaleSelf
Scales vector non-uniformly by vector v and overrides coordinates with result.- Parameters:
s- scale vector- Returns:
- itself
-
set
Overrides coordinates with the given values.- Parameters:
x- the xy- the yz- the z- Returns:
- itself
-
set
-
set
Overrides coordinates with the ones of the given vector.- Parameters:
v- vector to be copied- Returns:
- itself
-
setComponent
-
setComponent
-
setX
-
setXY
Overrides XY coordinates with the ones of the given 2D vector.- Parameters:
v- 2D vector- Returns:
- itself
-
setY
-
setZ
-
shuffle
-
signum
Replaces all vector components with the signum of their original values. In other words if a components value was negative its new value will be -1, if zero => 0, if positive => +1- Returns:
- itself
-
snapToAxis
Rounds the vector to the closest major axis. Assumes the vector is normalized.- Returns:
- itself
-
sub
Description copied from interface:ReadonlyVec3DSubtracts vector {a,b,c} and returns result as new vector.- Specified by:
subin interfaceReadonlyVec3D- Parameters:
a- X coordinateb- Y coordinatec- Z coordinate- Returns:
- result as new vector
-
sub
Description copied from interface:ReadonlyVec3DSubtracts vector v and returns result as new vector.- Specified by:
subin interfaceReadonlyVec3D- Parameters:
v- vector to be subtracted- Returns:
- result as new vector
-
sub
-
subSelf
Subtracts vector {a,b,c} and overrides coordinates with result.- Parameters:
a- X coordinateb- Y coordinatec- Z coordinate- Returns:
- itself
-
subSelf
-
subSelf
Subtracts vector v and overrides coordinates with result.- Parameters:
v- vector to be subtracted- Returns:
- itself
-
to2DXY
Description copied from interface:ReadonlyVec3DCreates a new 2D vector of the XY components.- Specified by:
to2DXYin interfaceReadonlyVec3D- Returns:
- new vector
-
to2DXZ
Description copied from interface:ReadonlyVec3DCreates a new 2D vector of the XZ components.- Specified by:
to2DXZin interfaceReadonlyVec3D- Returns:
- new vector
-
to2DYZ
Description copied from interface:ReadonlyVec3DCreates a new 2D vector of the YZ components.- Specified by:
to2DYZin interfaceReadonlyVec3D- Returns:
- new vector
-
to4D
Description copied from interface:ReadonlyVec3DCreates a Vec4D instance of this vector with the w component set to 1.0- Specified by:
to4Din interfaceReadonlyVec3D- Returns:
- 4d vector
-
to4D
Description copied from interface:ReadonlyVec3DCreates a Vec4D instance of this vector with it w component set to the given value.- Specified by:
to4Din interfaceReadonlyVec3D- Returns:
- weighted 4d vector
-
toArray
public float[] toArray()- Specified by:
toArrayin interfaceReadonlyVec3D
-
toArray4
public float[] toArray4(float w) - Specified by:
toArray4in interfaceReadonlyVec3D
-
toCartesian
-
toSpherical
-
toString
-
x
public final float x()- Specified by:
xin interfaceReadonlyVec3D
-
y
public final float y()- Specified by:
yin interfaceReadonlyVec3D
-
z
public final float z()- Specified by:
zin interfaceReadonlyVec3D
-