struct

CP::Vect

Inherits Struct / Value / Object

Chipmunk's 2D vector type.

Constructors

angle(a : Number) : self

Returns the unit length vector for the given angle (in radians).

Source
lerp(v1 : Vect, v2 : Vect, t : Number) : Vect

Linearly interpolate between v1 and v2.

Source
lerpconst(v1 : Vect, v2 : Vect, d : Number) : Vect

Linearly interpolate between v1 towards v2 by distance d.

Source
new(x : Number, y : Number)
Source
slerp(v1 : Vect, v2 : Vect, t : Number) : Vect

Spherical linearly interpolate between v1 and v2.

Source
slerpconst(v1 : Vect, v2 : Vect, a : Number) : Vect

Spherical linearly interpolate between v1 towards v2 by no more than angle a radians

Source

Instance methods

*(s : Number) : Vect

Scalar multiplication.

Source
+(v2 : Vect) : Vect

Add two vectors

Source
-(v2 : Vect) : Vect

Subtract two vectors.

Source
-

Negate a vector.

Source
==(v2 : Vect) : Bool

Check if two vectors are equal.

(Be careful when comparing floating point numbers!)

Source
clamp(len : Number) : Vect

Clamp the vector to length len.

Source
closest_point_on_segment(a : Vect, b : Vect) : Vect

Returns the closest point on the line segment a b, to the point stored in this Vect.

Source
cross(v2 : Vect) : Float64

2D vector cross product analog.

The cross product of 2D vectors results in a 3D vector with only a z component. This function returns the magnitude of the z value.

Source
dist(v2 : Vect) : Float64

Returns the distance between this vector and v2.

Source
distsq(v2 : Vect) : Float64

Returns the squared distance between this vector and v2.

Faster than dist when you only need to compare distances.

Source
dot(v2 : Vect) : Float64

Vector dot product.

Source
length

Returns the length of the vector.

Source
lengthsq

Returns the squared length of the vector.

Faster than length when you only need to compare lengths.

Source
near?(v2 : Vect, dist : Number) : Bool

Returns true if the distance between this vector and v2 is less than dist.

Source
normalize

Returns a normalized copy of the vector (unit vector).

Source
perp

Returns a perpendicular vector. (90 degree rotation)

Source
project(v2 : Vect) : Vect

Returns the vector projection of the vector onto v2.

Source
rotate(v2 : Vect) : Vect

Uses complex number multiplication to rotate the vector by v2.

Scaling will occur if the vector is not a unit vector.

Source
rperp

Returns a perpendicular vector. (-90 degree rotation)

Source
to_angle

Returns the angular direction the vector is pointing in (in radians).

Source
unrotate(v2 : Vect) : Vect

Inverse of rotate.

Source
x=(x : Float64)
Source
y=(y : Float64)
Source