struct CP::Vect
- CP::Vect
- Struct
- Value
- Object
Overview
Chipmunk's 2D vector type.
Defined in:
chipmunk/vector.crConstructors
-
.angle(a : Number) : self
Returns the unit length vector for the given angle (in radians).
-
.lerp(v1 : Vect, v2 : Vect, t : Number) : Vect
Linearly interpolate between v1 and v2.
-
.lerpconst(v1 : Vect, v2 : Vect, d : Number) : Vect
Linearly interpolate between v1 towards v2 by distance d.
- .new(x : Number, y : Number)
-
.slerp(v1 : Vect, v2 : Vect, t : Number) : Vect
Spherical linearly interpolate between v1 and v2.
-
.slerpconst(v1 : Vect, v2 : Vect, a : Number) : Vect
Spherical linearly interpolate between v1 towards v2 by no more than angle a radians
Instance Method Summary
-
#*(s : Number) : Vect
Scalar multiplication.
-
#+(v2 : Vect) : Vect
Add two vectors
-
#-(v2 : Vect) : Vect
Subtract two vectors.
-
#- : Vect
Negate a vector.
-
#==(v2 : Vect) : Bool
Check if two vectors are equal.
-
#clamp(len : Number) : Vect
Clamp the vector to length len.
-
#closest_point_on_segment(a : Vect, b : Vect) : Vect
Returns the closest point on the line segment
a
b
, to the point stored in thisVect
. -
#cross(v2 : Vect) : Float64
2D vector cross product analog.
-
#dist(v2 : Vect) : Float64
Returns the distance between this vector and v2.
-
#distsq(v2 : Vect) : Float64
Returns the squared distance between this vector and v2.
-
#dot(v2 : Vect) : Float64
Vector dot product.
-
#length : Float64
Returns the length of the vector.
-
#lengthsq : Float64
Returns the squared length of the vector.
-
#near?(v2 : Vect, dist : Number) : Bool
Returns true if the distance between this vector and v2 is less than dist.
-
#normalize : Vect
Returns a normalized copy of the vector (unit vector).
-
#perp : Vect
Returns a perpendicular vector.
-
#project(v2 : Vect) : Vect
Returns the vector projection of the vector onto v2.
-
#rotate(v2 : Vect) : Vect
Uses complex number multiplication to rotate the vector by v2.
-
#rperp : Vect
Returns a perpendicular vector.
-
#to_angle : Float64
Returns the angular direction the vector is pointing in (in radians).
-
#unrotate(v2 : Vect) : Vect
Inverse of
#rotate
. - #x : Float64
- #x=(x : Float64)
- #y : Float64
- #y=(y : Float64)
Constructor Detail
Returns the unit length vector for the given angle (in radians).
Linearly interpolate between v1 and v2.
Linearly interpolate between v1 towards v2 by distance d.
Spherical linearly interpolate between v1 and v2.
Spherical linearly interpolate between v1 towards v2 by no more than angle a radians
Instance Method Detail
Check if two vectors are equal.
(Be careful when comparing floating point numbers!)
Returns the closest point on the line segment a
b
, to the point stored in this Vect
.
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.
Returns the squared distance between this vector and v2.
Faster than #dist
when you only need to compare distances.
Returns the squared length of the vector.
Faster than #length
when you only need to compare lengths.
Returns true if the distance between this vector and v2 is less than dist.
Uses complex number multiplication to rotate the vector by v2.
Scaling will occur if the vector is not a unit vector.