|
||||||||||
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 Vec2D |
MAX_VALUE
Defines vector with both coords set to Float.MAX_VALUE. |
static Vec2D |
MIN_VALUE
Defines vector with both coords set to Float.MIN_VALUE. |
float |
x
X coordinate |
static Vec2D |
X_AXIS
Defines positive X axis |
float |
y
Y coordinate |
static Vec2D |
Y_AXIS
Defines positive Y axis |
static Vec2D |
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(Vec2D 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(Vec2D v)
Add vector v and returns result as new vector. |
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(Vec2D v)
Computes the angle between this vector and vector V. |
float |
angleBetween(Vec2D v,
boolean forceNormalize)
Computes the angle between this vector and vector V |
Vec2D |
clear()
Sets all vector components to 0. |
Vec2D |
closestPointOnLine(Vec2D a,
Vec2D b)
Computes the closest point on the given line segment. |
Vec2D |
closestPointOnTriangle(Vec2D a,
Vec2D b,
Vec2D c)
Finds and returns the closest point on any of the edges of the given triangle. |
int |
compareTo(Vec2D 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(Vec2D v)
Calculates the cross-product with the given vector. |
float |
distanceTo(Vec2D v)
Calculates distance to another vector |
float |
distanceToSquared(Vec2D v)
Calculates the squared distance to another vector |
float |
dot(Vec2D v)
Computes the scalar product (dot product) with the given vector. |
boolean |
equals(java.lang.Object obj)
|
boolean |
equalsWithTolerance(Vec2D 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(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 |
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(Vec2D v,
float f)
Interpolates the vector towards the given target vector, using linear interpolation |
Vec2D |
interpolateTo(Vec2D v,
float f,
InterpolateStrategy s)
Interpolates the vector towards the given target vector, using the given InterpolateStrategy |
Vec2D |
interpolateToSelf(Vec2D v,
float f)
Interpolates the vector towards the given target vector, using linear interpolation |
Vec2D |
interpolateToSelf(Vec2D v,
float f,
InterpolateStrategy s)
Interpolates the vector towards the given target vector, using the given InterpolateStrategy |
float |
intersectRayCircle(Vec2D rayDir,
Vec2D circleOrigin,
float circleRadius)
Calculates the distance of the vector to the given sphere in the specified direction. |
Vec2D |
invert()
Scales vector uniformly by factor -1 ( v = -v ), overrides coordinates with result |
boolean |
isInCircle(Vec2D 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 |
isZeroVector()
Checks if vector has a magnitude of 0 |
Vec2D |
jitter(float j)
|
Vec2D |
jitter(float jx,
float jy)
Adds random jitter to the vector. |
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()
|
boolean |
pointInPolygon(java.util.ArrayList<Vec2D> vertices)
Checks if the point is within the convex polygon defined by the points in the given list |
static Vec2D |
randomVector()
Static factory method. |
static Vec2D |
randomVector(java.util.Random rnd)
Static factory method. |
Vec2D |
reciprocal()
|
Vec2D |
rotate(float theta)
Rotates the vector by the given angle around the Z 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(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(Vec2D v)
Overrides coordinates with the ones of the given vector |
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(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()
|
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Vec2D X_AXIS
public static final Vec2D Y_AXIS
public static final Vec2D ZERO
public static final Vec2D MIN_VALUE
public static final Vec2D MAX_VALUE
public float x
public float y
Constructor Detail |
---|
public Vec2D()
public Vec2D(float x, float y)
x
- y
- public Vec2D(Vec2D 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()
public static final Vec2D randomVector(java.util.Random rnd)
public final Vec2D abs()
public final Vec2D add(float a, float b)
a
- X coordinateb
- Y coordinate
public final Vec2D add(Vec2D v)
v
- vector to add
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(Vec2D v)
angleBetween(Vec2D, boolean)
v
- vector
public final float angleBetween(Vec2D v, boolean forceNormalize)
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 final Vec2D clear()
public Vec2D closestPointOnLine(Vec2D a, Vec2D b)
a
- start point of line segmentb
- end point of line segment
public Vec2D closestPointOnTriangle(Vec2D a, Vec2D b, Vec2D c)
a
- triangle vertexb
- triangle vertexc
- triangle vertex
public int compareTo(Vec2D v)
compareTo
in interface java.lang.Comparable<Vec2D>
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()
public float cross(Vec2D v)
v
- vector
public final float distanceTo(Vec2D v)
v
- non-null vector
public final float distanceToSquared(Vec2D v)
v
- non-null vector
magSquared()
public final float dot(Vec2D v)
v
-
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public boolean equalsWithTolerance(Vec2D v, float tolerance)
v
- the vtolerance
- the tolerance
public final Vec2D floor()
public final Vec2D frac()
public final Vec2D getAbs()
public float getComponent(Vec2D.Axis id)
public final Vec2D getConstrained(Rect r)
r
-
public final Vec2D getFloored()
public final Vec2D getFrac()
public final Vec2D getInverted()
public final Vec2D getLimited(float lim)
lim
- new maximum magnitude
public final Vec2D getNormalized()
public Vec2D getNormalizedTo(float len)
len
- new desired length
public final Vec2D getPerpendicular()
public final Vec2D getReciprocal()
public final Vec2D getRotated(float theta)
theta
-
public Vec2D getSignum()
public int hashCode()
hashCode
in class java.lang.Object
public final float heading()
public final Vec2D interpolateTo(Vec2D v, float f)
v
- target vectorf
- interpolation factor (should be in the range 0..1)
public Vec2D interpolateTo(Vec2D v, float f, InterpolateStrategy s)
InterpolateStrategy
v
- target vectorf
- interpolation factor (should be in the range 0..1)s
- InterpolateStrategy instance
public final Vec2D interpolateToSelf(Vec2D v, float f)
v
- target vectorf
- interpolation factor (should be in the range 0..1)
public Vec2D interpolateToSelf(Vec2D v, float f, InterpolateStrategy s)
InterpolateStrategy
v
- target vectorf
- interpolation factor (should be in the range 0..1)s
- InterpolateStrategy instance
public float intersectRayCircle(Vec2D rayDir, Vec2D circleOrigin, float circleRadius)
rayDir
- intersection directioncircleOrigin
- circleRadius
-
public final Vec2D invert()
public boolean isInCircle(Vec2D sO, float sR)
sO
- circle origin/centresR
- circle radius
public boolean isInRectangle(Rect r)
r
- bounding rectangle
public boolean isInTriangle(Vec2D a, Vec2D b, Vec2D c)
public final boolean isZeroVector()
public final Vec2D jitter(float j)
public final Vec2D jitter(float jx, float jy)
jx
- maximum x jitterjy
- maximum y jitter
public final Vec2D jitter(Vec2D jv)
public final Vec2D limit(float lim)
lim
- new maximum magnitude
public final float magnitude()
public final float magSquared()
public final Vec2D max(Vec2D v)
v
-
public final Vec2D maxSelf(Vec2D v)
v
-
public final Vec2D min(Vec2D v)
v
- comparing vector
public final Vec2D minSelf(Vec2D v)
v
-
public final Vec2D normalize()
public Vec2D normalizeTo(float len)
len
- desired length
public final Vec2D perpendicular()
public boolean pointInPolygon(java.util.ArrayList<Vec2D> vertices)
vertices
-
public final Vec2D reciprocal()
public final Vec2D rotate(float theta)
theta
-
public final Vec2D scale(float s)
s
- scale factor
public final Vec2D scale(float a, float b)
a
- scale factor for X coordinateb
- scale factor for Y coordinate
public final Vec2D scale(Vec2D s)
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(Vec2D v)
v
- vector to be copied
public Vec2D setComponent(Vec2D.Axis id, float val)
public Vec2D signum()
public final Vec2D sub(float a, float b)
a
- X coordinateb
- Y coordinate
public final Vec2D sub(Vec2D v)
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 Vec2D tangentNormalOfEllipse(Vec2D eO, Vec2D eR)
eO
- ellipse origin/centreeR
- ellipse radii
public Vec3D to3DXY()
public Vec3D to3DXZ()
public Vec3D to3DYZ()
public float[] toArray()
public Vec2D toCartesian()
public Vec2D toPolar()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |