Package toxi.geom
Interface ReadonlyVec3D
- All Known Implementing Classes:
AABB
,AudioSource
,Cone
,DLAParticle
,Plane
,PointOctree
,Ray3D
,SoundListener
,Sphere
,Vec3D
,VerletParticle3D
,Vertex
,WEVertex
public interface ReadonlyVec3D
Readonly, immutable interface wrapper for Vec3D instances. Used throughout
the library for safety purposes.
-
Method Summary
Modifier and TypeMethodDescriptionadd
(float a, float b, float c) Adds vector {a,b,c} and returns result as new vector.add
(ReadonlyVec3D v) Add vector v and returns result as new vector.float
Computes the angle between this vector and vector V.float
angleBetween
(ReadonlyVec3D v, boolean forceNormalize) Computes the angle between this vector and vector V.int
Compares the length of the vector with another one.copy()
Copy.Calculates cross-product with vector v.crossInto
(ReadonlyVec3D v, Vec3D result) Calculates cross-product with vector v.float
Calculates distance to another vector.float
Calculates the squared distance to another vector.float
dot
(ReadonlyVec3D v) Computes the scalar product (dot product) with the given vector.boolean
boolean
equalsWithTolerance
(ReadonlyVec3D v, float tolerance) Compares this vector with the one given.getAbs()
Gets the abs.Converts the spherical vector back into cartesian coordinates.float
getComponent
(int id) float
getConstrained
(AABB box) Creates a copy of the vector which forcefully fits in the given AABB.Creates a new vector whose components are the integer value of their current values.getFrac()
Creates a new vector whose components are the fractional part of their current values.Scales vector uniformly by factor -1 ( v = -v ).getLimited
(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
.Produces the normalized version as a new vector.getNormalizedTo
(float len) Produces a new vector normalized to the given length.Returns a multiplicative inverse copy of the vector.getReflected
(ReadonlyVec3D normal) getRotatedAroundAxis
(ReadonlyVec3D axis, float theta) Gets the rotated around axis.getRotatedX
(float theta) Creates a new vector rotated by the given angle around the X axis.getRotatedY
(float theta) Creates a new vector rotated by the given angle around the Y axis.getRotatedZ
(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).Creates a new vector in which all components are replaced with the signum of their original values.Converts the vector into spherical coordinates.float
Computes the vector's direction in the XY plane (for example for 2D points).float
Computes the vector's direction in the XZ plane.float
Computes the vector's direction in the YZ plane.interpolateTo
(ReadonlyVec3D v, float f) Interpolates the vector towards the given target vector, using linear interpolation.interpolateTo
(ReadonlyVec3D v, float f, InterpolateStrategy s) Interpolates the vector towards the given target vector, using the givenInterpolateStrategy
.boolean
Checks if the point is inside the given AABB.boolean
Checks if the point is inside the given axis-aligned bounding box.boolean
isMajorAxis
(float tolerance) Checks if the vector is parallel with either the X or Y axis (any direction).boolean
Checks if vector has a magnitude equals or close to zero (tolerance used isMathUtils.EPS
).float
Calculates the magnitude/eucledian length of the vector.float
Calculates only the squared magnitude/length of the vector.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.sub
(float a, float b, float c) Subtracts vector {a,b,c} and returns result as new vector.sub
(ReadonlyVec3D v) Subtracts vector v and returns result as new vector.to2DXY()
Creates a new 2D vector of the XY components.to2DXZ()
Creates a new 2D vector of the XZ components.to2DYZ()
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) float
x()
float
y()
float
z()
-
Method Details
-
add
Adds vector {a,b,c} and returns result as new vector.- Parameters:
a
- X coordinateb
- Y coordinatec
- Z coordinate- Returns:
- result as new vector
-
add
-
add
Add vector v and returns result as new vector.- Parameters:
v
- vector to add- Returns:
- result as new vector
-
angleBetween
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 implementationangleBetween(ReadonlyVec3D, boolean)
- Parameters:
v
- vector- Returns:
- angle in radians, or NaN if vectors are parallel
-
angleBetween
Computes the angle between this vector and vector V.- 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
-
compareTo
Compares the length of the vector with another one.- Parameters:
v
- vector to compare with- Returns:
- -1 if other vector is longer, 0 if both are equal or else +1
-
copy
Vec3D copy()Copy.- Returns:
- a new independent instance/copy of a given vector
-
cross
Calculates cross-product with vector v. The resulting vector is perpendicular to both the current and supplied vector.- Parameters:
v
- vector to cross- Returns:
- cross-product as new vector
-
crossInto
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.- Parameters:
v
- vector to crossresult
- result vector- Returns:
- result vector
-
distanceTo
Calculates distance to another vector.- Parameters:
v
- non-null vector- Returns:
- distance or Float.NaN if v=null
-
distanceToSquared
Calculates the squared distance to another vector.- Parameters:
v
- non-null vector- Returns:
- distance or NaN if v=null
- See Also:
-
dot
Computes the scalar product (dot product) with the given vector.- Parameters:
v
- the v- Returns:
- dot product
- See Also:
-
equals
-
equalsWithTolerance
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.- Parameters:
v
- the vtolerance
- the tolerance- Returns:
- true, if equal
-
getAbs
Vec3D getAbs()Gets the abs.- Returns:
- the abs
-
getCartesian
Vec3D getCartesian()Converts the spherical vector back into cartesian coordinates.- Returns:
- new vector
-
getClosestAxis
Vec3D.Axis getClosestAxis() -
getComponent
-
getComponent
float getComponent(int id) -
getConstrained
Creates a copy of the vector which forcefully fits in the given AABB.- Parameters:
box
- the box- Returns:
- fitted vector
-
getFloored
Vec3D getFloored()Creates a new vector whose components are the integer value of their current values.- Returns:
- result as new vector
-
getFrac
Vec3D getFrac()Creates a new vector whose components are the fractional part of their current values.- Returns:
- result as new vector
-
getInverted
Vec3D getInverted()Scales vector uniformly by factor -1 ( v = -v ).- Returns:
- result as new vector
-
getLimited
Creates a copy of the vector with its magnitude limited to the length given.- Parameters:
lim
- new maximum magnitude- Returns:
- result as new vector
-
getMapped
Produces a new vector with its coordinates passed through the givenScaleMap
.- Parameters:
map
-- Returns:
- mapped vector
-
getNormalized
Vec3D getNormalized()Produces the normalized version as a new vector.- Returns:
- new vector
-
getNormalizedTo
Produces a new vector normalized to the given length.- Parameters:
len
- new desired length- Returns:
- new vector
-
getReciprocal
Vec3D getReciprocal()Returns a multiplicative inverse copy of the vector.- Returns:
- new vector
-
getReflected
-
getRotatedAroundAxis
Gets the rotated around axis.- Parameters:
axis
- the axistheta
- the theta- Returns:
- new result vector
-
getRotatedX
Creates a new vector rotated by the given angle around the X axis.- Parameters:
theta
- the theta- Returns:
- rotated vector
-
getRotatedY
Creates a new vector rotated by the given angle around the Y axis.- Parameters:
theta
- the theta- Returns:
- rotated vector
-
getRotatedZ
Creates a new vector rotated by the given angle around the Z axis.- Parameters:
theta
- the theta- Returns:
- rotated vector
-
getRoundedTo
Creates a new vector with its coordinates rounded to the given precision (grid alignment).- Parameters:
prec
-- Returns:
- grid aligned vector
-
getSignum
Vec3D getSignum()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- Returns:
- result vector
-
getSpherical
Vec3D getSpherical()Converts the vector into spherical coordinates. After the conversion the vector components are to be interpreted as:- x = radius
- y = azimuth
- z = theta
- Returns:
- new vector
-
headingXY
float headingXY()Computes the vector's direction in the XY plane (for example for 2D points). The positive X axis equals 0 degrees.- Returns:
- rotation angle
-
headingXZ
float headingXZ()Computes the vector's direction in the XZ plane. The positive X axis equals 0 degrees.- Returns:
- rotation angle
-
headingYZ
float headingYZ()Computes the vector's direction in the YZ plane. The positive Z axis equals 0 degrees.- Returns:
- rotation angle
-
interpolateTo
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:
- result as new vector
-
interpolateTo
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:
- result as new vector
-
isInAABB
Checks if the point is inside the given AABB.- Parameters:
box
- bounding box to check- Returns:
- true, if point is inside
-
isInAABB
Checks if the point is inside the given axis-aligned bounding box.- Parameters:
boxOrigin
- bounding box origin/centerboxExtent
- bounding box extends (half measure)- Returns:
- true, if point is inside the box
-
isMajorAxis
boolean isMajorAxis(float tolerance) Checks if the vector is parallel with either the X or Y axis (any direction).- Parameters:
tolerance
-- Returns:
- true, if parallel within the given tolerance
-
isZeroVector
boolean isZeroVector()Checks if vector has a magnitude equals or close to zero (tolerance used isMathUtils.EPS
).- Returns:
- true, if zero vector
-
magnitude
float magnitude()Calculates the magnitude/eucledian length of the vector.- Returns:
- vector length
-
magSquared
float magSquared()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).- Returns:
- squared magnitude (x^2 + y^2 + z^2)
-
scale
Scales vector uniformly and returns result as new vector.- Parameters:
s
- scale factor- Returns:
- new vector
-
scale
Scales vector non-uniformly and returns result as new vector.- Parameters:
a
- scale factor for X coordinateb
- scale factor for Y coordinatec
- scale factor for Z coordinate- Returns:
- new vector
-
scale
Scales vector non-uniformly by vector v and returns result as new vector.- Parameters:
s
- scale vector- Returns:
- new vector
-
sub
Subtracts vector {a,b,c} and returns result as new vector.- Parameters:
a
- X coordinateb
- Y coordinatec
- Z coordinate- Returns:
- result as new vector
-
sub
Subtracts vector v and returns result as new vector.- Parameters:
v
- vector to be subtracted- Returns:
- result as new vector
-
to2DXY
Vec2D to2DXY()Creates a new 2D vector of the XY components.- Returns:
- new vector
-
to2DXZ
Vec2D to2DXZ()Creates a new 2D vector of the XZ components.- Returns:
- new vector
-
to2DYZ
Vec2D to2DYZ()Creates a new 2D vector of the YZ components.- Returns:
- new vector
-
to4D
Vec4D to4D()Creates a Vec4D instance of this vector with the w component set to 1.0- Returns:
- 4d vector
-
to4D
Creates a Vec4D instance of this vector with it w component set to the given value.- Parameters:
w
-- Returns:
- weighted 4d vector
-
toArray
float[] toArray() -
toArray4
float[] toArray4(float w) -
x
float x() -
y
float y() -
z
float z()
-