|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttoxi.geom.Vec2D
public class Vec2D
Comprehensive 2D vector class with additional basic intersection and collision detection features.
Nested Class Summary | |
---|---|
static class |
Vec2D.Axis
|
Field Summary | |
---|---|
static ReadonlyVec2D |
MAX_VALUE
Defines vector with both coords set to Float.MAX_VALUE. |
static ReadonlyVec2D |
MIN_VALUE
Defines vector with both coords set to Float.MIN_VALUE. |
float |
x
X coordinate |
static ReadonlyVec2D |
X_AXIS
Defines positive X axis |
float |
y
Y coordinate |
static ReadonlyVec2D |
Y_AXIS
Defines positive Y axis |
static ReadonlyVec2D |
ZERO
Defines the zero vector. |
Constructor Summary | |
---|---|
Vec2D()
Creates a new zero vector |
|
Vec2D(float x,
float y)
Creates a new vector with the given coordinates |
|
Vec2D(ReadonlyVec2D v)
Creates a new vector with the coordinates of the given vector |
Method Summary | |
---|---|
Vec2D |
abs()
|
Vec2D |
add(float a,
float b)
Adds vector {a,b,c} and returns result as new vector. |
Vec2D |
add(ReadonlyVec2D v)
Add vector v and returns result as new vector. |
Vec2D |
add(Vec2D v)
|
Vec2D |
addSelf(float a,
float b)
Adds vector {a,b,c} and overrides coordinates with result. |
Vec2D |
addSelf(Vec2D v)
Adds vector v and overrides coordinates with result. |
float |
angleBetween(ReadonlyVec2D v)
Computes the angle between this vector and vector V. |
float |
angleBetween(ReadonlyVec2D v,
boolean forceNormalize)
Computes the angle between this vector and vector V |
Vec3D |
bisect(Vec2D b)
Computes the perpendicular bisector of two points. |
Vec2D |
clear()
Sets all vector components to 0. |
int |
compareTo(ReadonlyVec2D v)
Compares the length of the vector with another one. |
Vec2D |
constrain(Rect r)
Forcefully fits the vector in the given rectangle. |
Vec2D |
constrain(Vec2D min,
Vec2D max)
Forcefully fits the vector in the given rectangle defined by the points. |
Vec2D |
copy()
|
float |
cross(ReadonlyVec2D v)
Calculates the cross-product with the given vector. |
float |
distanceTo(ReadonlyVec2D v)
Calculates distance to another vector |
float |
distanceToSquared(ReadonlyVec2D v)
Calculates the squared distance to another vector |
float |
dot(ReadonlyVec2D v)
Computes the scalar product (dot product) with the given vector. |
boolean |
equals(java.lang.Object obj)
|
boolean |
equalsWithTolerance(ReadonlyVec2D v,
float tolerance)
Compares this vector with the one given. |
Vec2D |
floor()
Replaces the vector components with integer values of their current values |
Vec2D |
frac()
Replaces the vector components with the fractional part of their current values |
static Vec2D |
fromTheta(float theta)
Creates a new vector from the given angle in the XY plane. |
Vec2D |
getAbs()
|
float |
getComponent(int id)
|
float |
getComponent(Vec2D.Axis id)
|
Vec2D |
getConstrained(Rect r)
Creates a copy of the vector which forcefully fits in the given rectangle. |
Vec2D |
getFloored()
Creates a new vector whose components are the integer value of their current values |
Vec2D |
getFrac()
Creates a new vector whose components are the fractional part of their current values |
Vec2D |
getInverted()
Scales vector uniformly by factor -1 ( v = -v ) |
Vec2D |
getLimited(float lim)
Creates a copy of the vector with its magnitude limited to the length given |
Vec2D |
getNormalized()
Produces the normalized version as a new vector |
Vec2D |
getNormalizedTo(float len)
Produces a new vector normalized to the given length. |
Vec2D |
getPerpendicular()
|
Vec2D |
getReciprocal()
|
Vec2D |
getReflected(ReadonlyVec2D normal)
|
Vec2D |
getRotated(float theta)
Creates a new vector rotated by the given angle around the Z axis. |
Vec2D |
getSignum()
Creates a new vector in which all components are replaced with the signum of their original values. |
int |
hashCode()
Returns a unique code for this vector object based on it's values. |
float |
heading()
Computes the vector's direction in the XY plane (for example for 2D points). |
Vec2D |
interpolateTo(ReadonlyVec2D v,
float f)
Interpolates the vector towards the given target vector, using linear interpolation |
Vec2D |
interpolateTo(ReadonlyVec2D v,
float f,
InterpolateStrategy s)
Interpolates the vector towards the given target vector, using the given InterpolateStrategy |
Vec2D |
interpolateTo(Vec2D v,
float f)
|
Vec2D |
interpolateTo(Vec2D v,
float f,
InterpolateStrategy s)
|
Vec2D |
interpolateToSelf(ReadonlyVec2D v,
float f)
Interpolates the vector towards the given target vector, using linear interpolation |
Vec2D |
interpolateToSelf(ReadonlyVec2D v,
float f,
InterpolateStrategy s)
Interpolates the vector towards the given target vector, using the given InterpolateStrategy |
Vec2D |
invert()
Scales vector uniformly by factor -1 ( v = -v ), overrides coordinates with result |
boolean |
isInCircle(ReadonlyVec2D sO,
float sR)
Checks if the point is inside the given sphere. |
boolean |
isInRectangle(Rect r)
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 tol)
Checks if the vector is parallel with either the X or Y axis (any direction). |
boolean |
isZeroVector()
Checks if vector has a magnitude equals or close to zero (tolerance used is MathUtils.EPS ). |
Vec2D |
jitter(float j)
|
Vec2D |
jitter(float jx,
float jy)
Adds random jitter to the vector in the range -j ... |
Vec2D |
jitter(java.util.Random rnd,
float j)
|
Vec2D |
jitter(java.util.Random rnd,
float jx,
float jy)
|
Vec2D |
jitter(java.util.Random rnd,
Vec2D jv)
|
Vec2D |
jitter(Vec2D jv)
|
Vec2D |
limit(float lim)
Limits the vector's magnitude to the length given |
float |
magnitude()
Calculates the magnitude/eucledian length of the vector |
float |
magSquared()
Calculates only the squared magnitude/length of the vector. |
Vec2D |
max(Vec2D v)
Constructs a new vector consisting of the largest components of both vectors. |
static Vec2D |
max(Vec2D a,
Vec2D b)
Constructs a new vector consisting of the largest components of both vectors. |
Vec2D |
maxSelf(Vec2D v)
Adjusts the vector components to the maximum values of both vectors |
Vec2D |
min(Vec2D v)
Constructs a new vector consisting of the smallest components of both vectors. |
static Vec2D |
min(Vec2D a,
Vec2D b)
Constructs a new vector consisting of the smallest components of both vectors. |
Vec2D |
minSelf(Vec2D v)
Adjusts the vector components to the minimum values of both vectors |
Vec2D |
normalize()
Normalizes the vector so that its magnitude = 1 |
Vec2D |
normalizeTo(float len)
Normalizes the vector to the given length. |
Vec2D |
perpendicular()
|
static Vec2D |
randomVector()
Static factory method. |
static Vec2D |
randomVector(java.util.Random rnd)
Static factory method. |
Vec2D |
reciprocal()
|
Vec2D |
reflect(ReadonlyVec2D normal)
|
Vec2D |
rotate(float theta)
Rotates the vector by the given angle around the Z axis. |
Vec2D |
roundToAxis()
Rounds the vector to the closest major axis. |
Vec2D |
scale(float s)
Scales vector uniformly and returns result as new vector. |
Vec2D |
scale(float a,
float b)
Scales vector non-uniformly and returns result as new vector. |
Vec2D |
scale(ReadonlyVec2D s)
|
Vec2D |
scale(Vec2D s)
Scales vector non-uniformly by vector v and returns result as new vector |
Vec2D |
scaleSelf(float s)
Scales vector uniformly and overrides coordinates with result |
Vec2D |
scaleSelf(float a,
float b)
Scales vector non-uniformly by vector {a,b,c} and overrides coordinates with result |
Vec2D |
scaleSelf(Vec2D s)
Scales vector non-uniformly by vector v and overrides coordinates with result |
Vec2D |
set(float x,
float y)
Overrides coordinates with the given values |
Vec2D |
set(ReadonlyVec2D v)
|
Vec2D |
set(Vec2D v)
Overrides coordinates with the ones of the given vector |
Vec2D |
setComponent(int id,
float val)
|
Vec2D |
setComponent(Vec2D.Axis id,
float val)
|
Vec2D |
signum()
Replaces all vector components with the signum of their original values. |
Vec2D |
sub(float a,
float b)
Subtracts vector {a,b,c} and returns result as new vector. |
Vec2D |
sub(ReadonlyVec2D v)
|
Vec2D |
sub(Vec2D v)
Subtracts vector v and returns result as new vector. |
Vec2D |
subSelf(float a,
float b)
Subtracts vector {a,b,c} and overrides coordinates with result. |
Vec2D |
subSelf(Vec2D v)
Subtracts vector v and overrides coordinates with result. |
Vec2D |
tangentNormalOfEllipse(Vec2D eO,
Vec2D eR)
Calculates the normal vector on the given ellipse in the direction of the current point. |
Vec3D |
to3DXY()
Creates a 3D version of this vector in the XY plane. |
Vec3D |
to3DXZ()
Creates a 3D version of this vector in the XZ plane. |
Vec3D |
to3DYZ()
Creates a 3D version of this vector in the YZ plane. |
float[] |
toArray()
|
Vec2D |
toCartesian()
Converts the vector from polar to Cartesian space. |
Vec2D |
toPolar()
Converts the current vector into polar coordinates. |
java.lang.String |
toString()
|
float |
x()
|
float |
y()
|
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final ReadonlyVec2D X_AXIS
public static final ReadonlyVec2D Y_AXIS
public static final ReadonlyVec2D ZERO
public static final ReadonlyVec2D MIN_VALUE
public static final ReadonlyVec2D MAX_VALUE
public float x
public float y
Constructor Detail |
---|
public Vec2D()
public Vec2D(float x, float y)
x
- y
- public Vec2D(ReadonlyVec2D v)
v
- vector to be copiedMethod Detail |
---|
public static final Vec2D fromTheta(float theta)
theta
-
public static final Vec2D max(Vec2D a, Vec2D b)
b
- the ba
- the a
public static final Vec2D min(Vec2D a, Vec2D b)
b
- comparing vectora
- the a
public static final Vec2D randomVector()
MathUtils
class.
public static final Vec2D randomVector(java.util.Random rnd)
public final Vec2D abs()
public final Vec2D add(float a, float b)
ReadonlyVec2D
add
in interface ReadonlyVec2D
a
- X coordinateb
- Y coordinate
public Vec2D add(ReadonlyVec2D v)
ReadonlyVec2D
add
in interface ReadonlyVec2D
v
- vector to add
public final Vec2D add(Vec2D v)
public final Vec2D addSelf(float a, float b)
a
- X coordinateb
- Y coordinate
public final Vec2D addSelf(Vec2D v)
v
- vector to add
public final float angleBetween(ReadonlyVec2D v)
ReadonlyVec2D
ReadonlyVec2D.angleBetween(ReadonlyVec2D, boolean)
angleBetween
in interface ReadonlyVec2D
v
- vector
public final float angleBetween(ReadonlyVec2D v, boolean forceNormalize)
ReadonlyVec2D
angleBetween
in interface ReadonlyVec2D
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)
public Vec3D bisect(Vec2D b)
ReadonlyVec2D
bisect
in interface ReadonlyVec2D
b
- other point
Vec3D
public final Vec2D clear()
public int compareTo(ReadonlyVec2D v)
ReadonlyVec2D
compareTo
in interface java.lang.Comparable<ReadonlyVec2D>
compareTo
in interface ReadonlyVec2D
v
- vector to compare with
public final Vec2D constrain(Rect r)
r
-
public final Vec2D constrain(Vec2D min, Vec2D max)
min
- max
-
public final Vec2D copy()
copy
in interface ReadonlyVec2D
public float cross(ReadonlyVec2D v)
ReadonlyVec2D
cross
in interface ReadonlyVec2D
v
- vector
public final float distanceTo(ReadonlyVec2D v)
ReadonlyVec2D
distanceTo
in interface ReadonlyVec2D
v
- non-null vector
public final float distanceToSquared(ReadonlyVec2D v)
ReadonlyVec2D
distanceToSquared
in interface ReadonlyVec2D
v
- non-null vector
ReadonlyVec2D.magSquared()
public final float dot(ReadonlyVec2D v)
ReadonlyVec2D
dot
in interface ReadonlyVec2D
public boolean equals(java.lang.Object obj)
equals
in interface ReadonlyVec2D
equals
in class java.lang.Object
public boolean equalsWithTolerance(ReadonlyVec2D v, float tolerance)
ReadonlyVec2D
equalsWithTolerance
in interface ReadonlyVec2D
v
- the vtolerance
- the tolerance
public final Vec2D floor()
public final Vec2D frac()
public final Vec2D getAbs()
getAbs
in interface ReadonlyVec2D
public float getComponent(Vec2D.Axis id)
getComponent
in interface ReadonlyVec2D
public final float getComponent(int id)
getComponent
in interface ReadonlyVec2D
public final Vec2D getConstrained(Rect r)
ReadonlyVec2D
getConstrained
in interface ReadonlyVec2D
public final Vec2D getFloored()
ReadonlyVec2D
getFloored
in interface ReadonlyVec2D
public final Vec2D getFrac()
ReadonlyVec2D
getFrac
in interface ReadonlyVec2D
public final Vec2D getInverted()
ReadonlyVec2D
getInverted
in interface ReadonlyVec2D
public final Vec2D getLimited(float lim)
ReadonlyVec2D
getLimited
in interface ReadonlyVec2D
lim
- new maximum magnitude
public final Vec2D getNormalized()
ReadonlyVec2D
getNormalized
in interface ReadonlyVec2D
public final Vec2D getNormalizedTo(float len)
ReadonlyVec2D
getNormalizedTo
in interface ReadonlyVec2D
len
- new desired length
public final Vec2D getPerpendicular()
getPerpendicular
in interface ReadonlyVec2D
public final Vec2D getReciprocal()
getReciprocal
in interface ReadonlyVec2D
public final Vec2D getReflected(ReadonlyVec2D normal)
getReflected
in interface ReadonlyVec2D
public final Vec2D getRotated(float theta)
ReadonlyVec2D
getRotated
in interface ReadonlyVec2D
public Vec2D getSignum()
ReadonlyVec2D
getSignum
in interface ReadonlyVec2D
public int hashCode()
hashCode
in class java.lang.Object
public final float heading()
ReadonlyVec2D
heading
in interface ReadonlyVec2D
public Vec2D interpolateTo(ReadonlyVec2D v, float f)
ReadonlyVec2D
interpolateTo
in interface ReadonlyVec2D
v
- target vectorf
- interpolation factor (should be in the range 0..1)
public Vec2D interpolateTo(ReadonlyVec2D v, float f, InterpolateStrategy s)
ReadonlyVec2D
InterpolateStrategy
interpolateTo
in interface ReadonlyVec2D
v
- target vectorf
- interpolation factor (should be in the range 0..1)s
- InterpolateStrategy instance
public final Vec2D interpolateTo(Vec2D v, float f)
public Vec2D interpolateTo(Vec2D v, float f, InterpolateStrategy s)
public final Vec2D interpolateToSelf(ReadonlyVec2D v, float f)
v
- target vectorf
- interpolation factor (should be in the range 0..1)
public Vec2D interpolateToSelf(ReadonlyVec2D v, float f, InterpolateStrategy s)
InterpolateStrategy
v
- target vectorf
- interpolation factor (should be in the range 0..1)s
- InterpolateStrategy instance
public final Vec2D invert()
public boolean isInCircle(ReadonlyVec2D sO, float sR)
ReadonlyVec2D
isInCircle
in interface ReadonlyVec2D
sO
- circle origin/centresR
- circle radius
public boolean isInRectangle(Rect r)
ReadonlyVec2D
isInRectangle
in interface ReadonlyVec2D
r
- bounding rectangle
public boolean isInTriangle(Vec2D a, Vec2D b, Vec2D c)
ReadonlyVec2D
isInTriangle
in interface ReadonlyVec2D
public final boolean isMajorAxis(float tol)
ReadonlyVec2D
isMajorAxis
in interface ReadonlyVec2D
public final boolean isZeroVector()
ReadonlyVec2D
MathUtils.EPS
).
isZeroVector
in interface ReadonlyVec2D
public final Vec2D jitter(float j)
public final Vec2D jitter(float jx, float jy)
Random
generator of MathUtils
.
jx
- maximum x jitterjy
- maximum y jitter
public final Vec2D jitter(java.util.Random rnd, float j)
public final Vec2D jitter(java.util.Random rnd, float jx, float jy)
public final Vec2D jitter(java.util.Random rnd, Vec2D jv)
public final Vec2D jitter(Vec2D jv)
public final Vec2D limit(float lim)
lim
- new maximum magnitude
public final float magnitude()
ReadonlyVec2D
magnitude
in interface ReadonlyVec2D
public final float magSquared()
ReadonlyVec2D
magSquared
in interface ReadonlyVec2D
public final Vec2D max(Vec2D v)
ReadonlyVec2D
max
in interface ReadonlyVec2D
public final Vec2D maxSelf(Vec2D v)
v
-
public final Vec2D min(Vec2D v)
ReadonlyVec2D
min
in interface ReadonlyVec2D
v
- comparing vector
public final Vec2D minSelf(Vec2D v)
v
-
public final Vec2D normalize()
public final Vec2D normalizeTo(float len)
len
- desired length
public final Vec2D perpendicular()
public final Vec2D reciprocal()
public final Vec2D reflect(ReadonlyVec2D normal)
public final Vec2D rotate(float theta)
theta
-
public final Vec2D roundToAxis()
public final Vec2D scale(float s)
ReadonlyVec2D
scale
in interface ReadonlyVec2D
s
- scale factor
public final Vec2D scale(float a, float b)
ReadonlyVec2D
scale
in interface ReadonlyVec2D
a
- scale factor for X coordinateb
- scale factor for Y coordinate
public final Vec2D scale(ReadonlyVec2D s)
scale
in interface ReadonlyVec2D
public final Vec2D scale(Vec2D s)
ReadonlyVec2D
scale
in interface ReadonlyVec2D
s
- scale vector
public final Vec2D scaleSelf(float s)
s
- scale factor
public final Vec2D scaleSelf(float a, float b)
a
- scale factor for X coordinateb
- scale factor for Y coordinate
public final Vec2D scaleSelf(Vec2D s)
s
- scale vector
public final Vec2D set(float x, float y)
x
- y
-
public final Vec2D set(ReadonlyVec2D v)
public final Vec2D set(Vec2D v)
v
- vector to be copied
public final Vec2D setComponent(Vec2D.Axis id, float val)
public final Vec2D setComponent(int id, float val)
public final Vec2D signum()
public final Vec2D sub(float a, float b)
ReadonlyVec2D
sub
in interface ReadonlyVec2D
a
- X coordinateb
- Y coordinate
public final Vec2D sub(ReadonlyVec2D v)
sub
in interface ReadonlyVec2D
public final Vec2D sub(Vec2D v)
ReadonlyVec2D
sub
in interface ReadonlyVec2D
v
- vector to be subtracted
public final Vec2D subSelf(float a, float b)
a
- X coordinateb
- Y coordinate
public final Vec2D subSelf(Vec2D v)
v
- vector to be subtracted
public final Vec2D tangentNormalOfEllipse(Vec2D eO, Vec2D eR)
ReadonlyVec2D
tangentNormalOfEllipse
in interface ReadonlyVec2D
eO
- ellipse origin/centreeR
- ellipse radii
public final Vec3D to3DXY()
ReadonlyVec2D
to3DXY
in interface ReadonlyVec2D
public final Vec3D to3DXZ()
ReadonlyVec2D
to3DXZ
in interface ReadonlyVec2D
public final Vec3D to3DYZ()
ReadonlyVec2D
to3DYZ
in interface ReadonlyVec2D
public float[] toArray()
toArray
in interface ReadonlyVec2D
public final Vec2D toCartesian()
ReadonlyVec2D
toCartesian
in interface ReadonlyVec2D
public final Vec2D toPolar()
ReadonlyVec2D
toPolar
in interface ReadonlyVec2D
public java.lang.String toString()
toString
in class java.lang.Object
public final float x()
x
in interface ReadonlyVec2D
public final float y()
y
in interface ReadonlyVec2D
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |