toxi.geom
Class Vec2D

java.lang.Object
  extended by toxi.geom.Vec2D
All Implemented Interfaces:
java.lang.Comparable<Vec2D>
Direct Known Subclasses:
Ellipse, Ray2D

public class Vec2D
extends java.lang.Object
implements java.lang.Comparable<Vec2D>

Comprehensive 2D vector class with additional basic intersection and collision detection features.

Author:
Karsten Schmidt

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

X_AXIS

public static final Vec2D X_AXIS
Defines positive X axis


Y_AXIS

public static final Vec2D Y_AXIS
Defines positive Y axis


ZERO

public static final Vec2D ZERO
Defines the zero vector.


MIN_VALUE

public static final Vec2D MIN_VALUE
Defines vector with both coords set to Float.MIN_VALUE. Useful for bounding box operations.


MAX_VALUE

public static final Vec2D MAX_VALUE
Defines vector with both coords set to Float.MAX_VALUE. Useful for bounding box operations.


x

public float x
X coordinate


y

public float y
Y coordinate

Constructor Detail

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(Vec2D v)
Creates a new vector with the coordinates of the given vector

Parameters:
v - vector to be copied
Method Detail

fromTheta

public static final Vec2D fromTheta(float theta)
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

public static final Vec2D max(Vec2D a,
                              Vec2D b)
Constructs a new vector consisting of the largest components of both vectors.

Parameters:
b - the b
a - the a
Returns:
result as new vector

min

public static final Vec2D min(Vec2D a,
                              Vec2D b)
Constructs a new vector consisting of the smallest components of both vectors.

Parameters:
b - comparing vector
a - the a
Returns:
result as new vector

randomVector

public static final Vec2D randomVector()
Static factory method. Creates a new random unit vector using the default Math.random() Random instance.

Returns:
a new random normalized unit vector.

randomVector

public static final Vec2D randomVector(java.util.Random rnd)
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

public final Vec2D abs()

add

public final 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

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

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

addSelf

public final Vec2D addSelf(float a,
                           float b)
Adds vector {a,b,c} and overrides coordinates with result.

Parameters:
a - X coordinate
b - Y coordinate
Returns:
itself

addSelf

public final Vec2D addSelf(Vec2D v)
Adds vector v and overrides coordinates with result.

Parameters:
v - vector to add
Returns:
itself

angleBetween

public final float angleBetween(Vec2D 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(Vec2D, boolean)

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

angleBetween

public final float angleBetween(Vec2D 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

clear

public final Vec2D clear()
Sets all vector components to 0.

Returns:
itself

closestPointOnLine

public Vec2D closestPointOnLine(Vec2D a,
                                Vec2D b)
Computes the closest point on the given line segment.

Parameters:
a - start point of line segment
b - end point of line segment
Returns:
closest point on the line segment a -> b

closestPointOnTriangle

public Vec2D closestPointOnTriangle(Vec2D a,
                                    Vec2D b,
                                    Vec2D c)
Finds and returns the closest point on any of the edges of the given triangle.

Parameters:
a - triangle vertex
b - triangle vertex
c - triangle vertex
Returns:
closest point

compareTo

public int compareTo(Vec2D v)
Compares the length of the vector with another one.

Specified by:
compareTo in interface java.lang.Comparable<Vec2D>
Parameters:
v - vector to compare with
Returns:
-1 if other vector is longer, 0 if both are equal or else +1

constrain

public final Vec2D constrain(Rect r)
Forcefully fits the vector in the given rectangle.

Parameters:
r -
Returns:
itself

constrain

public final Vec2D constrain(Vec2D min,
                             Vec2D max)
Forcefully fits the vector in the given rectangle defined by the points.

Parameters:
min -
max -
Returns:
itself

copy

public final Vec2D copy()
Returns:
a new independent instance/copy of a given vector

cross

public float cross(Vec2D 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

public final float distanceTo(Vec2D v)
Calculates distance to another vector

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

distanceToSquared

public final float distanceToSquared(Vec2D v)
Calculates the squared distance to another vector

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

dot

public final float dot(Vec2D v)
Computes the scalar product (dot product) with the given vector.

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

equals

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

equalsWithTolerance

public boolean equalsWithTolerance(Vec2D 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

floor

public final Vec2D floor()
Replaces the vector components with integer values of their current values

Returns:
itself

frac

public final Vec2D frac()
Replaces the vector components with the fractional part of their current values

Returns:
itself

getAbs

public final Vec2D getAbs()

getComponent

public float getComponent(Vec2D.Axis id)

getConstrained

public final Vec2D getConstrained(Rect r)
Creates a copy of the vector which forcefully fits in the given rectangle.

Parameters:
r -
Returns:
fitted vector

getFloored

public final Vec2D getFloored()
Creates a new vector whose components are the integer value of their current values

Returns:
result as new vector

getFrac

public final Vec2D getFrac()
Creates a new vector whose components are the fractional part of their current values

Returns:
result as new vector

getInverted

public final Vec2D getInverted()
Scales vector uniformly by factor -1 ( v = -v )

Returns:
result as new vector

getLimited

public final 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

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

Returns:
new vector

getNormalizedTo

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

Parameters:
len - new desired length
Returns:
new vector

getPerpendicular

public final Vec2D getPerpendicular()

getReciprocal

public final Vec2D getReciprocal()

getRotated

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

Parameters:
theta -
Returns:
rotated vector

getSignum

public 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

hashCode

public int hashCode()
Returns a unique code for this vector object based on it's values. If two vectors are logically equivalent, they will return the same hash code value.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value of this vector.

heading

public final 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

public final Vec2D interpolateTo(Vec2D 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

public Vec2D interpolateTo(Vec2D 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

interpolateToSelf

public final Vec2D interpolateToSelf(Vec2D 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:
itself, result overrides current vector

interpolateToSelf

public Vec2D interpolateToSelf(Vec2D 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:
itself, result overrides current vector

intersectRayCircle

public float intersectRayCircle(Vec2D rayDir,
                                Vec2D circleOrigin,
                                float circleRadius)
Calculates the distance of the vector to the given sphere in the specified direction. A sphere is defined by a 3D point and a radius. Normalized directional vectors expected.

Parameters:
rayDir - intersection direction
circleOrigin -
circleRadius -
Returns:
distance to sphere in world units, -1 if no intersection.

invert

public final Vec2D invert()
Scales vector uniformly by factor -1 ( v = -v ), overrides coordinates with result

Returns:
itself

isInCircle

public boolean isInCircle(Vec2D 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

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

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

isInTriangle

public 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.

isZeroVector

public final boolean isZeroVector()
Checks if vector has a magnitude of 0

Returns:
true, if vector = {0,0,0}

jitter

public final Vec2D jitter(float j)

jitter

public final Vec2D jitter(float jx,
                          float jy)
Adds random jitter to the vector.

Parameters:
jx - maximum x jitter
jy - maximum y jitter
Returns:
itself

jitter

public final Vec2D jitter(Vec2D jv)

limit

public final Vec2D limit(float lim)
Limits the vector's magnitude to the length given

Parameters:
lim - new maximum magnitude
Returns:
itself

magnitude

public final float magnitude()
Calculates the magnitude/eucledian length of the vector

Returns:
vector length

magSquared

public final 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

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

Parameters:
v -
Returns:
result as new vector

maxSelf

public final Vec2D maxSelf(Vec2D v)
Adjusts the vector components to the maximum values of both vectors

Parameters:
v -
Returns:
itself

min

public final 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

minSelf

public final Vec2D minSelf(Vec2D v)
Adjusts the vector components to the minimum values of both vectors

Parameters:
v -
Returns:
itself

normalize

public final Vec2D normalize()
Normalizes the vector so that its magnitude = 1

Returns:
itself

normalizeTo

public Vec2D normalizeTo(float len)
Normalizes the vector to the given length.

Parameters:
len - desired length
Returns:
itself

perpendicular

public final Vec2D perpendicular()

pointInPolygon

public boolean pointInPolygon(java.util.ArrayList<Vec2D> vertices)
Checks if the point is within the convex polygon defined by the points in the given list

Parameters:
vertices -
Returns:
true, if inside polygon

reciprocal

public final Vec2D reciprocal()

rotate

public final Vec2D rotate(float theta)
Rotates the vector by the given angle around the Z axis.

Parameters:
theta -
Returns:
itself

scale

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

Parameters:
s - scale factor
Returns:
new vector

scale

public final 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

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

Parameters:
s - scale vector
Returns:
new vector

scaleSelf

public final Vec2D scaleSelf(float s)
Scales vector uniformly and overrides coordinates with result

Parameters:
s - scale factor
Returns:
itself

scaleSelf

public final Vec2D scaleSelf(float a,
                             float b)
Scales vector non-uniformly by vector {a,b,c} and overrides coordinates with result

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

scaleSelf

public final Vec2D scaleSelf(Vec2D s)
Scales vector non-uniformly by vector v and overrides coordinates with result

Parameters:
s - scale vector
Returns:
itself

set

public final Vec2D set(float x,
                       float y)
Overrides coordinates with the given values

Parameters:
x -
y -
Returns:
itself

set

public final Vec2D set(Vec2D v)
Overrides coordinates with the ones of the given vector

Parameters:
v - vector to be copied
Returns:
itself

setComponent

public Vec2D setComponent(Vec2D.Axis id,
                          float val)

signum

public Vec2D 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

sub

public final 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

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

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

subSelf

public final Vec2D subSelf(float a,
                           float b)
Subtracts vector {a,b,c} and overrides coordinates with result.

Parameters:
a - X coordinate
b - Y coordinate
Returns:
itself

subSelf

public final Vec2D subSelf(Vec2D v)
Subtracts vector v and overrides coordinates with result.

Parameters:
v - vector to be subtracted
Returns:
itself

tangentNormalOfEllipse

public 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

public Vec3D to3DXY()
Creates a 3D version of this vector in the XY plane.

Returns:
3D vector

to3DXZ

public Vec3D to3DXZ()
Creates a 3D version of this vector in the XZ plane. (The 2D Y coordinate interpreted as Z)

Returns:
3D vector

to3DYZ

public 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

public float[] toArray()

toCartesian

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

Returns:
itself as Cartesian vector

toPolar

public 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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object