struct CP::Vect

Overview

Chipmunk's 2D vector type.

Defined in:

chipmunk/vector.cr

Constructors

Instance Method Summary

Constructor Detail

def self.angle(a : Number) : self #

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


[View source]
def self.lerp(v1 : Vect, v2 : Vect, t : Number) : Vect #

Linearly interpolate between v1 and v2.


[View source]
def self.lerpconst(v1 : Vect, v2 : Vect, d : Number) : Vect #

Linearly interpolate between v1 towards v2 by distance d.


[View source]
def self.new(x : Number, y : Number) #

[View source]
def self.slerp(v1 : Vect, v2 : Vect, t : Number) : Vect #

Spherical linearly interpolate between v1 and v2.


[View source]
def self.slerpconst(v1 : Vect, v2 : Vect, a : Number) : Vect #

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


[View source]

Instance Method Detail

def *(s : Number) : Vect #

Scalar multiplication.


[View source]
def +(v2 : Vect) : Vect #

Add two vectors


[View source]
def -(v2 : Vect) : Vect #

Subtract two vectors.


[View source]
def - : Vect #

Negate a vector.


[View source]
def ==(v2 : Vect) : Bool #

Check if two vectors are equal.

(Be careful when comparing floating point numbers!)


[View source]
def clamp(len : Number) : Vect #

Clamp the vector to length len.


[View source]
def 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.


[View source]
def 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.


[View source]
def dist(v2 : Vect) : Float64 #

Returns the distance between this vector and v2.


[View source]
def distsq(v2 : Vect) : Float64 #

Returns the squared distance between this vector and v2.

Faster than #dist when you only need to compare distances.


[View source]
def dot(v2 : Vect) : Float64 #

Vector dot product.


[View source]
def length : Float64 #

Returns the length of the vector.


[View source]
def lengthsq : Float64 #

Returns the squared length of the vector.

Faster than #length when you only need to compare lengths.


[View source]
def near?(v2 : Vect, dist : Number) : Bool #

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


[View source]
def normalize : Vect #

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


[View source]
def perp : Vect #

Returns a perpendicular vector. (90 degree rotation)


[View source]
def project(v2 : Vect) : Vect #

Returns the vector projection of the vector onto v2.


[View source]
def 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.


[View source]
def rperp : Vect #

Returns a perpendicular vector. (-90 degree rotation)


[View source]
def to_angle : Float64 #

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


[View source]
def unrotate(v2 : Vect) : Vect #

Inverse of #rotate.


[View source]
def x : Float64 #

[View source]
def x=(x : Float64) #

[View source]
def y : Float64 #

[View source]
def y=(y : Float64) #

[View source]