Chipmunk's 2D vector type.
Constructors
angle(a : Number) : self
Returns the unit length vector for the given angle (in radians).
Sourcelerp(v1 : Vect, v2 : Vect, t : Number) : Vect
Linearly interpolate between v1 and v2.
Sourcelerpconst(v1 : Vect, v2 : Vect, d : Number) : Vect
Linearly interpolate between v1 towards v2 by distance d.
Sourcenew(x : Number, y : Number)
Sourceslerp(v1 : Vect, v2 : Vect, t : Number) : Vect
Spherical linearly interpolate between v1 and v2.
Sourceslerpconst(v1 : Vect, v2 : Vect, a : Number) : Vect
Spherical linearly interpolate between v1 towards v2 by no more than angle a radians
SourceInstance methods
==(v2 : Vect) : Bool
Check if two vectors are equal.
(Be careful when comparing floating point numbers!)
Sourceclamp(len : Number) : Vect
Clamp the vector to length len.
Sourceclosest_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.
Sourcecross(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.
Sourcedist(v2 : Vect) : Float64
Returns the distance between this vector and v2.
Sourcedistsq(v2 : Vect) : Float64
Returns the squared distance between this vector and v2.
Faster than dist when you only need to compare distances.
Sourcedot(v2 : Vect) : Float64
Sourcelength
Returns the length of the vector.
Sourcelengthsq
Returns the squared length of the vector.
Faster than length when you only need to compare lengths.
Sourcenear?(v2 : Vect, dist : Number) : Bool
Returns true if the distance between this vector and v2 is less than dist.
Sourcenormalize
Returns a normalized copy of the vector (unit vector).
Sourceperp
Returns a perpendicular vector. (90 degree rotation)
Sourceproject(v2 : Vect) : Vect
Returns the vector projection of the vector onto v2.
Sourcerotate(v2 : Vect) : Vect
Uses complex number multiplication to rotate the vector by v2.
Scaling will occur if the vector is not a unit vector.
Sourcerperp
Returns a perpendicular vector. (-90 degree rotation)
Sourceto_angle
Returns the angular direction the vector is pointing in (in radians).
Sourceunrotate(v2 : Vect) : Vect
Source