toxi.geom
Interface ReadonlyVec2D

All Known Implementing Classes:
Circle, Ellipse, Ray2D, Vec2D

public interface ReadonlyVec2D

Readonly, immutable interface wrapper for Vec2D instances. Used throughout the library for safety purposes.


Method Summary
 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.
 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 p)
          Computes the perpendicular bisector of two points.
 int compareTo(ReadonlyVec2D v)
          Compares the length of the vector with another one.
 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 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.
 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
 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 tolerance)
          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).
 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.
 Vec2D min(Vec2D v)
          Constructs a new vector consisting of the smallest components of both vectors.
 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 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 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.
 float x()
           
 float y()
           
 

Method Detail

add

Vec2D add(float a,
          float b)
Adds vector {a,b,c} and returns result as new vector.

Parameters:
a - X coordinate
b - Y coordinate
Returns:
result as new vector

add

Vec2D add(ReadonlyVec2D v)
Add vector v and returns result as new vector.

Parameters:
v - vector to add
Returns:
result as new vector

angleBetween

float angleBetween(ReadonlyVec2D v)
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 implementation angleBetween(ReadonlyVec2D, boolean)

Parameters:
v - vector
Returns:
angle in radians, or NaN if vectors are parallel

angleBetween

float angleBetween(ReadonlyVec2D v,
                   boolean forceNormalize)
Computes the angle between this vector and vector V

Parameters:
v - vector
forceNormalize - 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

Vec3D bisect(Vec2D p)
Computes the perpendicular bisector of two points.

Parameters:
p - other point
Returns:
bisector coefficients as Vec3D

compareTo

int compareTo(ReadonlyVec2D v)
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

float cross(ReadonlyVec2D v)
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:
Stackoverflow entry

distanceTo

float distanceTo(ReadonlyVec2D v)
Calculates distance to another vector

Parameters:
v - non-null vector
Returns:
distance or Float.NaN if v=null

distanceToSquared

float distanceToSquared(ReadonlyVec2D v)
Calculates the squared distance to another vector

Parameters:
v - non-null vector
Returns:
distance or NaN if v=null
See Also:
magSquared()

dot

float dot(ReadonlyVec2D v)
Computes the scalar product (dot product) with the given vector.

Parameters:
v -
Returns:
dot product
See Also:
Wikipedia entry< /a>

equals

boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

equalsWithTolerance

boolean equalsWithTolerance(ReadonlyVec2D v,
                            float tolerance)
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 v
tolerance - the tolerance
Returns:
true, if equal

getAbs

Vec2D getAbs()

getComponent

float getComponent(Vec2D.Axis id)

getComponent

float getComponent(int id)

getConstrained

Vec2D getConstrained(Rect r)
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

Vec2D getLimited(float lim)
Creates a copy of the vector with its magnitude limited to the length given

Parameters:
lim - new maximum magnitude
Returns:
result as new vector

getNormalized

Vec2D getNormalized()
Produces the normalized version as a new vector

Returns:
new vector

getNormalizedTo

Vec2D getNormalizedTo(float len)
Produces a new vector normalized to the given length.

Parameters:
len - new desired length
Returns:
new vector

getPerpendicular

Vec2D getPerpendicular()

getReciprocal

Vec2D getReciprocal()

getReflected

Vec2D getReflected(ReadonlyVec2D normal)

getRotated

Vec2D getRotated(float theta)
Creates a new vector rotated by the given angle around the Z axis.

Parameters:
theta -
Returns:
rotated 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

Vec2D interpolateTo(ReadonlyVec2D v,
                    float f)
Interpolates the vector towards the given target vector, using linear interpolation

Parameters:
v - target vector
f - interpolation factor (should be in the range 0..1)
Returns:
result as new vector

interpolateTo

Vec2D interpolateTo(ReadonlyVec2D v,
                    float f,
                    InterpolateStrategy s)
Interpolates the vector towards the given target vector, using the given InterpolateStrategy

Parameters:
v - target vector
f - interpolation factor (should be in the range 0..1)
s - InterpolateStrategy instance
Returns:
result as new vector

isInCircle

boolean isInCircle(ReadonlyVec2D sO,
                   float sR)
Checks if the point is inside the given sphere.

Parameters:
sO - circle origin/centre
sR - circle radius
Returns:
true, if point is in sphere

isInRectangle

boolean isInRectangle(Rect r)
Checks if the point is inside the given rectangle.

Parameters:
r - bounding rectangle
Returns:
true, if point is inside

isInTriangle

boolean isInTriangle(Vec2D a,
                     Vec2D b,
                     Vec2D c)
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 is MathUtils.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

Vec2D max(Vec2D v)
Constructs a new vector consisting of the largest components of both vectors.

Parameters:
v -
Returns:
result as new vector

min

Vec2D min(Vec2D v)
Constructs a new vector consisting of the smallest components of both vectors.

Parameters:
v - comparing vector
Returns:
result as new vector

scale

Vec2D scale(float s)
Scales vector uniformly and returns result as new vector.

Parameters:
s - scale factor
Returns:
new vector

scale

Vec2D scale(float a,
            float b)
Scales vector non-uniformly and returns result as new vector.

Parameters:
a - scale factor for X coordinate
b - scale factor for Y coordinate
Returns:
new vector

scale

Vec2D scale(ReadonlyVec2D s)

scale

Vec2D scale(Vec2D s)
Scales vector non-uniformly by vector v and returns result as new vector

Parameters:
s - scale vector
Returns:
new vector

sub

Vec2D sub(float a,
          float b)
Subtracts vector {a,b,c} and returns result as new vector.

Parameters:
a - X coordinate
b - Y coordinate
Returns:
result as new vector

sub

Vec2D sub(ReadonlyVec2D v)

sub

Vec2D sub(Vec2D v)
Subtracts vector v and returns result as new vector.

Parameters:
v - vector to be subtracted
Returns:
result as new vector

tangentNormalOfEllipse

Vec2D tangentNormalOfEllipse(Vec2D eO,
                             Vec2D eR)
Calculates the normal vector on the given ellipse in the direction of the current point.

Parameters:
eO - ellipse origin/centre
eR - 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()

toCartesian

Vec2D toCartesian()
Converts the vector from polar to Cartesian space. Assumes this order: x=radius, y=theta

Returns:
itself as Cartesian vector

toPolar

Vec2D toPolar()
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:
itself as polar vector

x

float x()

y

float y()