Vector2

Category: Built-In Types

Brief Description

Vector used for 2D Math.

Member Variables

  • float height - Height of the vector (Same as Y).
  • float width - Width of the vector (Same as X).
  • float x - X component of the vector.
  • float y - Y component of the vector.

Description

2-element structure that can be used to represent positions in 2d-space, or any other pair of numeric values.

Member Function Description

Constructs a new Vector2 from the given x and y.

Returns a new vector with all components in absolute values (i.e. positive).

Returns the result of atan2 when called with the Vector’s x and y as parameters (Math::atan2(x,y)).

Be aware that it therefore returns an angle oriented clockwise with regard to the (0, 1) unit vector, and not an angle oriented counter-clockwise with regard to the (1, 0) unit vector (which would be the typical trigonometric representation of the angle when calling Math::atan2(y,x)).

Returns the angle in radians between the two vectors.

Returns the angle in radians between the line connecting the two points and the x coordinate.

Returns the vector with a maximum length.

Cubicly interpolates between this Vector and “b”, using “pre_a” and “post_b” as handles, and returning the result at position “t”.

Returns the squared distance to vector “b”. Prefer this function over “distance_to” if you need to sort vectors or need the squared distance for some formula.

Returns the distance to vector “b”.

Returns the dot product with vector “b”.

Remove the fractional part of x and y.

Remove the fractional part of x and y.

Returns the ratio of X to Y.

Returns the length of the vector.

  • float length_squared ( )

Returns the squared length of the vector. Prefer this function over “length” if you need to sort vectors or need the squared length for some formula.

Returns the result of the linear interpolation between this vector and “b”, by amount “t”.

Returns a normalized vector to unit length.

Like “slide”, but reflects the Vector instead of continuing along the wall.

Rotates the vector by “phi” radians.

Slides the vector by the other vector.

Snaps the vector to a grid with the given size.

Returns a perpendicular vector.