Package org.web3d.util.spatial
Class Vec3DDouble
java.lang.Object
org.web3d.util.spatial.Vec3DDouble
- All Implemented Interfaces:
Comparable<ReadonlyVec3DDouble>
,ReadonlyVec3DDouble
public class Vec3DDouble
extends Object
implements Comparable<ReadonlyVec3DDouble>, ReadonlyVec3DDouble
Comprehensive 3D vector class with additional basic intersection and
collision detection features.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ReadonlyVec3DDouble
Defines vector with all coords set to Double.MAX_VALUE.static final ReadonlyVec3DDouble
Defines vector with all coords set to Double.MIN_VALUE.double
X coordinate.static final ReadonlyVec3DDouble
Defines positive X axis.double
Y coordinate.static final ReadonlyVec3DDouble
Defines positive Y axis.double
Z coordinate.static final ReadonlyVec3DDouble
Defines positive Z axis.static final ReadonlyVec3DDouble
Defines the zero vector. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new zero vector.Vec3DDouble
(double[] v) Vec3DDouble
(double x, double y, double z) Creates a new vector with the given coordinates.Creates a new vector with the coordinates of the given vector. -
Method Summary
Modifier and TypeMethodDescriptionfinal Vec3DDouble
abs()
Abs.final Vec3DDouble
add
(double a, double b, double c) Adds vector {a,b,c} and returns result as new vector.final Vec3DDouble
add
(Vec3DDouble v) Add vector v and returns result as new vector.final Vec3DDouble
addSelf
(double a, double b, double c) Adds vector {a,b,c} and overrides coordinates with result.final Vec3DDouble
final Vec3DDouble
Adds vector v and overrides coordinates with result.final double
Computes the angle between this vector and vector V.final double
angleBetween
(ReadonlyVec3DDouble v, boolean forceNormalize) Computes the angle between this vector and vector V.final ReadonlyVec3DDouble
clear()
Sets all vector components to 0.int
Compares the length of the vector with another one.final Vec3DDouble
constrain
(toxi.geom.AABB box) Forcefully fits the vector in the given AABB.final Vec3DDouble
constrain
(toxi.geom.Vec3D min, toxi.geom.Vec3D max) Forcefully fits the vector in the given AABB specified by the 2 given points.copy()
Copy.final Vec3DDouble
Calculates cross-product with vector v.final Vec3DDouble
cross
(Vec3DDouble v) final Vec3DDouble
crossInto
(ReadonlyVec3DDouble v, Vec3DDouble result) Calculates cross-product with vector v.final Vec3DDouble
Calculates cross-product with vector v.final double
Calculates distance to another vector.final double
Calculates the squared distance to another vector.final double
Computes the scalar product (dot product) with the given vector.final double
dot
(Vec3DDouble v) boolean
Returns true if the Object v is of type ReadonlyVec3DDouble and all of the data members of v are equal to the corresponding data members in this vector.boolean
Returns true if the Object v is of type ReadonlyVec3DDouble and all of the data members of v are equal to the corresponding data members in this vector.boolean
equalsWithTolerance
(ReadonlyVec3DDouble v, double tolerance) Compares this vector with the one given.final Vec3DDouble
floor()
Replaces the vector components with integer values of their current values.final Vec3DDouble
frac()
Replaces the vector components with the fractional part of their current values.static Vec3DDouble
fromXYTheta
(double theta) Creates a new vector from the given angle in the XY plane.static Vec3DDouble
fromXZTheta
(double theta) Creates a new vector from the given angle in the XZ plane.static Vec3DDouble
fromYZTheta
(double theta) Creates a new vector from the given angle in the YZ plane.final Vec3DDouble
getAbs()
Gets the abs.Converts the spherical vector back into cartesian coordinates.final double
getComponent
(int id) final double
final Vec3DDouble
getConstrained
(toxi.geom.AABB box) Creates a copy of the vector which forcefully fits in the given AABB.final Vec3DDouble
Creates a new vector whose components are the integer value of their current values.final Vec3DDouble
getFrac()
Creates a new vector whose components are the fractional part of their current values.final Vec3DDouble
Scales vector uniformly by factor -1 ( v = -v ).final Vec3DDouble
getLimited
(double lim) Creates a copy of the vector with its magnitude limited to the length given.getMapped
(toxi.math.ScaleMap map) Produces a new vector with its coordinates passed through the givenScaleMap
.final Vec3DDouble
Produces the normalized version as a new vector.final Vec3DDouble
getNormalizedTo
(double len) Produces a new vector normalized to the given length.final Vec3DDouble
Returns a multiplicative inverse copy of the vector.final Vec3DDouble
getReflected
(ReadonlyVec3DDouble normal) final Vec3DDouble
getRotatedAroundAxis
(ReadonlyVec3DDouble axis, double theta) Gets the rotated around axis.final Vec3DDouble
getRotatedX
(double theta) Creates a new vector rotated by the given angle around the X axis.final Vec3DDouble
getRotatedY
(double theta) Creates a new vector rotated by the given angle around the Y axis.final Vec3DDouble
getRotatedZ
(double theta) Creates a new vector rotated by the given angle around the Z axis.final Vec3DDouble
Creates a new vector in which all components are replaced with the signum of their original values.Converts the vector into spherical coordinates.int
hashCode()
Returns a hash code value based on the data values in this object.final double
Computes the vector's direction in the XY plane (for example for 2D points).final double
Computes the vector's direction in the XZ plane.final double
Computes the vector's direction in the YZ plane.final Vec3DDouble
interpolateTo
(ReadonlyVec3DDouble v, double f) Interpolates the vector towards the given target vector, using linear interpolation.final Vec3DDouble
interpolateTo
(ReadonlyVec3DDouble v, double f, toxi.math.InterpolateStrategy s) Interpolates the vector towards the given target vector, using the givenInterpolateStrategy
.final Vec3DDouble
interpolateTo
(Vec3DDouble v, double f) final Vec3DDouble
interpolateTo
(Vec3DDouble v, double f, toxi.math.InterpolateStrategy s) final Vec3DDouble
interpolateToSelf
(ReadonlyVec3DDouble v, double f) Interpolates the vector towards the given target vector, using linear interpolation.final Vec3DDouble
interpolateToSelf
(ReadonlyVec3DDouble v, double f, toxi.math.InterpolateStrategy s) Interpolates the vector towards the given target vector, using the givenInterpolateStrategy
.final Vec3DDouble
invert()
Scales vector uniformly by factor -1 ( v = -v ), overrides coordinates with result.boolean
isInAABB
(Vec3DDouble boxOrigin, Vec3DDouble boxExtent) Checks if the point is inside the given axis-aligned bounding box.boolean
isInAABB
(toxi.geom.AABB box) Checks if the point is inside the given AABB.final boolean
isMajorAxis
(double tol) Checks if the vector is parallel with either the X or Y axis (any direction).final boolean
Checks if vector has a magnitude equals or close to zero (tolerance used isMathUtils.EPS
).final Vec3DDouble
jitter
(double j) Add random jitter to the vector in the range -j ...final Vec3DDouble
jitter
(double jx, double jy, double jz) Adds random jitter to the vector in the range -j ...final Vec3DDouble
final Vec3DDouble
final Vec3DDouble
jitter
(Random rnd, Vec3DDouble jitterVec) final Vec3DDouble
jitter
(Vec3DDouble jitterVec) Adds random jitter to the vector in the range defined by the given vector components and using the defaultRandom
generator ofMathUtils
.final Vec3DDouble
limit
(double lim) Limits the vector's magnitude to the length given.final double
Calculates the magnitude/eucledian length of the vector.final double
Calculates only the squared magnitude/length of the vector.static Vec3DDouble
Constructs a new vector consisting of the largest components of both vectors.final Vec3DDouble
Max self.static Vec3DDouble
Constructs a new vector consisting of the smallest components of both vectors.final Vec3DDouble
Min self.final Vec3DDouble
modSelf
(double base) Applies a uniform modulo operation to the vector, using the same base for all components.final Vec3DDouble
modSelf
(double bx, double by, double bz) Calculates modulo operation for each vector component separately.final Vec3DDouble
Normalizes the vector so that its magnitude = 1.final Vec3DDouble
normalizeTo
(double len) Normalizes the vector to the given length.static Vec3DDouble
Static factory method.static Vec3DDouble
randomVector
(Random rnd) Static factory method.final Vec3DDouble
Replaces the vector components with their multiplicative inverse.final Vec3DDouble
reflect
(ReadonlyVec3DDouble normal) final Vec3DDouble
rotateAroundAxis
(ReadonlyVec3DDouble axis, double theta) Rotates the vector around the giving axis.final Vec3DDouble
rotateX
(double theta) Rotates the vector by the given angle around the X axis.final Vec3DDouble
rotateY
(double theta) Rotates the vector by the given angle around the Y axis.final Vec3DDouble
rotateZ
(double theta) Rotates the vector by the given angle around the Z axis.scale
(double s) Scales vector uniformly and returns result as new vector.scale
(double a, double b, double c) Scales vector non-uniformly and returns result as new vector.Scales vector non-uniformly by vector v and returns result as new vector.scale
(Vec3DDouble s) scaleSelf
(double s) Scales vector uniformly and overrides coordinates with result.scaleSelf
(double a, double b, double 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
(double x, double y, double z) Overrides coordinates with the given values.set
(Vec3DDouble v) Overrides coordinates with the ones of the given vector.final Vec3DDouble
setComponent
(int id, double val) final Vec3DDouble
setComponent
(Vec3DDouble.Axis id, double val) setX
(double x) setXY
(toxi.geom.Vec2D v) Overrides XY coordinates with the ones of the given 2D vector.setY
(double y) setZ
(double z) shuffle
(int iterations) signum()
Replaces all vector components with the signum of their original values.final Vec3DDouble
Rounds the vector to the closest major axis.final Vec3DDouble
sub
(double a, double b, double c) Subtracts vector {a,b,c} and returns result as new vector.final Vec3DDouble
Subtracts vector v and returns result as new vector.final Vec3DDouble
sub
(Vec3DDouble v) final Vec3DDouble
subSelf
(double a, double b, double c) Subtracts vector {a,b,c} and overrides coordinates with result.final Vec3DDouble
final Vec3DDouble
Subtracts vector v and overrides coordinates with result.final toxi.geom.Vec2D
to2DXY()
Creates a new 2D vector of the XY components.final toxi.geom.Vec2D
to2DXZ()
Creates a new 2D vector of the XZ components.final toxi.geom.Vec2D
to2DYZ()
Creates a new 2D vector of the YZ components.double[]
toArray()
double[]
toArray4
(double w) final Vec3DDouble
final Vec3DDouble
toString()
final double
x()
final double
y()
final double
z()
-
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 Double.MIN_VALUE. Useful for bounding box operations. -
MAX_VALUE
Defines vector with all coords set to Double.MAX_VALUE. Useful for bounding box operations. -
x
public double xX coordinate. -
y
public double yY coordinate. -
z
public double zZ coordinate.
-
-
Constructor Details
-
Vec3DDouble
public Vec3DDouble()Creates a new zero vector. -
Vec3DDouble
public Vec3DDouble(double x, double y, double z) Creates a new vector with the given coordinates.- Parameters:
x
- the xy
- the yz
- the z
-
Vec3DDouble
public Vec3DDouble(double[] v) -
Vec3DDouble
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:
a
- the ab
- the b- Returns:
- result as new vector
-
min
Constructs a new vector consisting of the smallest components of both vectors.- Parameters:
a
- the ab
- comparing vector- Returns:
- result as new vector
-
randomVector
Static factory method. Creates a new random unit vector using the Random implementation set as default for theMathUtils
class.- 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
-
add
Description copied from interface:ReadonlyVec3DDouble
Adds vector {a,b,c} and returns result as new vector.- Specified by:
add
in interfaceReadonlyVec3DDouble
- Parameters:
a
- X coordinateb
- Y coordinatec
- Z coordinate- Returns:
- result as new vector
-
add
- Specified by:
add
in interfaceReadonlyVec3DDouble
-
add
Description copied from interface:ReadonlyVec3DDouble
Add vector v and returns result as new vector.- Specified by:
add
in interfaceReadonlyVec3DDouble
- 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:ReadonlyVec3DDouble
Computes the angle between this vector and vector V. This function assumes both vectors are normalized, if this can't be guaranteed, use the alternative implementationReadonlyVec3DDouble.angleBetween(ReadonlyVec3DDouble, boolean)
- Specified by:
angleBetween
in interfaceReadonlyVec3DDouble
- Parameters:
v
- vector- Returns:
- angle in radians, or NaN if vectors are parallel
-
angleBetween
Description copied from interface:ReadonlyVec3DDouble
Computes the angle between this vector and vector V.- Specified by:
angleBetween
in interfaceReadonlyVec3DDouble
- 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
-
compareTo
Description copied from interface:ReadonlyVec3DDouble
Compares the length of the vector with another one.- Specified by:
compareTo
in interfaceComparable<ReadonlyVec3DDouble>
- Specified by:
compareTo
in interfaceReadonlyVec3DDouble
- 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:ReadonlyVec3DDouble
Copy.- Specified by:
copy
in interfaceReadonlyVec3DDouble
- Returns:
- a new independent instance/copy of a given vector
-
cross
Description copied from interface:ReadonlyVec3DDouble
Calculates cross-product with vector v. The resulting vector is perpendicular to both the current and supplied vector.- Specified by:
cross
in interfaceReadonlyVec3DDouble
- Parameters:
v
- vector to cross- Returns:
- cross-product as new vector
-
cross
-
crossInto
Description copied from interface:ReadonlyVec3DDouble
Calculates 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:
crossInto
in interfaceReadonlyVec3DDouble
- 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:ReadonlyVec3DDouble
Calculates distance to another vector.- Specified by:
distanceTo
in interfaceReadonlyVec3DDouble
- Parameters:
v
- non-null vector- Returns:
- distance or Float.NaN if v=null
-
distanceToSquared
Description copied from interface:ReadonlyVec3DDouble
Calculates the squared distance to another vector.- Specified by:
distanceToSquared
in interfaceReadonlyVec3DDouble
- Parameters:
v
- non-null vector- Returns:
- distance or NaN if v=null
- See Also:
-
dot
Description copied from interface:ReadonlyVec3DDouble
Computes the scalar product (dot product) with the given vector.- Specified by:
dot
in interfaceReadonlyVec3DDouble
- Parameters:
v
- the v- Returns:
- dot product
- See Also:
-
dot
-
equals
Returns true if the Object v is of type ReadonlyVec3DDouble and all of the data members of v are equal to the corresponding data members in this vector.- Specified by:
equals
in interfaceReadonlyVec3DDouble
- Overrides:
equals
in 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 ReadonlyVec3DDouble 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:ReadonlyVec3DDouble
Compares 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:
equalsWithTolerance
in interfaceReadonlyVec3DDouble
- 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:ReadonlyVec3DDouble
Gets the abs.- Specified by:
getAbs
in interfaceReadonlyVec3DDouble
- Returns:
- the abs
-
getCartesian
Description copied from interface:ReadonlyVec3DDouble
Converts the spherical vector back into cartesian coordinates.- Specified by:
getCartesian
in interfaceReadonlyVec3DDouble
- Returns:
- new vector
-
getComponent
- Specified by:
getComponent
in interfaceReadonlyVec3DDouble
-
getComponent
public final double getComponent(int id) - Specified by:
getComponent
in interfaceReadonlyVec3DDouble
-
getConstrained
Description copied from interface:ReadonlyVec3DDouble
Creates a copy of the vector which forcefully fits in the given AABB.- Specified by:
getConstrained
in interfaceReadonlyVec3DDouble
- Parameters:
box
- the box- Returns:
- fitted vector
-
getFloored
Description copied from interface:ReadonlyVec3DDouble
Creates a new vector whose components are the integer value of their current values.- Specified by:
getFloored
in interfaceReadonlyVec3DDouble
- Returns:
- result as new vector
-
getFrac
Description copied from interface:ReadonlyVec3DDouble
Creates a new vector whose components are the fractional part of their current values.- Specified by:
getFrac
in interfaceReadonlyVec3DDouble
- Returns:
- result as new vector
-
getInverted
Description copied from interface:ReadonlyVec3DDouble
Scales vector uniformly by factor -1 ( v = -v ).- Specified by:
getInverted
in interfaceReadonlyVec3DDouble
- Returns:
- result as new vector
-
getLimited
Description copied from interface:ReadonlyVec3DDouble
Creates a copy of the vector with its magnitude limited to the length given.- Specified by:
getLimited
in interfaceReadonlyVec3DDouble
- Parameters:
lim
- new maximum magnitude- Returns:
- result as new vector
-
getMapped
Description copied from interface:ReadonlyVec3DDouble
Produces a new vector with its coordinates passed through the givenScaleMap
.- Specified by:
getMapped
in interfaceReadonlyVec3DDouble
- Parameters:
map
-- Returns:
- mapped vector
-
getNormalized
Description copied from interface:ReadonlyVec3DDouble
Produces the normalized version as a new vector.- Specified by:
getNormalized
in interfaceReadonlyVec3DDouble
- Returns:
- new vector
-
getNormalizedTo
Description copied from interface:ReadonlyVec3DDouble
Produces a new vector normalized to the given length.- Specified by:
getNormalizedTo
in interfaceReadonlyVec3DDouble
- Parameters:
len
- new desired length- Returns:
- new vector
-
getReciprocal
Description copied from interface:ReadonlyVec3DDouble
Returns a multiplicative inverse copy of the vector.- Specified by:
getReciprocal
in interfaceReadonlyVec3DDouble
- Returns:
- new vector
-
getReflected
- Specified by:
getReflected
in interfaceReadonlyVec3DDouble
-
getRotatedAroundAxis
Description copied from interface:ReadonlyVec3DDouble
Gets the rotated around axis.- Specified by:
getRotatedAroundAxis
in interfaceReadonlyVec3DDouble
- Parameters:
axis
- the axistheta
- the theta- Returns:
- new result vector
-
getRotatedX
Description copied from interface:ReadonlyVec3DDouble
Creates a new vector rotated by the given angle around the X axis.- Specified by:
getRotatedX
in interfaceReadonlyVec3DDouble
- Parameters:
theta
- the theta- Returns:
- rotated vector
-
getRotatedY
Description copied from interface:ReadonlyVec3DDouble
Creates a new vector rotated by the given angle around the Y axis.- Specified by:
getRotatedY
in interfaceReadonlyVec3DDouble
- Parameters:
theta
- the theta- Returns:
- rotated vector
-
getRotatedZ
Description copied from interface:ReadonlyVec3DDouble
Creates a new vector rotated by the given angle around the Z axis.- Specified by:
getRotatedZ
in interfaceReadonlyVec3DDouble
- Parameters:
theta
- the theta- Returns:
- rotated vector
-
getSignum
Description copied from interface:ReadonlyVec3DDouble
Creates 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:
getSignum
in interfaceReadonlyVec3DDouble
- Returns:
- result vector
-
getSpherical
Description copied from interface:ReadonlyVec3DDouble
Converts the vector into spherical coordinates. After the conversion the vector components are to be interpreted as:- x = radius
- y = azimuth
- z = theta
- Specified by:
getSpherical
in interfaceReadonlyVec3DDouble
- Returns:
- new vector
-
hashCode
public int hashCode()Returns a hash code value based on the data values in this object. Two different Vec3DDouble objects with identical data values (i.e., Vec3DDouble.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 double headingXY()Description copied from interface:ReadonlyVec3DDouble
Computes the vector's direction in the XY plane (for example for 2D points). The positive X axis equals 0 degrees.- Specified by:
headingXY
in interfaceReadonlyVec3DDouble
- Returns:
- rotation angle
-
headingXZ
public final double headingXZ()Description copied from interface:ReadonlyVec3DDouble
Computes the vector's direction in the XZ plane. The positive X axis equals 0 degrees.- Specified by:
headingXZ
in interfaceReadonlyVec3DDouble
- Returns:
- rotation angle
-
headingYZ
public final double headingYZ()Description copied from interface:ReadonlyVec3DDouble
Computes the vector's direction in the YZ plane. The positive Z axis equals 0 degrees.- Specified by:
headingYZ
in interfaceReadonlyVec3DDouble
- Returns:
- rotation angle
-
immutable
-
interpolateTo
Description copied from interface:ReadonlyVec3DDouble
Interpolates the vector towards the given target vector, using linear interpolation.- Specified by:
interpolateTo
in interfaceReadonlyVec3DDouble
- Parameters:
v
- target vectorf
- interpolation factor (should be in the range 0..1)- Returns:
- result as new vector
-
interpolateTo
public final Vec3DDouble interpolateTo(ReadonlyVec3DDouble v, double f, toxi.math.InterpolateStrategy s) Description copied from interface:ReadonlyVec3DDouble
Interpolates the vector towards the given target vector, using the givenInterpolateStrategy
.- Specified by:
interpolateTo
in interfaceReadonlyVec3DDouble
- 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
public final Vec3DDouble interpolateToSelf(ReadonlyVec3DDouble v, double f, toxi.math.InterpolateStrategy s) 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
public boolean isInAABB(toxi.geom.AABB box) Description copied from interface:ReadonlyVec3DDouble
Checks if the point is inside the given AABB.- Specified by:
isInAABB
in interfaceReadonlyVec3DDouble
- Parameters:
box
- bounding box to check- Returns:
- true, if point is inside
-
isInAABB
Description copied from interface:ReadonlyVec3DDouble
Checks if the point is inside the given axis-aligned bounding box.- Specified by:
isInAABB
in interfaceReadonlyVec3DDouble
- Parameters:
boxOrigin
- bounding box origin/centerboxExtent
- bounding box extends (half measure)- Returns:
- true, if point is inside the box
-
isMajorAxis
public final boolean isMajorAxis(double tol) Description copied from interface:ReadonlyVec3DDouble
Checks if the vector is parallel with either the X or Y axis (any direction).- Specified by:
isMajorAxis
in interfaceReadonlyVec3DDouble
- Parameters:
tol
-- Returns:
- true, if parallel within the given tolerance
-
isZeroVector
public final boolean isZeroVector()Description copied from interface:ReadonlyVec3DDouble
Checks if vector has a magnitude equals or close to zero (tolerance used isMathUtils.EPS
).- Specified by:
isZeroVector
in interfaceReadonlyVec3DDouble
- Returns:
- true, if zero vector
-
jitter
Add random jitter to the vector in the range -j ... +j using the defaultRandom
generator ofMathUtils
.- Parameters:
j
- the j- Returns:
- the vec3 d
-
jitter
Adds random jitter to the vector in the range -j ... +j using the defaultRandom
generator 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 defaultRandom
generator 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 double magnitude()Description copied from interface:ReadonlyVec3DDouble
Calculates the magnitude/eucledian length of the vector.- Specified by:
magnitude
in interfaceReadonlyVec3DDouble
- Returns:
- vector length
-
magSquared
public final double magSquared()Description copied from interface:ReadonlyVec3DDouble
Calculates 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:
magSquared
in interfaceReadonlyVec3DDouble
- 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
-
scale
Description copied from interface:ReadonlyVec3DDouble
Scales vector uniformly and returns result as new vector.- Specified by:
scale
in interfaceReadonlyVec3DDouble
- Parameters:
s
- scale factor- Returns:
- new vector
-
scale
Description copied from interface:ReadonlyVec3DDouble
Scales vector non-uniformly and returns result as new vector.- Specified by:
scale
in interfaceReadonlyVec3DDouble
- 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:ReadonlyVec3DDouble
Scales vector non-uniformly by vector v and returns result as new vector.- Specified by:
scale
in interfaceReadonlyVec3DDouble
- 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:ReadonlyVec3DDouble
Subtracts vector {a,b,c} and returns result as new vector.- Specified by:
sub
in interfaceReadonlyVec3DDouble
- Parameters:
a
- X coordinateb
- Y coordinatec
- Z coordinate- Returns:
- result as new vector
-
sub
Description copied from interface:ReadonlyVec3DDouble
Subtracts vector v and returns result as new vector.- Specified by:
sub
in interfaceReadonlyVec3DDouble
- 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
public final toxi.geom.Vec2D to2DXY()Description copied from interface:ReadonlyVec3DDouble
Creates a new 2D vector of the XY components.- Specified by:
to2DXY
in interfaceReadonlyVec3DDouble
- Returns:
- new vector
-
to2DXZ
public final toxi.geom.Vec2D to2DXZ()Description copied from interface:ReadonlyVec3DDouble
Creates a new 2D vector of the XZ components.- Specified by:
to2DXZ
in interfaceReadonlyVec3DDouble
- Returns:
- new vector
-
to2DYZ
public final toxi.geom.Vec2D to2DYZ()Description copied from interface:ReadonlyVec3DDouble
Creates a new 2D vector of the YZ components.- Specified by:
to2DYZ
in interfaceReadonlyVec3DDouble
- Returns:
- new vector
-
toArray
public double[] toArray()- Specified by:
toArray
in interfaceReadonlyVec3DDouble
-
toArray4
public double[] toArray4(double w) - Specified by:
toArray4
in interfaceReadonlyVec3DDouble
-
toCartesian
-
toSpherical
-
toString
-
x
public final double x()- Specified by:
x
in interfaceReadonlyVec3DDouble
-
y
public final double y()- Specified by:
y
in interfaceReadonlyVec3DDouble
-
z
public final double z()- Specified by:
z
in interfaceReadonlyVec3DDouble
-