Package toxi.geom
Interface ReadonlyVec2D
- All Known Implementing Classes:
Circle
,Ellipse
,Ray2D
,Vec2D
,VerletParticle2D
public interface ReadonlyVec2D
Readonly, immutable interface wrapper for Vec2D instances. Used throughout
the library for safety purposes.
-
Method Summary
Modifier and TypeMethodDescriptionadd
(float a, float b) Adds vector {a,b,c} and returns result as new vector.add
(ReadonlyVec2D v) Add vector v and returns result as new vector.float
Computes the angle between this vector and vector V.float
angleBetween
(ReadonlyVec2D v, boolean forceNormalize) Computes the angle between this vector and vector VComputes the perpendicular bisector of two points.int
Compares the length of the vector with another one.copy()
float
Calculates the cross-product with the given vector.float
Calculates distance to another vectorfloat
Calculates the squared distance to another vectorfloat
dot
(ReadonlyVec2D v) Computes the scalar product (dot product) with the given vector.boolean
boolean
equalsWithTolerance
(ReadonlyVec2D v, float tolerance) Compares this vector with the one given.getAbs()
Converts the vector from polar to Cartesian space.float
getComponent
(int id) float
Creates a copy of the vector which forcefully fits in the given rectangle.Creates a new vector whose components are the integer value of their current valuesgetFrac()
Creates a new vector whose components are the fractional part of their current valuesScales vector uniformly by factor -1 ( v = -v )getLimited
(float lim) Creates a copy of the vector with its magnitude limited to the length givenProduces a new vector with its coordinates passed through the givenScaleMap
.Produces the normalized version as a new vectorgetNormalizedTo
(float len) Produces a new vector normalized to the given length.getPolar()
Converts the current vector into polar coordinates.getReflected
(ReadonlyVec2D normal) getRotated
(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.float
heading()
Computes the vector's direction in the XY plane (for example for 2D points).interpolateTo
(ReadonlyVec2D v, float f) Interpolates the vector towards the given target vector, using linear interpolationinterpolateTo
(ReadonlyVec2D v, float f, InterpolateStrategy s) Interpolates the vector towards the given target vector, using the givenInterpolateStrategy
boolean
isInCircle
(ReadonlyVec2D sO, float sR) Checks if the point is inside the given sphere.boolean
Checks if the point is inside the given rectangle.boolean
isInTriangle
(Vec2D a, Vec2D b, Vec2D c) Checks if point vector is inside the triangle created by the points a, b and c.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 vectorfloat
Calculates only the squared magnitude/length of the vector.max
(ReadonlyVec2D v) Constructs a new vector consisting of the largest components of both vectors.min
(ReadonlyVec2D v) Constructs a new vector consisting of the smallest components of both vectors.scale
(float s) Scales vector uniformly and returns result as new vector.scale
(float a, float b) Scales vector non-uniformly and returns result as new vector.Scales vector non-uniformly by vector v and returns result as new vectorsub
(float a, float b) Subtracts vector {a,b,c} and returns result as new vector.sub
(ReadonlyVec2D v) Subtracts vector v and returns result as new vector.tangentNormalOfEllipse
(Vec2D eO, Vec2D eR) Calculates the normal vector on the given ellipse in the direction of the current point.to3DXY()
Creates a 3D version of this vector in the XY plane.to3DXZ()
Creates a 3D version of this vector in the XZ plane.to3DYZ()
Creates a 3D version of this vector in the YZ plane.float[]
toArray()
float
x()
float
y()
-
Method Details
-
add
Adds vector {a,b,c} and returns result as new vector.- Parameters:
a
- X coordinateb
- Y coordinate- Returns:
- result as new vector
-
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(ReadonlyVec2D, 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
-
bisect
Computes the perpendicular bisector of two points.- Parameters:
p
- other point- Returns:
- bisector coefficients as
Vec3D
-
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
Vec2D copy()- Returns:
- a new independent instance/copy of a given vector
-
cross
Calculates the cross-product with the given vector.- Parameters:
v
- vector- Returns:
- the magnitude of the vector that would result from a regular 3D cross product of the input vectors, taking their Z values implicitly as 0 (i.e. treating the 2D space as a plane in the 3D space). The 3D cross product will be perpendicular to that plane, and thus have 0 X & Y components (thus the scalar returned is the Z value of the 3D cross product vector).
- See Also:
-
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
-- 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
Vec2D getAbs() -
getCartesian
Vec2D getCartesian()Converts the vector from polar to Cartesian space. Assumes this order: x=radius, y=theta- Returns:
- new vector
-
getComponent
-
getComponent
float getComponent(int id) -
getConstrained
Creates a copy of the vector which forcefully fits in the given rectangle.- Parameters:
r
-- Returns:
- fitted vector
-
getFloored
Vec2D getFloored()Creates a new vector whose components are the integer value of their current values- Returns:
- result as new vector
-
getFrac
Vec2D getFrac()Creates a new vector whose components are the fractional part of their current values- Returns:
- result as new vector
-
getInverted
Vec2D 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
Vec2D 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
-
getPerpendicular
Vec2D getPerpendicular() -
getPolar
Vec2D getPolar()Converts the current vector into polar coordinates. After the conversion the x component of the vector contains the radius (magnitude) and y the rotation angle.- Returns:
- new vector
-
getReciprocal
Vec2D getReciprocal() -
getReflected
-
getRotated
Creates a new vector rotated by the given angle around the Z axis.- Parameters:
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
Vec2D 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
-
heading
float heading()Computes the vector's direction in the XY plane (for example for 2D points). The positive X 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
-
isInCircle
Checks if the point is inside the given sphere.- Parameters:
sO
- circle origin/centresR
- circle radius- Returns:
- true, if point is in sphere
-
isInRectangle
Checks if the point is inside the given rectangle.- Parameters:
r
- bounding rectangle- Returns:
- true, if point is inside
-
isInTriangle
Checks if point vector is inside the triangle created by the points a, b and c. These points will create a plane and the point checked will have to be on this plane in the region between a,b,c. Note: The triangle must be defined in clockwise order a,b,c- Returns:
- true, if point is in triangle.
-
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). Please note the vector should contain cartesian (not polar) coordinates in order for this function to work. The magnitude of polar vectors is stored in the x component.- Returns:
- squared magnitude (x^2 + y^2)
-
max
Constructs a new vector consisting of the largest components of both vectors.- Parameters:
v
-- Returns:
- result as new vector
-
min
Constructs a new vector consisting of the smallest components of both vectors.- Parameters:
v
- comparing vector- Returns:
- result as new vector
-
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 coordinate- Returns:
- new vector
-
scale
-
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 coordinate- Returns:
- result as new vector
-
sub
-
sub
Subtracts vector v and returns result as new vector.- Parameters:
v
- vector to be subtracted- Returns:
- result as new vector
-
tangentNormalOfEllipse
Calculates the normal vector on the given ellipse in the direction of the current point.- Parameters:
eO
- ellipse origin/centreeR
- ellipse radii- Returns:
- a unit normal vector to the tangent plane of the ellipsoid in the point.
-
to3DXY
Vec3D to3DXY()Creates a 3D version of this vector in the XY plane.- Returns:
- 3D vector
-
to3DXZ
Vec3D to3DXZ()Creates a 3D version of this vector in the XZ plane. (The 2D Y coordinate interpreted as Z)- Returns:
- 3D vector
-
to3DYZ
Vec3D to3DYZ()Creates a 3D version of this vector in the YZ plane. (The 2D X coordinate interpreted as Y & 2D Y as Z)- Returns:
- 3D vector
-
toArray
float[] toArray() -
x
float x() -
y
float y()
-