Package toxi.geom
Interface ReadonlyVec4D
- All Known Implementing Classes:
Vec4D
public interface ReadonlyVec4D
Readonly, immutable interface wrapper for Vec3D instances. Used throughout
the library for safety purposes.
-
Method Summary
Modifier and TypeMethodDescriptionadd
(ReadonlyVec4D v) Add vector v and returns result as new vector.addScaled
(ReadonlyVec4D t, float s) addXYZ
(float a, float b, float c) Adds vector {a,b,c} and returns result as new vector.float
Returns the (4-space) angle in radians between this vector and the vector parameter; the return value is constrained to the range [0,PI].int
Compares the length of the vector with another one.copy()
Copy.float
Calculates distance to another vector.float
Calculates the squared distance to another vector.float
dot
(ReadonlyVec4D v) Computes the scalar product (dot product) with the given vector.boolean
boolean
equalsWithTolerance
(ReadonlyVec4D v, float tolerance) Compares this vector with the one given.getAbs()
Gets the abs.Scales vector uniformly by factor -1 ( v = -v ).Produces a new vector with all of its coordinates passed through the givenScaleMap
.getMappedXYZ
(ScaleMap map) Produces a new vector with only its XYZ 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.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.getRoundedXYZTo
(float prec) Creates a new vector with its XYZ coordinates rounded to the given precision (grid alignment).interpolateTo
(ReadonlyVec4D v, float f) Interpolates the vector towards the given target vector, using linear interpolation.interpolateTo
(ReadonlyVec4D v, float f, InterpolateStrategy s) Interpolates the vector towards the given target vector, using the givenInterpolateStrategy
.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 x, float y, float z, float w) Scales vector non-uniformly and returns result as new vector.Scales vector non-uniformly by vector v and returns result as new vector.sub
(ReadonlyVec4D v) Subtracts vector v and returns result as new vector.subXYZ
(float a, float b, float c) Subtracts vector {a,b,c} and returns result as new vector.float[]
toArray()
unweightInto
(Vec3D out) float
w()
weightInto
(Vec3D out) float
x()
float
y()
float
z()
-
Method Details
-
add
Add vector v and returns result as new vector.- Parameters:
v
- vector to add- Returns:
- result as new vector
-
addScaled
-
addXYZ
Adds vector {a,b,c} and returns result as new vector.- Parameters:
a
- X coordinateb
- Y coordinatec
- Z coordinate- Returns:
- result as new vector
-
angleBetween
Returns the (4-space) angle in radians between this vector and the vector parameter; the return value is constrained to the range [0,PI].- Parameters:
v
- the other vector- Returns:
- the angle in radians in the range [0,PI]
-
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
Vec4D copy()Copy.- Returns:
- a new independent instance/copy of a given 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
Vec4D getAbs()Gets the abs.- Returns:
- the abs
-
getInvertedXYZ
Vec4D getInvertedXYZ()Scales vector uniformly by factor -1 ( v = -v ).- Returns:
- result as new vector
-
getMapped
Produces a new vector with all of its coordinates passed through the givenScaleMap
. This version also maps the w coordinate. For mapping only XYZ use thegetMappedXYZ(ScaleMap)
version.- Parameters:
map
-- Returns:
- mapped vector
-
getMappedXYZ
Produces a new vector with only its XYZ coordinates passed through the givenScaleMap
. This version keeps the original w coordinate. For mapping all XYZW, use thegetMapped(ScaleMap)
version.- Parameters:
map
-- Returns:
- mapped vector
-
getNormalized
Vec4D 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
-
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
-
getRoundedXYZTo
Creates a new vector with its XYZ coordinates rounded to the given precision (grid alignment). The weight component remains unmodified.- Parameters:
prec
-- Returns:
- grid aligned vector
-
getUnweighted
Vec4D getUnweighted() -
getWeighted
Vec4D getWeighted() -
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
-
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:
x
- scale factor for X coordinatey
- scale factor for Y coordinatez
- 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 v and returns result as new vector.- Parameters:
v
- vector to be subtracted- Returns:
- result as new vector
-
subXYZ
Subtracts vector {a,b,c} and returns result as new vector.- Parameters:
a
- X coordinateb
- Y coordinatec
- Z coordinate- Returns:
- result as new vector
-
toArray
float[] toArray() -
unweightInto
-
w
float w() -
weightInto
-
x
float x() -
y
float y() -
z
float z()
-