Package toxi.geom
Class Vec2D
java.lang.Object
toxi.geom.Vec2D
- All Implemented Interfaces:
Comparable<ReadonlyVec2D>
,ReadonlyVec2D
- Direct Known Subclasses:
Ellipse
,Ray2D
,VerletParticle2D
Comprehensive 2D vector class with additional basic intersection and
collision detection features.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ReadonlyVec2D
Defines vector with both coords set to Float.MAX_VALUE.static final ReadonlyVec2D
Defines vector with both coords set to Float.MIN_VALUE.static final ReadonlyVec2D
float
X coordinatestatic final ReadonlyVec2D
Defines positive X axisfloat
Y coordinatestatic final ReadonlyVec2D
Defines positive Y axisstatic final ReadonlyVec2D
Defines the zero vector. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal Vec2D
abs()
final Vec2D
add
(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.final Vec2D
final Vec2D
addSelf
(float a, float b) Adds vector {a,b,c} and overrides coordinates with result.final Vec2D
Adds vector v and overrides coordinates with result.final float
Computes the angle between this vector and vector V.final float
angleBetween
(ReadonlyVec2D v, boolean forceNormalize) Computes the angle between this vector and vector VComputes the perpendicular bisector of two points.final Vec2D
clear()
Sets all vector components to 0.int
Compares the length of the vector with another one.Constraints this vector to the perimeter of the given polygon.Forcefully fits the vector in the given rectangle.Forcefully fits the vector in the given rectangle defined by the points.final Vec2D
copy()
float
Calculates the cross-product with the given vector.final float
Calculates distance to another vectorfinal float
Calculates the squared distance to another vectorfinal float
dot
(ReadonlyVec2D v) Computes the scalar product (dot product) with the given vector.boolean
Returns true if the Object v is of type ReadonlyVec2D and all of the data members of v are equal to the corresponding data members in this vector.boolean
Returns true if all of the data members of ReadonlyVec2D v are equal to the corresponding data members in this vector.boolean
equalsWithTolerance
(ReadonlyVec2D v, float tolerance) Compares this vector with the one given.final Vec2D
floor()
Replaces the vector components with integer values of their current valuesfinal Vec2D
frac()
Replaces the vector components with the fractional part of their current valuesstatic final Vec2D
fromTheta
(float theta) Creates a new vector from the given angle in the XY plane.final Vec2D
getAbs()
Converts the vector from polar to Cartesian space.final float
getComponent
(int id) float
final Vec2D
getConstrained
(Polygon2D poly) final Vec2D
Creates a copy of the vector which forcefully fits in the given rectangle.final Vec2D
Creates a new vector whose components are the integer value of their current valuesfinal Vec2D
getFrac()
Creates a new vector whose components are the fractional part of their current valuesfinal Vec2D
Scales vector uniformly by factor -1 ( v = -v )final Vec2D
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
.final Vec2D
Produces the normalized version as a new vectorfinal Vec2D
getNormalizedTo
(float len) Produces a new vector normalized to the given length.final Vec2D
getPolar()
Converts the current vector into polar coordinates.final Vec2D
final Vec2D
getReflected
(ReadonlyVec2D normal) final Vec2D
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.int
hashCode()
Returns a hash code value based on the data values in this object.final 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
final Vec2D
interpolateTo
(Vec2D v, float f) interpolateTo
(Vec2D v, float f, InterpolateStrategy s) final Vec2D
interpolateToSelf
(ReadonlyVec2D v, float f) Interpolates the vector towards the given target vector, using linear interpolationinterpolateToSelf
(ReadonlyVec2D v, float f, InterpolateStrategy s) Interpolates the vector towards the given target vector, using the givenInterpolateStrategy
final Vec2D
invert()
Scales vector uniformly by factor -1 ( v = -v ), overrides coordinates with resultboolean
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.final boolean
isMajorAxis
(float 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 Vec2D
jitter
(float j) final Vec2D
jitter
(float jx, float jy) Adds random jitter to the vector in the range -j ...final Vec2D
final Vec2D
final Vec2D
final Vec2D
final Vec2D
limit
(float lim) Limits the vector's magnitude to the length givenfinal float
Calculates the magnitude/eucledian length of the vectorfinal float
Calculates only the squared magnitude/length of the vector.final Vec2D
max
(ReadonlyVec2D v) Constructs a new vector consisting of the largest components of both vectors.static final Vec2D
max
(ReadonlyVec2D a, ReadonlyVec2D b) Constructs a new vector consisting of the largest components of both vectors.final Vec2D
Adjusts the vector components to the maximum values of both vectorsfinal Vec2D
min
(ReadonlyVec2D v) Constructs a new vector consisting of the smallest components of both vectors.static final Vec2D
min
(ReadonlyVec2D a, ReadonlyVec2D b) Constructs a new vector consisting of the smallest components of both vectors.final Vec2D
Adjusts the vector components to the minimum values of both vectorsfinal Vec2D
Normalizes the vector so that its magnitude = 1final Vec2D
normalizeTo
(float len) Normalizes the vector to the given length.final Vec2D
final float
static final Vec2D
Static factory method.static final Vec2D
randomVector
(Random rnd) Static factory method.final Vec2D
final Vec2D
reflect
(ReadonlyVec2D normal) final Vec2D
rotate
(float theta) Rotates the vector by the given angle around the Z axis.roundTo
(float prec) final Vec2D
scale
(float s) Scales vector uniformly and returns result as new vector.final Vec2D
scale
(float a, float b) Scales vector non-uniformly and returns result as new vector.final Vec2D
final Vec2D
Scales vector non-uniformly by vector v and returns result as new vectorfinal Vec2D
scaleSelf
(float s) Scales vector uniformly and overrides coordinates with resultfinal Vec2D
scaleSelf
(float a, float b) Scales vector non-uniformly by vector {a,b,c} and overrides coordinates with resultfinal Vec2D
Scales vector non-uniformly by vector v and overrides coordinates with resultfinal Vec2D
set
(float x, float y) Overrides coordinates with the given valuesfinal Vec2D
set
(ReadonlyVec2D v) final Vec2D
Overrides coordinates with the ones of the given vectorfinal Vec2D
setComponent
(int id, float val) final Vec2D
setComponent
(Vec2D.Axis id, float val) setX
(float x) setY
(float y) final Vec2D
signum()
Replaces all vector components with the signum of their original values.final Vec2D
Rounds the vector to the closest major axis.final Vec2D
sub
(float a, float b) Subtracts vector {a,b,c} and returns result as new vector.final Vec2D
sub
(ReadonlyVec2D v) final Vec2D
Subtracts vector v and returns result as new vector.final Vec2D
subSelf
(float a, float b) Subtracts vector {a,b,c} and overrides coordinates with result.final Vec2D
Subtracts vector v and overrides coordinates with result.final Vec2D
tangentNormalOfEllipse
(Vec2D eO, Vec2D eR) Calculates the normal vector on the given ellipse in the direction of the current point.final Vec3D
to3DXY()
Creates a 3D version of this vector in the XY plane.final Vec3D
to3DXZ()
Creates a 3D version of this vector in the XZ plane.final Vec3D
to3DYZ()
Creates a 3D version of this vector in the YZ plane.float[]
toArray()
final Vec2D
final Vec2D
toPolar()
toString()
final float
x()
final float
y()
-
Field Details
-
X_AXIS
Defines positive X axis -
Y_AXIS
Defines positive Y axis -
ZERO
Defines the zero vector. -
MIN_VALUE
Defines vector with both coords set to Float.MIN_VALUE. Useful for bounding box operations. -
MAX_VALUE
Defines vector with both coords set to Float.MAX_VALUE. Useful for bounding box operations. -
NEG_MAX_VALUE
-
x
public float xX coordinate -
y
public float yY coordinate
-
-
Constructor Details
-
Vec2D
public Vec2D()Creates a new zero vector -
Vec2D
public Vec2D(float x, float y) Creates a new vector with the given coordinates- Parameters:
x
-y
-
-
Vec2D
public Vec2D(float[] v) -
Vec2D
Creates a new vector with the coordinates of the given vector- Parameters:
v
- vector to be copied
-
-
Method Details
-
fromTheta
Creates a new vector from the given angle in the XY plane. The resulting vector for theta=0 is equal to the positive X axis.- Parameters:
theta
-- Returns:
- new vector pointing into the direction of the passed in angle
-
max
Constructs a new vector consisting of the largest components of both vectors.- Parameters:
b
- the ba
- the a- Returns:
- result as new vector
-
min
Constructs a new vector consisting of the smallest components of both vectors.- Parameters:
b
- comparing vectora
- the a- 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.- Returns:
- a new random normalized unit vector.
-
abs
-
add
Description copied from interface:ReadonlyVec2D
Adds vector {a,b,c} and returns result as new vector.- Specified by:
add
in interfaceReadonlyVec2D
- Parameters:
a
- X coordinateb
- Y coordinate- Returns:
- result as new vector
-
add
Description copied from interface:ReadonlyVec2D
Add vector v and returns result as new vector.- Specified by:
add
in interfaceReadonlyVec2D
- Parameters:
v
- vector to add- Returns:
- result as new vector
-
add
-
addSelf
Adds vector {a,b,c} and overrides coordinates with result.- Parameters:
a
- X coordinateb
- Y coordinate- Returns:
- itself
-
addSelf
Adds vector v and overrides coordinates with result.- Parameters:
v
- vector to add- Returns:
- itself
-
angleBetween
Description copied from interface:ReadonlyVec2D
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 implementationReadonlyVec2D.angleBetween(ReadonlyVec2D, boolean)
- Specified by:
angleBetween
in interfaceReadonlyVec2D
- Parameters:
v
- vector- Returns:
- angle in radians, or NaN if vectors are parallel
-
angleBetween
Description copied from interface:ReadonlyVec2D
Computes the angle between this vector and vector V- Specified by:
angleBetween
in interfaceReadonlyVec2D
- 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
Description copied from interface:ReadonlyVec2D
Computes the perpendicular bisector of two points.- Specified by:
bisect
in interfaceReadonlyVec2D
- Parameters:
b
- other point- Returns:
- bisector coefficients as
Vec3D
-
clear
Sets all vector components to 0.- Returns:
- itself
-
compareTo
Description copied from interface:ReadonlyVec2D
Compares the length of the vector with another one.- Specified by:
compareTo
in interfaceComparable<ReadonlyVec2D>
- Specified by:
compareTo
in interfaceReadonlyVec2D
- Parameters:
v
- vector to compare with- Returns:
- -1 if other vector is longer, 0 if both are equal or else +1
-
constrain
Constraints this vector to the perimeter of the given polygon. Unlike theconstrain(Rect)
version of this method, this version DOES NOT check containment automatically. If you want to only constrain a point if its (for example) outside the polygon, then check containment withPolygon2D.containsPoint(ReadonlyVec2D)
first before calling this method.- Parameters:
poly
-- Returns:
- itself
-
constrain
Forcefully fits the vector in the given rectangle.- Parameters:
r
-- Returns:
- itself
-
constrain
Forcefully fits the vector in the given rectangle defined by the points.- Parameters:
min
-max
-- Returns:
- itself
-
copy
- Specified by:
copy
in interfaceReadonlyVec2D
- Returns:
- a new independent instance/copy of a given vector
-
cross
Description copied from interface:ReadonlyVec2D
Calculates the cross-product with the given vector.- Specified by:
cross
in interfaceReadonlyVec2D
- 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
Description copied from interface:ReadonlyVec2D
Calculates distance to another vector- Specified by:
distanceTo
in interfaceReadonlyVec2D
- Parameters:
v
- non-null vector- Returns:
- distance or Float.NaN if v=null
-
distanceToSquared
Description copied from interface:ReadonlyVec2D
Calculates the squared distance to another vector- Specified by:
distanceToSquared
in interfaceReadonlyVec2D
- Parameters:
v
- non-null vector- Returns:
- distance or NaN if v=null
- See Also:
-
dot
Description copied from interface:ReadonlyVec2D
Computes the scalar product (dot product) with the given vector.- Specified by:
dot
in interfaceReadonlyVec2D
- Returns:
- dot product
- See Also:
-
equals
Returns true if the Object v is of type ReadonlyVec2D and all of the data members of v are equal to the corresponding data members in this vector.- Specified by:
equals
in interfaceReadonlyVec2D
- Overrides:
equals
in classObject
- Parameters:
v
- the object with which the comparison is made- Returns:
- true or false
-
equals
Returns true if all of the data members of ReadonlyVec2D 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:ReadonlyVec2D
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 interfaceReadonlyVec2D
- 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
- Specified by:
getAbs
in interfaceReadonlyVec2D
-
getCartesian
Description copied from interface:ReadonlyVec2D
Converts the vector from polar to Cartesian space. Assumes this order: x=radius, y=theta- Specified by:
getCartesian
in interfaceReadonlyVec2D
- Returns:
- new vector
-
getComponent
- Specified by:
getComponent
in interfaceReadonlyVec2D
-
getComponent
public final float getComponent(int id) - Specified by:
getComponent
in interfaceReadonlyVec2D
-
getConstrained
-
getConstrained
Description copied from interface:ReadonlyVec2D
Creates a copy of the vector which forcefully fits in the given rectangle.- Specified by:
getConstrained
in interfaceReadonlyVec2D
- Returns:
- fitted vector
-
getFloored
Description copied from interface:ReadonlyVec2D
Creates a new vector whose components are the integer value of their current values- Specified by:
getFloored
in interfaceReadonlyVec2D
- Returns:
- result as new vector
-
getFrac
Description copied from interface:ReadonlyVec2D
Creates a new vector whose components are the fractional part of their current values- Specified by:
getFrac
in interfaceReadonlyVec2D
- Returns:
- result as new vector
-
getInverted
Description copied from interface:ReadonlyVec2D
Scales vector uniformly by factor -1 ( v = -v )- Specified by:
getInverted
in interfaceReadonlyVec2D
- Returns:
- result as new vector
-
getLimited
Description copied from interface:ReadonlyVec2D
Creates a copy of the vector with its magnitude limited to the length given- Specified by:
getLimited
in interfaceReadonlyVec2D
- Parameters:
lim
- new maximum magnitude- Returns:
- result as new vector
-
getMapped
Description copied from interface:ReadonlyVec2D
Produces a new vector with its coordinates passed through the givenScaleMap
.- Specified by:
getMapped
in interfaceReadonlyVec2D
- Returns:
- mapped vector
-
getNormalized
Description copied from interface:ReadonlyVec2D
Produces the normalized version as a new vector- Specified by:
getNormalized
in interfaceReadonlyVec2D
- Returns:
- new vector
-
getNormalizedTo
Description copied from interface:ReadonlyVec2D
Produces a new vector normalized to the given length.- Specified by:
getNormalizedTo
in interfaceReadonlyVec2D
- Parameters:
len
- new desired length- Returns:
- new vector
-
getPerpendicular
- Specified by:
getPerpendicular
in interfaceReadonlyVec2D
-
getPolar
Description copied from interface:ReadonlyVec2D
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.- Specified by:
getPolar
in interfaceReadonlyVec2D
- Returns:
- new vector
-
getReciprocal
- Specified by:
getReciprocal
in interfaceReadonlyVec2D
-
getReflected
- Specified by:
getReflected
in interfaceReadonlyVec2D
-
getRotated
Description copied from interface:ReadonlyVec2D
Creates a new vector rotated by the given angle around the Z axis.- Specified by:
getRotated
in interfaceReadonlyVec2D
- Returns:
- rotated vector
-
getRoundedTo
Description copied from interface:ReadonlyVec2D
Creates a new vector with its coordinates rounded to the given precision (grid alignment).- Specified by:
getRoundedTo
in interfaceReadonlyVec2D
- Returns:
- grid aligned vector
-
getSignum
Description copied from interface:ReadonlyVec2D
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 interfaceReadonlyVec2D
- Returns:
- result vector
-
hashCode
public int hashCode()Returns a hash code value based on the data values in this object. Two different Vec2D objects with identical data values (i.e., Vec2D.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. -
heading
public final float heading()Description copied from interface:ReadonlyVec2D
Computes the vector's direction in the XY plane (for example for 2D points). The positive X axis equals 0 degrees.- Specified by:
heading
in interfaceReadonlyVec2D
- Returns:
- rotation angle
-
interpolateTo
Description copied from interface:ReadonlyVec2D
Interpolates the vector towards the given target vector, using linear interpolation- Specified by:
interpolateTo
in interfaceReadonlyVec2D
- Parameters:
v
- target vectorf
- interpolation factor (should be in the range 0..1)- Returns:
- result as new vector
-
interpolateTo
Description copied from interface:ReadonlyVec2D
Interpolates the vector towards the given target vector, using the givenInterpolateStrategy
- Specified by:
interpolateTo
in interfaceReadonlyVec2D
- 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
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
-
isInCircle
Description copied from interface:ReadonlyVec2D
Checks if the point is inside the given sphere.- Specified by:
isInCircle
in interfaceReadonlyVec2D
- Parameters:
sO
- circle origin/centresR
- circle radius- Returns:
- true, if point is in sphere
-
isInRectangle
Description copied from interface:ReadonlyVec2D
Checks if the point is inside the given rectangle.- Specified by:
isInRectangle
in interfaceReadonlyVec2D
- Parameters:
r
- bounding rectangle- Returns:
- true, if point is inside
-
isInTriangle
Description copied from interface:ReadonlyVec2D
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- Specified by:
isInTriangle
in interfaceReadonlyVec2D
- Returns:
- true, if point is in triangle.
-
isMajorAxis
public final boolean isMajorAxis(float tol) Description copied from interface:ReadonlyVec2D
Checks if the vector is parallel with either the X or Y axis (any direction).- Specified by:
isMajorAxis
in interfaceReadonlyVec2D
- Returns:
- true, if parallel within the given tolerance
-
isZeroVector
public final boolean isZeroVector()Description copied from interface:ReadonlyVec2D
Checks if vector has a magnitude equals or close to zero (tolerance used isMathUtils.EPS
).- Specified by:
isZeroVector
in interfaceReadonlyVec2D
- Returns:
- true, if zero vector
-
jitter
-
jitter
Adds random jitter to the vector in the range -j ... +j using the defaultRandom
generator ofMathUtils
.- Parameters:
jx
- maximum x jitterjy
- maximum y jitter- Returns:
- itself
-
jitter
-
jitter
-
jitter
-
jitter
-
limit
Limits the vector's magnitude to the length given- Parameters:
lim
- new maximum magnitude- Returns:
- itself
-
magnitude
public final float magnitude()Description copied from interface:ReadonlyVec2D
Calculates the magnitude/eucledian length of the vector- Specified by:
magnitude
in interfaceReadonlyVec2D
- Returns:
- vector length
-
magSquared
public final float magSquared()Description copied from interface:ReadonlyVec2D
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.- Specified by:
magSquared
in interfaceReadonlyVec2D
- Returns:
- squared magnitude (x^2 + y^2)
-
max
Description copied from interface:ReadonlyVec2D
Constructs a new vector consisting of the largest components of both vectors.- Specified by:
max
in interfaceReadonlyVec2D
- Returns:
- result as new vector
-
maxSelf
Adjusts the vector components to the maximum values of both vectors- Parameters:
v
-- Returns:
- itself
-
min
Description copied from interface:ReadonlyVec2D
Constructs a new vector consisting of the smallest components of both vectors.- Specified by:
min
in interfaceReadonlyVec2D
- Parameters:
v
- comparing vector- Returns:
- result as new vector
-
minSelf
Adjusts the vector components to the minimum values of both vectors- Parameters:
v
-- 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
-
perpendicular
-
positiveHeading
public final float positiveHeading() -
reciprocal
-
reflect
-
rotate
Rotates the vector by the given angle around the Z axis.- Parameters:
theta
-- Returns:
- itself
-
roundTo
-
scale
Description copied from interface:ReadonlyVec2D
Scales vector uniformly and returns result as new vector.- Specified by:
scale
in interfaceReadonlyVec2D
- Parameters:
s
- scale factor- Returns:
- new vector
-
scale
Description copied from interface:ReadonlyVec2D
Scales vector non-uniformly and returns result as new vector.- Specified by:
scale
in interfaceReadonlyVec2D
- Parameters:
a
- scale factor for X coordinateb
- scale factor for Y coordinate- Returns:
- new vector
-
scale
- Specified by:
scale
in interfaceReadonlyVec2D
-
scale
Description copied from interface:ReadonlyVec2D
Scales vector non-uniformly by vector v and returns result as new vector- Specified by:
scale
in interfaceReadonlyVec2D
- Parameters:
s
- scale vector- Returns:
- new vector
-
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 coordinate- Returns:
- itself
-
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
-y
-- Returns:
- itself
-
set
-
set
Overrides coordinates with the ones of the given vector- Parameters:
v
- vector to be copied- Returns:
- itself
-
setComponent
-
setComponent
-
setX
-
setY
-
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:ReadonlyVec2D
Subtracts vector {a,b,c} and returns result as new vector.- Specified by:
sub
in interfaceReadonlyVec2D
- Parameters:
a
- X coordinateb
- Y coordinate- Returns:
- result as new vector
-
sub
- Specified by:
sub
in interfaceReadonlyVec2D
-
sub
Description copied from interface:ReadonlyVec2D
Subtracts vector v and returns result as new vector.- Specified by:
sub
in interfaceReadonlyVec2D
- Parameters:
v
- vector to be subtracted- Returns:
- result as new vector
-
subSelf
Subtracts vector {a,b,c} and overrides coordinates with result.- Parameters:
a
- X coordinateb
- Y coordinate- Returns:
- itself
-
subSelf
Subtracts vector v and overrides coordinates with result.- Parameters:
v
- vector to be subtracted- Returns:
- itself
-
tangentNormalOfEllipse
Description copied from interface:ReadonlyVec2D
Calculates the normal vector on the given ellipse in the direction of the current point.- Specified by:
tangentNormalOfEllipse
in interfaceReadonlyVec2D
- Parameters:
eO
- ellipse origin/centreeR
- ellipse radii- Returns:
- a unit normal vector to the tangent plane of the ellipsoid in the point.
-
to3DXY
Description copied from interface:ReadonlyVec2D
Creates a 3D version of this vector in the XY plane.- Specified by:
to3DXY
in interfaceReadonlyVec2D
- Returns:
- 3D vector
-
to3DXZ
Description copied from interface:ReadonlyVec2D
Creates a 3D version of this vector in the XZ plane. (The 2D Y coordinate interpreted as Z)- Specified by:
to3DXZ
in interfaceReadonlyVec2D
- Returns:
- 3D vector
-
to3DYZ
Description copied from interface:ReadonlyVec2D
Creates a 3D version of this vector in the YZ plane. (The 2D X coordinate interpreted as Y & 2D Y as Z)- Specified by:
to3DYZ
in interfaceReadonlyVec2D
- Returns:
- 3D vector
-
toArray
public float[] toArray()- Specified by:
toArray
in interfaceReadonlyVec2D
-
toCartesian
-
toPolar
-
toString
-
x
public final float x()- Specified by:
x
in interfaceReadonlyVec2D
-
y
public final float y()- Specified by:
y
in interfaceReadonlyVec2D
-