Fork me on GitHub
View source

package haxepunk.math

class Vector2

Constructor

View source

new (x : Float = 0, y : Float = 0) : Void

Variables

length : Float

The length of this vector

x : Float

y : Float

Functions

View source

add (other : Vector2) : Void

View source

copyFrom (other : Vector2) : Void

Copies the values from one vector into this one


Parameters:
other   

The vector to copy from

View source

distance (other : Vector2) : Float

Returns the distance between this and another point


Parameters:
other   

The other point to use for distance calculation


Returns:

The distance between the two points

View source

dot (other : Vector2) : Float

Can be used to determine if an angle between two vectors is acute or obtuse.

View source

inverse () : Void

Invert (negate) the vector contents

View source

normalize (size : Float = 1) : Void

Normalize the vector to a set length


Parameters:
size   

The length of the resulting vector. Default: unit length (1)

View source

perpendicular () : Void

Convert this vector to it's perpendicular counterpart

View source

rotate (angle : Float) : Void

Rotate the vector around an angle


Parameters:
angle   

The angle, in radians to rotate around (clockwise)

View source

scale (scalar : Float) : Void

Scale the vector by a single value

View source

setTo (x : Float, y : Float) : Void

Set the internal x, y values

View source

subtract (other : Vector2) : Void

View source

zcross (other : Vector2) : Float

This is the same as a 3D cross product but only returns the z value because x and y are 0. Can be used to determine if and angle between two vectors is greater than 180 degrees.