Graphmath.Vec2.Tuple

This is the 2D mathematics library for graphmath.

This submodule handles vectors stored as a tuple.

Summary

add(a, b)

add( a, b) adds a vec2 (a) to a vec2 (b)

create()

create() creates a zero vec2

create(vec)

create(vec) creates a vec2 of value (x,y) out of a list of 2 or more numbers

create(x, y)

create(x,y) creates a vec2 of value (x,y)

dot(a, b)

dot( a, b) finds the dot (inner) product of a vec2 (a) with another vec2 (b)

length(a)

length(a) finds the length (L2 norm) of a vec2 (a)

length_manhattan(a)

length_manhattan(a) finds the Manhattan (L1 norm) length of a vec2 (a)

length_squared(a)

length_squared(a) finds the square of the length of a vec2 (a)

lerp(a, b, t)

lerp(a,b,t) is used to linearly interpolate between two given vectors a and b along an interpolant t

multiply(a, b)

multiply( a, b) mulitplies element-wise a vec2 (a) by a vec2 (b)

near(a, b, distance)

near(a,b, distance) checks whether two vectors are within a length of each other

normalize(a)

normalize(a) finds the unit vector with the same direction as a vec2 (a)

perp_prod(a, b)

perp_prod( a, b) finds the perpindicular product of a vec2 (a) with another vec2 (b)

project(a, b)

project(a,b) projects one vector onto another, and returns the resulting image

rotate(a, theta)

rotate(a,theta) rotates a vec2 (a) CCW about the +Z axis theta radians

scale(a, scale)

scale( a, scale) uniformly scales a vec2 (a) by an amount (x)

subtract(a, b)

subtract(a, b) subtracts a vec2 (b) from a vec2 (a)

Functions

add(a, b)

Specs:

  • add({float, float}, {float, float}) :: {float, float}

add( a, b) adds a vec2 (a) to a vec2 (b).

It returns a tuple of the form { ax + bx, ay + by }.

create()

Specs:

  • create :: {float, float}

create() creates a zero vec2.

It will return a tuple of the form {0.0,0.0}.

create(vec)

Specs:

  • create([float]) :: {float, float}

create(vec) creates a vec2 of value (x,y) out of a list of 2 or more numbers.

It will return a tupleof the form {x,y}.

create(x, y)

Specs:

  • create(float, float) :: {float, float}

create(x,y) creates a vec2 of value (x,y).

It will return a tuple of the form {x,y}.

dot(a, b)

Specs:

  • dot({float, float}, {float, float}) :: float

dot( a, b) finds the dot (inner) product of a vec2 (a) with another vec2 (b).

It returns a float of the value (axbx + ayby).

length(a)

Specs:

  • length({float, float}) :: float

length(a) finds the length (L2 norm) of a vec2 (a).

The length is the square root of the sum of the squares of the components.

It returns a float of the value ( sqrt(axax + ayay).

length_manhattan(a)

Specs:

  • length_manhattan({float, float}) :: float

length_manhattan(a) finds the Manhattan (L1 norm) length of a vec2 (a).

The Manhattan length is the sum of the components.

It returns a float of the value (ax + ay).

length_squared(a)

Specs:

  • length_squared({float, float}) :: float

length_squared(a) finds the square of the length of a vec2 (a).

In many cases, this is sufficient for comparisions and avaoids a sqrt.

It returns a float of the value (axax + ayay).

lerp(a, b, t)

Specs:

  • lerp({float, float}, {float, float}, float) :: {float, float}

lerp(a,b,t) is used to linearly interpolate between two given vectors a and b along an interpolant t.

The interpolant t is on the domain [0,1]. Behavior outside of that is undefined.

multiply(a, b)

Specs:

  • multiply({float, float}, {float, float}) :: {float, float}

multiply( a, b) mulitplies element-wise a vec2 (a) by a vec2 (b).

It returns a tuple of the form { axbx, ayby }.

near(a, b, distance)

Specs:

  • near({float, float}, {float, float}, float) :: boolean

near(a,b, distance) checks whether two vectors are within a length of each other.

normalize(a)

Specs:

  • normalize({float, float}) :: {float, float}

normalize(a) finds the unit vector with the same direction as a vec2 (a).

This is done by dividing each component by the vector’s magnitude.

It returns a tuple of the form { normx, normy }.

perp_prod(a, b)

Specs:

  • perp_prod({float, float}, {float, float}) :: float

perp_prod( a, b) finds the perpindicular product of a vec2 (a) with another vec2 (b).

The perpindicular product is the magnitude of the cross-product between the two vectors.

It returns a float of the value (axby - bxay).

project(a, b)

Specs:

  • project({float, float}, {float, float}) :: {float, float}

project(a,b) projects one vector onto another, and returns the resulting image.

rotate(a, theta)

Specs:

  • rotate({float, float}, float) :: {float, float}

rotate(a,theta) rotates a vec2 (a) CCW about the +Z axis theta radians.

scale(a, scale)

Specs:

  • scale({float, float}, float) :: {float, float}

scale( a, scale) uniformly scales a vec2 (a) by an amount (x).

It returns a tuple of the form { axscale, ayscale }.

subtract(a, b)

Specs:

  • subtract({float, float}, {float, float}) :: {float, float}

subtract(a, b) subtracts a vec2 (b) from a vec2 (a).

It returns a tuple of the form { ax - bx, ay - by }.