Vector math
module CP
#
Extended modules
CP
Methods#
#lerp(f1 : Number, f2 : Number, t : Number) : Number
#
Linearly interpolate (or extrapolate) between f1 and f2 by t percent.
#lerpconst(f1 : Number, f2 : Number, d : Number) : Number
#
Linearly interpolate from f1 to f2 by no more than d.
struct CP::Vect
inherits Struct
#
Chipmunk's 2D vector type.
Constructors#
.angle(a : Number) : self
#
Returns the unit length vector for the given angle (in radians).
.lerpconst(v1 : Vect, v2 : Vect, d : Number) : Vect
#
Linearly interpolate between v1 towards v2 by distance d.
.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
Methods#
#==(v2 : Vect) : Bool
#
Check if two vectors are equal.
(Be careful when comparing floating point numbers!)
#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
.
#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.
#distsq(v2 : Vect) : Float64
#
Returns the squared distance between this vector and v2.
Faster than dist
when you only need to compare distances.
#lengthsq : Float64
#
Returns the squared length of the vector.
Faster than length
when you only need to compare lengths.
#near?(v2 : Vect, dist : Number) : Bool
#
Returns true if the distance between this vector and v2 is less than dist.
#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.
#to_angle : Float64
#
Returns the angular direction the vector is pointing in (in radians).
struct CP::BB
inherits Struct
#
Chipmunk's axis-aligned 2D bounding box type. (left, bottom, right, top)
Constructors#
.new_for_circle(p : Vect, r : Number) : self
#
Constructs a BB
fitting a circle with the position p and radius r.
.new_for_extents(c : Vect, hw : Number, hh : Number) : self
#
Constructs a BB
centered on a point with the given extents (half sizes).
Methods#
#contains?(other : BB) : Bool
#
Returns true if the other BB
lies completely within this one.
#expand(point : Vect) : BB
#
Returns the minimal bounding box that contains both this BB
and the point.
#intersects_segment?(a : Vect, b : Vect) : Bool
#
Return true if the bounding box intersects the line segment with ends a and b.
#segment_query(a : Vect, b : Vect) : Float64
#
Returns the fraction along the segment query the BB
is hit.
Returns INFINITY if it doesn't hit.
struct CP::Mat2x2
inherits Struct
#
struct CP::Transform
inherits Struct
#
Column major 2x3 affine transform.
Constants#
IDENTITY = new
#
Identity transform matrix.
Constructors#
.new(a : Number = 1, b : Number = 0, c : Number = 0, d : Number = 1, tx : Number = 0, ty : Number = 0)
#
Construct a new transform matrix.
- (a, b) is the x basis vector.
- (c, d) is the y basis vector.
- (tx, ty) is the translation.
.new_transpose(a : Number, c : Number, tx : Number, b : Number, d : Number, ty : Number) : self
#
Construct a new transform matrix in transposed order.
.rigid(translate : Vect, radians : Number) : Transform
#
Create a rigid transformation matrix. (translation + rotation)