Package toxi.geom
Class Vec4D
java.lang.Object
toxi.geom.Vec4D
- All Implemented Interfaces:
Cloneable
,ReadonlyVec4D
-
Field Summary
-
Constructor Summary
ConstructorDescriptionVec4D()
Vec4D
(float x, float y, float z, float w) Vec4D
(ReadonlyVec3D v, float w) -
Method Summary
Modifier and TypeMethodDescriptionabs()
final Vec4D
add
(ReadonlyVec4D v) Add vector v and returns result as new vector.final Vec4D
addScaled
(ReadonlyVec4D t, float s) final Vec4D
addScaledSelf
(ReadonlyVec4D t, float s) final Vec4D
final Vec4D
addXYZ
(float xx, float yy, float zz) Adds vector {a,b,c} and returns result as new vector.final Vec4D
final Vec4D
addXYZSelf
(float xx, float yy, float zz) final Vec4D
final 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].clone()
int
Compares the length of the vector with another one.final Vec4D
copy()
Copy.final float
Calculates distance to another vector.final float
Calculates the squared distance to another vector.final float
dot
(ReadonlyVec4D v) Computes the scalar product (dot product) with the given vector.boolean
Returns true if the Object v is of type ReadonlyVec4D 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 Vec4D and all of the data members of v are equal to the corresponding data members in this vector.boolean
equalsWithTolerance
(ReadonlyVec4D v, float tolerance) Compares this vector with the one given.getAbs()
Gets the abs.final Vec4D
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).int
hashCode()
Returns a hash code value based on the data values in this object.final Vec4D
interpolateTo
(ReadonlyVec4D v, float t) Interpolates the vector towards the given target vector, using linear interpolation.final Vec4D
interpolateTo
(ReadonlyVec4D v, float f, InterpolateStrategy s) Interpolates the vector towards the given target vector, using the givenInterpolateStrategy
.final Vec4D
interpolateToSelf
(ReadonlyVec4D v, float t) final Vec4D
interpolateToSelf
(ReadonlyVec4D v, float f, InterpolateStrategy s) final Vec4D
final boolean
Checks if vector has a magnitude equals or close to zero (tolerance used isMathUtils.EPS
).final float
Calculates the magnitude/eucledian length of the vector.final float
Calculates only the squared magnitude/length of the vector.final Vec4D
Normalizes the vector so that its magnitude = 1.final Vec4D
normalizeTo
(float len) Normalizes the vector to the given length.final Vec4D
rotateAroundAxis
(ReadonlyVec3D axis, float theta) Rotates the vector around the giving axis.final Vec4D
rotateX
(float theta) Rotates the vector by the given angle around the X axis.final Vec4D
rotateY
(float theta) Rotates the vector by the given angle around the Y axis.final Vec4D
rotateZ
(float theta) Rotates the vector by the given angle around the Z axis.roundXYZTo
(float prec) final Vec4D
scale
(float s) Scales vector uniformly and returns result as new vector.final Vec4D
scale
(float xx, float yy, float zz, float ww) Scales vector non-uniformly and returns result as new vector.Scales vector non-uniformly by vector v and returns result as new vector.final Vec4D
scaleSelf
(float s) final Vec4D
scaleXYZSelf
(float s) final Vec4D
scaleXYZSelf
(float xscale, float yscale, float zscale) set
(float x, float y, float z, float w) Overrides coordinates with the given values.final Vec4D
set
(ReadonlyVec4D v) setW
(float w) setX
(float x) final Vec4D
setY
(float y) setZ
(float z) final Vec4D
sub
(ReadonlyVec4D v) Subtracts vector v and returns result as new vector.final Vec4D
final Vec4D
subXYZ
(float xx, float yy, float zz) Subtracts vector {a,b,c} and returns result as new vector.final Vec4D
final Vec4D
subXYZSelf
(float xx, float yy, float zz) final Vec4D
final Vec3D
to3D()
float[]
toArray()
toString()
final Vec4D
translate
(float xx, float yy, float zz) final Vec4D
unweight()
Divides each coordinate bythe weight with and sets the coordinate to the newly calculatd ones.final Vec3D
unweightInto
(Vec3D out) final float
w()
final Vec4D
weight()
Multiplies the weight with each coordinate and sets the coordinate to the newly calculatd ones.final Vec3D
weightInto
(Vec3D out) final float
x()
final float
y()
final float
z()
-
Field Details
-
x
public float xX coordinate -
y
public float yY coordinate -
z
public float zZ coordinate -
w
public float wW coordinate (weight)
-
-
Constructor Details
-
Vec4D
public Vec4D() -
Vec4D
public Vec4D(float x, float y, float z, float w) -
Vec4D
-
Vec4D
-
-
Method Details
-
abs
-
add
Description copied from interface:ReadonlyVec4D
Add vector v and returns result as new vector.- Specified by:
add
in interfaceReadonlyVec4D
- Parameters:
v
- vector to add- Returns:
- result as new vector
-
addScaled
- Specified by:
addScaled
in interfaceReadonlyVec4D
-
addScaledSelf
-
addSelf
-
addXYZ
Description copied from interface:ReadonlyVec4D
Adds vector {a,b,c} and returns result as new vector.- Specified by:
addXYZ
in interfaceReadonlyVec4D
- Parameters:
xx
- X coordinateyy
- Y coordinatezz
- Z coordinate- Returns:
- result as new vector
-
addXYZ
-
addXYZSelf
-
addXYZSelf
-
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].- Specified by:
angleBetween
in interfaceReadonlyVec4D
- Parameters:
v
- the other vector- Returns:
- the angle in radians in the range [0,PI]
-
clone
-
compareTo
Description copied from interface:ReadonlyVec4D
Compares the length of the vector with another one.- Specified by:
compareTo
in interfaceReadonlyVec4D
- Parameters:
v
- vector to compare with- Returns:
- -1 if other vector is longer, 0 if both are equal or else +1
-
copy
Description copied from interface:ReadonlyVec4D
Copy.- Specified by:
copy
in interfaceReadonlyVec4D
- Returns:
- a new independent instance/copy of a given vector
-
distanceTo
Description copied from interface:ReadonlyVec4D
Calculates distance to another vector.- Specified by:
distanceTo
in interfaceReadonlyVec4D
- Parameters:
v
- non-null vector- Returns:
- distance or Float.NaN if v=null
-
distanceToSquared
Description copied from interface:ReadonlyVec4D
Calculates the squared distance to another vector.- Specified by:
distanceToSquared
in interfaceReadonlyVec4D
- Parameters:
v
- non-null vector- Returns:
- distance or NaN if v=null
- See Also:
-
dot
Description copied from interface:ReadonlyVec4D
Computes the scalar product (dot product) with the given vector.- Specified by:
dot
in interfaceReadonlyVec4D
- Parameters:
v
- the v- Returns:
- dot product
- See Also:
-
equals
Returns true if the Object v is of type ReadonlyVec4D and all of the data members of v are equal to the corresponding data members in this vector.- Specified by:
equals
in interfaceReadonlyVec4D
- 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 Vec4D 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:ReadonlyVec4D
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 interfaceReadonlyVec4D
- Parameters:
v
- the vtolerance
- the tolerance- Returns:
- true, if equal
-
getAbs
Description copied from interface:ReadonlyVec4D
Gets the abs.- Specified by:
getAbs
in interfaceReadonlyVec4D
- Returns:
- the abs
-
getInvertedXYZ
Description copied from interface:ReadonlyVec4D
Scales vector uniformly by factor -1 ( v = -v ).- Specified by:
getInvertedXYZ
in interfaceReadonlyVec4D
- Returns:
- result as new vector
-
getMapped
Description copied from interface:ReadonlyVec4D
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 theReadonlyVec4D.getMappedXYZ(ScaleMap)
version.- Specified by:
getMapped
in interfaceReadonlyVec4D
- Returns:
- mapped vector
-
getMappedXYZ
Description copied from interface:ReadonlyVec4D
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 theReadonlyVec4D.getMapped(ScaleMap)
version.- Specified by:
getMappedXYZ
in interfaceReadonlyVec4D
- Returns:
- mapped vector
-
getNormalized
Description copied from interface:ReadonlyVec4D
Produces the normalized version as a new vector.- Specified by:
getNormalized
in interfaceReadonlyVec4D
- Returns:
- new vector
-
getNormalizedTo
Description copied from interface:ReadonlyVec4D
Produces a new vector normalized to the given length.- Specified by:
getNormalizedTo
in interfaceReadonlyVec4D
- Parameters:
len
- new desired length- Returns:
- new vector
-
getRotatedAroundAxis
Description copied from interface:ReadonlyVec4D
Gets the rotated around axis.- Specified by:
getRotatedAroundAxis
in interfaceReadonlyVec4D
- Parameters:
axis
- the axistheta
- the theta- Returns:
- new result vector
-
getRotatedX
Description copied from interface:ReadonlyVec4D
Creates a new vector rotated by the given angle around the X axis.- Specified by:
getRotatedX
in interfaceReadonlyVec4D
- Parameters:
theta
- the theta- Returns:
- rotated vector
-
getRotatedY
Description copied from interface:ReadonlyVec4D
Creates a new vector rotated by the given angle around the Y axis.- Specified by:
getRotatedY
in interfaceReadonlyVec4D
- Parameters:
theta
- the theta- Returns:
- rotated vector
-
getRotatedZ
Description copied from interface:ReadonlyVec4D
Creates a new vector rotated by the given angle around the Z axis.- Specified by:
getRotatedZ
in interfaceReadonlyVec4D
- Parameters:
theta
- the theta- Returns:
- rotated vector
-
getRoundedXYZTo
Description copied from interface:ReadonlyVec4D
Creates a new vector with its XYZ coordinates rounded to the given precision (grid alignment). The weight component remains unmodified.- Specified by:
getRoundedXYZTo
in interfaceReadonlyVec4D
- Returns:
- grid aligned vector
-
getUnweighted
- Specified by:
getUnweighted
in interfaceReadonlyVec4D
-
getWeighted
- Specified by:
getWeighted
in interfaceReadonlyVec4D
-
hashCode
public int hashCode()Returns a hash code value based on the data values in this object. Two different Vec4D objects with identical data values (i.e., Vec4D.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. -
interpolateTo
Description copied from interface:ReadonlyVec4D
Interpolates the vector towards the given target vector, using linear interpolation.- Specified by:
interpolateTo
in interfaceReadonlyVec4D
- Parameters:
v
- target vectort
- interpolation factor (should be in the range 0..1)- Returns:
- result as new vector
-
interpolateTo
Description copied from interface:ReadonlyVec4D
Interpolates the vector towards the given target vector, using the givenInterpolateStrategy
.- Specified by:
interpolateTo
in interfaceReadonlyVec4D
- Parameters:
v
- target vectorf
- interpolation factor (should be in the range 0..1)s
- InterpolateStrategy instance- Returns:
- result as new vector
-
interpolateToSelf
-
interpolateToSelf
-
invertXYZ
-
isZeroVector
public final boolean isZeroVector()Description copied from interface:ReadonlyVec4D
Checks if vector has a magnitude equals or close to zero (tolerance used isMathUtils.EPS
).- Specified by:
isZeroVector
in interfaceReadonlyVec4D
- Returns:
- true, if zero vector
-
magnitude
public final float magnitude()Description copied from interface:ReadonlyVec4D
Calculates the magnitude/eucledian length of the vector.- Specified by:
magnitude
in interfaceReadonlyVec4D
- Returns:
- vector length
-
magSquared
public final float magSquared()Description copied from interface:ReadonlyVec4D
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 interfaceReadonlyVec4D
- Returns:
- squared magnitude (x^2 + y^2 + z^2)
-
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
-
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
-
roundXYZTo
-
scale
Description copied from interface:ReadonlyVec4D
Scales vector uniformly and returns result as new vector.- Specified by:
scale
in interfaceReadonlyVec4D
- Parameters:
s
- scale factor- Returns:
- new vector
-
scale
Description copied from interface:ReadonlyVec4D
Scales vector non-uniformly and returns result as new vector.- Specified by:
scale
in interfaceReadonlyVec4D
- Parameters:
xx
- scale factor for X coordinateyy
- scale factor for Y coordinatezz
- scale factor for Z coordinate- Returns:
- new vector
-
scale
Description copied from interface:ReadonlyVec4D
Scales vector non-uniformly by vector v and returns result as new vector.- Specified by:
scale
in interfaceReadonlyVec4D
- Parameters:
s
- scale vector- Returns:
- new vector
-
scaleSelf
-
scaleSelf
-
scaleXYZSelf
-
scaleXYZSelf
-
set
Overrides coordinates with the given values.- Parameters:
x
- the xy
- the yz
- the zw
- the w- Returns:
- itself
-
set
-
setW
-
setX
-
setXYZ
-
setY
-
setZ
-
sub
Description copied from interface:ReadonlyVec4D
Subtracts vector v and returns result as new vector.- Specified by:
sub
in interfaceReadonlyVec4D
- Parameters:
v
- vector to be subtracted- Returns:
- result as new vector
-
subSelf
-
subXYZ
Description copied from interface:ReadonlyVec4D
Subtracts vector {a,b,c} and returns result as new vector.- Specified by:
subXYZ
in interfaceReadonlyVec4D
- Parameters:
xx
- X coordinateyy
- Y coordinatezz
- Z coordinate- Returns:
- result as new vector
-
subXYZ
-
subXYZSelf
-
subXYZSelf
-
to3D
-
toArray
public float[] toArray()- Specified by:
toArray
in interfaceReadonlyVec4D
-
toString
-
translate
-
unweight
Divides each coordinate bythe weight with and sets the coordinate to the newly calculatd ones. -
unweightInto
- Specified by:
unweightInto
in interfaceReadonlyVec4D
-
w
public final float w()- Specified by:
w
in interfaceReadonlyVec4D
- Returns:
- the w
-
weight
Multiplies the weight with each coordinate and sets the coordinate to the newly calculatd ones.- Returns:
- itself
-
weightInto
- Specified by:
weightInto
in interfaceReadonlyVec4D
-
x
public final float x()- Specified by:
x
in interfaceReadonlyVec4D
- Returns:
- the x
-
y
public final float y()- Specified by:
y
in interfaceReadonlyVec4D
- Returns:
- the y
-
z
public final float z()- Specified by:
z
in interfaceReadonlyVec4D
- Returns:
- the z
-