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
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ReadonlyVec2DDefines vector with both coords set to Float.MAX_VALUE.static final ReadonlyVec2DDefines vector with both coords set to Float.MIN_VALUE.static final ReadonlyVec2DfloatX coordinatestatic final ReadonlyVec2DDefines positive X axisfloatY coordinatestatic final ReadonlyVec2DDefines positive Y axisstatic final ReadonlyVec2DDefines the zero vector. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Vec2Dabs()final Vec2Dadd(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 Vec2Dfinal Vec2DaddSelf(float a, float b) Adds vector {a,b,c} and overrides coordinates with result.final Vec2DAdds vector v and overrides coordinates with result.final floatComputes the angle between this vector and vector V.final floatangleBetween(ReadonlyVec2D v, boolean forceNormalize) Computes the angle between this vector and vector VComputes the perpendicular bisector of two points.final Vec2Dclear()Sets all vector components to 0.intCompares 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 Vec2Dcopy()floatCalculates the cross-product with the given vector.final floatCalculates distance to another vectorfinal floatCalculates the squared distance to another vectorfinal floatdot(ReadonlyVec2D v) Computes the scalar product (dot product) with the given vector.booleanReturns 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.booleanReturns true if all of the data members of ReadonlyVec2D v are equal to the corresponding data members in this vector.booleanequalsWithTolerance(ReadonlyVec2D v, float tolerance) Compares this vector with the one given.final Vec2Dfloor()Replaces the vector components with integer values of their current valuesfinal Vec2Dfrac()Replaces the vector components with the fractional part of their current valuesstatic final Vec2DfromTheta(float theta) Creates a new vector from the given angle in the XY plane.final Vec2DgetAbs()Converts the vector from polar to Cartesian space.final floatgetComponent(int id) floatfinal Vec2DgetConstrained(Polygon2D poly) final Vec2DCreates a copy of the vector which forcefully fits in the given rectangle.final Vec2DCreates a new vector whose components are the integer value of their current valuesfinal Vec2DgetFrac()Creates a new vector whose components are the fractional part of their current valuesfinal Vec2DScales vector uniformly by factor -1 ( v = -v )final Vec2DgetLimited(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 Vec2DProduces the normalized version as a new vectorfinal Vec2DgetNormalizedTo(float len) Produces a new vector normalized to the given length.final Vec2DgetPolar()Converts the current vector into polar coordinates.final Vec2Dfinal Vec2DgetReflected(ReadonlyVec2D normal) final Vec2DgetRotated(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.inthashCode()Returns a hash code value based on the data values in this object.final floatheading()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 givenInterpolateStrategyfinal Vec2DinterpolateTo(Vec2D v, float f) interpolateTo(Vec2D v, float f, InterpolateStrategy s) final Vec2DinterpolateToSelf(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 givenInterpolateStrategyfinal Vec2Dinvert()Scales vector uniformly by factor -1 ( v = -v ), overrides coordinates with resultbooleanisInCircle(ReadonlyVec2D sO, float sR) Checks if the point is inside the given sphere.booleanChecks if the point is inside the given rectangle.booleanisInTriangle(Vec2D a, Vec2D b, Vec2D c) Checks if point vector is inside the triangle created by the points a, b and c.final booleanisMajorAxis(float tol) Checks if the vector is parallel with either the X or Y axis (any direction).final booleanChecks if vector has a magnitude equals or close to zero (tolerance used isMathUtils.EPS).final Vec2Djitter(float j) final Vec2Djitter(float jx, float jy) Adds random jitter to the vector in the range -j ...final Vec2Dfinal Vec2Dfinal Vec2Dfinal Vec2Dfinal Vec2Dlimit(float lim) Limits the vector's magnitude to the length givenfinal floatCalculates the magnitude/eucledian length of the vectorfinal floatCalculates only the squared magnitude/length of the vector.final Vec2Dmax(ReadonlyVec2D v) Constructs a new vector consisting of the largest components of both vectors.static final Vec2Dmax(ReadonlyVec2D a, ReadonlyVec2D b) Constructs a new vector consisting of the largest components of both vectors.final Vec2DAdjusts the vector components to the maximum values of both vectorsfinal Vec2Dmin(ReadonlyVec2D v) Constructs a new vector consisting of the smallest components of both vectors.static final Vec2Dmin(ReadonlyVec2D a, ReadonlyVec2D b) Constructs a new vector consisting of the smallest components of both vectors.final Vec2DAdjusts the vector components to the minimum values of both vectorsfinal Vec2DNormalizes the vector so that its magnitude = 1final Vec2DnormalizeTo(float len) Normalizes the vector to the given length.final Vec2Dfinal floatstatic final Vec2DStatic factory method.static final Vec2DrandomVector(Random rnd) Static factory method.final Vec2Dfinal Vec2Dreflect(ReadonlyVec2D normal) final Vec2Drotate(float theta) Rotates the vector by the given angle around the Z axis.roundTo(float prec) final Vec2Dscale(float s) Scales vector uniformly and returns result as new vector.final Vec2Dscale(float a, float b) Scales vector non-uniformly and returns result as new vector.final Vec2Dfinal Vec2DScales vector non-uniformly by vector v and returns result as new vectorfinal Vec2DscaleSelf(float s) Scales vector uniformly and overrides coordinates with resultfinal Vec2DscaleSelf(float a, float b) Scales vector non-uniformly by vector {a,b,c} and overrides coordinates with resultfinal Vec2DScales vector non-uniformly by vector v and overrides coordinates with resultfinal Vec2Dset(float x, float y) Overrides coordinates with the given valuesfinal Vec2Dset(ReadonlyVec2D v) final Vec2DOverrides coordinates with the ones of the given vectorfinal Vec2DsetComponent(int id, float val) final Vec2DsetComponent(Vec2D.Axis id, float val) setX(float x) setY(float y) final Vec2Dsignum()Replaces all vector components with the signum of their original values.final Vec2DRounds the vector to the closest major axis.final Vec2Dsub(float a, float b) Subtracts vector {a,b,c} and returns result as new vector.final Vec2Dsub(ReadonlyVec2D v) final Vec2DSubtracts vector v and returns result as new vector.final Vec2DsubSelf(float a, float b) Subtracts vector {a,b,c} and overrides coordinates with result.final Vec2DSubtracts vector v and overrides coordinates with result.final Vec2DtangentNormalOfEllipse(Vec2D eO, Vec2D eR) Calculates the normal vector on the given ellipse in the direction of the current point.final Vec3Dto3DXY()Creates a 3D version of this vector in the XY plane.final Vec3Dto3DXZ()Creates a 3D version of this vector in the XZ plane.final Vec3Dto3DYZ()Creates a 3D version of this vector in the YZ plane.float[]toArray()final Vec2Dfinal Vec2DtoPolar()toString()final floatx()final floaty()
-
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 theMathUtilsclass.- 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:ReadonlyVec2DAdds vector {a,b,c} and returns result as new vector.- Specified by:
addin interfaceReadonlyVec2D- Parameters:
a- X coordinateb- Y coordinate- Returns:
- result as new vector
-
add
Description copied from interface:ReadonlyVec2DAdd vector v and returns result as new vector.- Specified by:
addin 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:ReadonlyVec2DComputes 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:
angleBetweenin interfaceReadonlyVec2D- Parameters:
v- vector- Returns:
- angle in radians, or NaN if vectors are parallel
-
angleBetween
Description copied from interface:ReadonlyVec2DComputes the angle between this vector and vector V- Specified by:
angleBetweenin 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:ReadonlyVec2DComputes the perpendicular bisector of two points.- Specified by:
bisectin interfaceReadonlyVec2D- Parameters:
b- other point- Returns:
- bisector coefficients as
Vec3D
-
clear
Sets all vector components to 0.- Returns:
- itself
-
compareTo
Description copied from interface:ReadonlyVec2DCompares the length of the vector with another one.- Specified by:
compareToin interfaceComparable<ReadonlyVec2D>- Specified by:
compareToin 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:
copyin interfaceReadonlyVec2D- Returns:
- a new independent instance/copy of a given vector
-
cross
Description copied from interface:ReadonlyVec2DCalculates the cross-product with the given vector.- Specified by:
crossin 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:ReadonlyVec2DCalculates distance to another vector- Specified by:
distanceToin interfaceReadonlyVec2D- Parameters:
v- non-null vector- Returns:
- distance or Float.NaN if v=null
-
distanceToSquared
Description copied from interface:ReadonlyVec2DCalculates the squared distance to another vector- Specified by:
distanceToSquaredin interfaceReadonlyVec2D- Parameters:
v- non-null vector- Returns:
- distance or NaN if v=null
- See Also:
-
dot
Description copied from interface:ReadonlyVec2DComputes the scalar product (dot product) with the given vector.- Specified by:
dotin 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:
equalsin interfaceReadonlyVec2D- Overrides:
equalsin 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:ReadonlyVec2DCompares 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:
equalsWithTolerancein 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:
getAbsin interfaceReadonlyVec2D
-
getCartesian
Description copied from interface:ReadonlyVec2DConverts the vector from polar to Cartesian space. Assumes this order: x=radius, y=theta- Specified by:
getCartesianin interfaceReadonlyVec2D- Returns:
- new vector
-
getComponent
- Specified by:
getComponentin interfaceReadonlyVec2D
-
getComponent
public final float getComponent(int id) - Specified by:
getComponentin interfaceReadonlyVec2D
-
getConstrained
-
getConstrained
Description copied from interface:ReadonlyVec2DCreates a copy of the vector which forcefully fits in the given rectangle.- Specified by:
getConstrainedin interfaceReadonlyVec2D- Returns:
- fitted vector
-
getFloored
Description copied from interface:ReadonlyVec2DCreates a new vector whose components are the integer value of their current values- Specified by:
getFlooredin interfaceReadonlyVec2D- Returns:
- result as new vector
-
getFrac
Description copied from interface:ReadonlyVec2DCreates a new vector whose components are the fractional part of their current values- Specified by:
getFracin interfaceReadonlyVec2D- Returns:
- result as new vector
-
getInverted
Description copied from interface:ReadonlyVec2DScales vector uniformly by factor -1 ( v = -v )- Specified by:
getInvertedin interfaceReadonlyVec2D- Returns:
- result as new vector
-
getLimited
Description copied from interface:ReadonlyVec2DCreates a copy of the vector with its magnitude limited to the length given- Specified by:
getLimitedin interfaceReadonlyVec2D- Parameters:
lim- new maximum magnitude- Returns:
- result as new vector
-
getMapped
Description copied from interface:ReadonlyVec2DProduces a new vector with its coordinates passed through the givenScaleMap.- Specified by:
getMappedin interfaceReadonlyVec2D- Returns:
- mapped vector
-
getNormalized
Description copied from interface:ReadonlyVec2DProduces the normalized version as a new vector- Specified by:
getNormalizedin interfaceReadonlyVec2D- Returns:
- new vector
-
getNormalizedTo
Description copied from interface:ReadonlyVec2DProduces a new vector normalized to the given length.- Specified by:
getNormalizedToin interfaceReadonlyVec2D- Parameters:
len- new desired length- Returns:
- new vector
-
getPerpendicular
- Specified by:
getPerpendicularin interfaceReadonlyVec2D
-
getPolar
Description copied from interface:ReadonlyVec2DConverts 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:
getPolarin interfaceReadonlyVec2D- Returns:
- new vector
-
getReciprocal
- Specified by:
getReciprocalin interfaceReadonlyVec2D
-
getReflected
- Specified by:
getReflectedin interfaceReadonlyVec2D
-
getRotated
Description copied from interface:ReadonlyVec2DCreates a new vector rotated by the given angle around the Z axis.- Specified by:
getRotatedin interfaceReadonlyVec2D- Returns:
- rotated vector
-
getRoundedTo
Description copied from interface:ReadonlyVec2DCreates a new vector with its coordinates rounded to the given precision (grid alignment).- Specified by:
getRoundedToin interfaceReadonlyVec2D- Returns:
- grid aligned vector
-
getSignum
Description copied from interface:ReadonlyVec2DCreates 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:
getSignumin 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:ReadonlyVec2DComputes the vector's direction in the XY plane (for example for 2D points). The positive X axis equals 0 degrees.- Specified by:
headingin interfaceReadonlyVec2D- Returns:
- rotation angle
-
interpolateTo
Description copied from interface:ReadonlyVec2DInterpolates the vector towards the given target vector, using linear interpolation- Specified by:
interpolateToin interfaceReadonlyVec2D- Parameters:
v- target vectorf- interpolation factor (should be in the range 0..1)- Returns:
- result as new vector
-
interpolateTo
Description copied from interface:ReadonlyVec2DInterpolates the vector towards the given target vector, using the givenInterpolateStrategy- Specified by:
interpolateToin 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:ReadonlyVec2DChecks if the point is inside the given sphere.- Specified by:
isInCirclein interfaceReadonlyVec2D- Parameters:
sO- circle origin/centresR- circle radius- Returns:
- true, if point is in sphere
-
isInRectangle
Description copied from interface:ReadonlyVec2DChecks if the point is inside the given rectangle.- Specified by:
isInRectanglein interfaceReadonlyVec2D- Parameters:
r- bounding rectangle- Returns:
- true, if point is inside
-
isInTriangle
Description copied from interface:ReadonlyVec2DChecks 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:
isInTrianglein interfaceReadonlyVec2D- Returns:
- true, if point is in triangle.
-
isMajorAxis
public final boolean isMajorAxis(float tol) Description copied from interface:ReadonlyVec2DChecks if the vector is parallel with either the X or Y axis (any direction).- Specified by:
isMajorAxisin interfaceReadonlyVec2D- Returns:
- true, if parallel within the given tolerance
-
isZeroVector
public final boolean isZeroVector()Description copied from interface:ReadonlyVec2DChecks if vector has a magnitude equals or close to zero (tolerance used isMathUtils.EPS).- Specified by:
isZeroVectorin interfaceReadonlyVec2D- Returns:
- true, if zero vector
-
jitter
-
jitter
Adds random jitter to the vector in the range -j ... +j using the defaultRandomgenerator 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:ReadonlyVec2DCalculates the magnitude/eucledian length of the vector- Specified by:
magnitudein interfaceReadonlyVec2D- Returns:
- vector length
-
magSquared
public final float magSquared()Description copied from interface:ReadonlyVec2DCalculates 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:
magSquaredin interfaceReadonlyVec2D- Returns:
- squared magnitude (x^2 + y^2)
-
max
Description copied from interface:ReadonlyVec2DConstructs a new vector consisting of the largest components of both vectors.- Specified by:
maxin 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:ReadonlyVec2DConstructs a new vector consisting of the smallest components of both vectors.- Specified by:
minin 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:ReadonlyVec2DScales vector uniformly and returns result as new vector.- Specified by:
scalein interfaceReadonlyVec2D- Parameters:
s- scale factor- Returns:
- new vector
-
scale
Description copied from interface:ReadonlyVec2DScales vector non-uniformly and returns result as new vector.- Specified by:
scalein interfaceReadonlyVec2D- Parameters:
a- scale factor for X coordinateb- scale factor for Y coordinate- Returns:
- new vector
-
scale
- Specified by:
scalein interfaceReadonlyVec2D
-
scale
Description copied from interface:ReadonlyVec2DScales vector non-uniformly by vector v and returns result as new vector- Specified by:
scalein 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:ReadonlyVec2DSubtracts vector {a,b,c} and returns result as new vector.- Specified by:
subin interfaceReadonlyVec2D- Parameters:
a- X coordinateb- Y coordinate- Returns:
- result as new vector
-
sub
- Specified by:
subin interfaceReadonlyVec2D
-
sub
Description copied from interface:ReadonlyVec2DSubtracts vector v and returns result as new vector.- Specified by:
subin 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:ReadonlyVec2DCalculates the normal vector on the given ellipse in the direction of the current point.- Specified by:
tangentNormalOfEllipsein 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:ReadonlyVec2DCreates a 3D version of this vector in the XY plane.- Specified by:
to3DXYin interfaceReadonlyVec2D- Returns:
- 3D vector
-
to3DXZ
Description copied from interface:ReadonlyVec2DCreates a 3D version of this vector in the XZ plane. (The 2D Y coordinate interpreted as Z)- Specified by:
to3DXZin interfaceReadonlyVec2D- Returns:
- 3D vector
-
to3DYZ
Description copied from interface:ReadonlyVec2DCreates a 3D version of this vector in the YZ plane. (The 2D X coordinate interpreted as Y & 2D Y as Z)- Specified by:
to3DYZin interfaceReadonlyVec2D- Returns:
- 3D vector
-
toArray
public float[] toArray()- Specified by:
toArrayin interfaceReadonlyVec2D
-
toCartesian
-
toPolar
-
toString
-
x
public final float x()- Specified by:
xin interfaceReadonlyVec2D
-
y
public final float y()- Specified by:
yin interfaceReadonlyVec2D
-