Graphmath.Vec2

This is the 2D mathematics library for graphmath.

Summary

add(a, b)

add is used to add a vec2 to another vec2. It takes two vec2s and returns a vec2 which is the element-wise sum of those lists

compare(list1, list2, l)

compare is used to check whether or not two vectors are within a length of each other

create()

create is used to create a 2d vector

create(vec)
create(x, y)
dot(list1, list2)

dot is used to find the inner product (dot product) of one vec2 and another

length(list1)

length is used to find the length (L2 norm) of a vector

length_manhattan(list1)

length_manhatten is used to find the Manhattan (L1 norm) length of a vector

length_squared(list1)

length_squared is used to find the square of the length of a vector

lerp(list1, list2, t)

lerp is used to linearly interpolate between two given vectors

normalize(list1)

normalize is used to find the unit vector with the same direction as the supplied vector

perp_prod(list1, list2)

perp_prod is used to find the perpindicular product of two vec2s

project(list1, list2)

project projects one vector onto another, and returns the resulting image

rotate(list1, theta)

rotate is used to rotate a vec CCW about the +Z axis a given number of radians

scale(vec, scale)

scale is used to perform a scaling on a vec2

subtract(list1, list2)

subtract is used to subtract a vec2 from another vec2. It takes two vec2s and returns the difference of the two

Functions

add(a, b)

Specs:

  • add([float], [float]) :: [float]

add is used to add a vec2 to another vec2. It takes two vec2s and returns a vec2 which is the element-wise sum of those lists.

compare(list1, list2, l)

Specs:

  • compare([float], [float], float) :: boolean

compare is used to check whether or not two vectors are within a length of each other.

create()

Specs:

  • create :: [float]

create is used to create a 2d vector.

It takes a list of numbers and converts it into an array of form [x,y].

create(vec)

Specs:

  • create([float]) :: [float]
create(x, y)

Specs:

  • create(float, float) :: [float]
dot(list1, list2)

Specs:

  • dot([float], [float]) :: float

dot is used to find the inner product (dot product) of one vec2 and another.

Passing it two vec2s will cause it to return the inner product of those two vec2s.

length(list1)

Specs:

  • length([float]) :: float

length is used to find the length (L2 norm) of a vector.

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

length_manhattan(list1)

Specs:

  • length_manhattan([float]) :: float

length_manhatten is used to find the Manhattan (L1 norm) length of a vector.

The Manhattan length is simply the sum of the components.

length_squared(list1)

Specs:

  • length_squared([float]) :: float

length_squared is used to find the square of the length of a vector.

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

lerp(list1, list2, t)

Specs:

  • lerp([float], [float], float) :: [float]

lerp is used to linearly interpolate between two given vectors.

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

normalize(list1)

Specs:

  • normalize([float]) :: [float]

normalize is used to find the unit vector with the same direction as the supplied vector.

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

perp_prod(list1, list2)

Specs:

  • perp_prod([float], [float]) :: float

perp_prod is used to find the perpindicular product of two vec2s.

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

project(list1, list2)

Specs:

  • project([float], [float]) :: [float]

project projects one vector onto another, and returns the resulting image.

rotate(list1, theta)

Specs:

  • rotate([float], float) :: [float]

rotate is used to rotate a vec CCW about the +Z axis a given number of radians.

scale(vec, scale)

Specs:

  • scale([float], float) :: [float]
  • scale([float], [float]) :: [float]

scale is used to perform a scaling on a vec2.

Passing it a single number will cause all elements of the vec2 to be multipled by that number. Passing it a vec2 will cause each element of to be multiplied by the corresponding element of the scale vec2.

subtract(list1, list2)

Specs:

  • subtract([float], [float]) :: [float]

subtract is used to subtract a vec2 from another vec2. It takes two vec2s and returns the difference of the two.