Graphmath.Vec2

This is the 2D mathematics library for graphmath.

Summary

add_vec2(a, b)

add_vec2 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_vec2(list1, list2, l)

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

create_vec2()

create_vec2 is used to create a 2d vector

create_vec2(vec)
dot_vec2(list1, list2)

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

length_manhattan_vec2(list1)

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

length_squared_vec2(list1)

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

length_vec2(list1)

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

lerp_vec2(list1, list2, t)

lerp_vec2 is used to linearly interpolate between two given vectors

normalize_vec2(list1)

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

perp_prod_vec2(list1, list2)

perp_prod_vec2 is used to find the perpindicular product of two vec2s

project_vec2(list1, list2)

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

rotate_vec2(list1, theta)

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

scale_vec2(vec, scale)

scale_vec2 is used to perform a scaling on a vec2

subtract_vec2(list1, list2)

subtract_vec2 is used to subtract a vec2 from another vec2.

It takes two vec2s and returns the difference of the two

Functions

add_vec2(a, b)

Specs:

  • add_vec2([float], [float]) :: [float]
`add_vec2` 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_vec2(list1, list2, l)

Specs:

  • compare_vec2([float], [float], float) :: boolean
`compare_vec2` is used to check whether or not two vectors are within a length of each other.
create_vec2()

Specs:

  • create_vec2 :: [float]
`create_vec2` is used to create a 2d vector.

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

Specs:

  • create_vec2([float]) :: [float]
dot_vec2(list1, list2)

Specs:

  • dot_vec2([float], [float]) :: float
`dot_vec2` 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_manhattan_vec2(list1)

Specs:

  • length_manhattan_vec2([float]) :: float
`length_manhatten_vec2` is used to find the Manhattan (L1 norm) length of a vector.

The Manhattan length is simply the sum of the components.
length_squared_vec2(list1)

Specs:

  • length_squared_vec2([float]) :: float
`length_squared_vec2` is used to find the square of the length of a vector.

In many cases, this is sufficient for comparisions and avaoids a sqrt.
length_vec2(list1)

Specs:

  • length_vec2([float]) :: float
`length_vec2` is used to find the length (L2 norm) of a vector.

The length is the square root of the sum of the squares.
lerp_vec2(list1, list2, t)

Specs:

  • lerp_vec2([float], [float], float) :: [float]
`lerp_vec2` is used to linearly interpolate between two given vectors.

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

Specs:

  • normalize_vec2([float]) :: [float]
`normalize_vec2` 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_vec2(list1, list2)

Specs:

  • perp_prod_vec2([float], [float]) :: float
`perp_prod_vec2` 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_vec2(list1, list2)

Specs:

  • project_vec2([float], [float]) :: [float]
`project_vec2` projects one vector onto another, and returns the resulting image.
rotate_vec2(list1, theta)

Specs:

  • rotate_vec2([float], float) :: [float]
`rotate_vec2` is used to rotate a vec CCW about the +Z axis a given number of radians.
scale_vec2(vec, scale)

Specs:

  • scale_vec2([float], float) :: [float]
  • scale_vec2([float], [float]) :: [float]
`scale_vec2` 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_vec2(list1, list2)

Specs:

  • subtract_vec2([float], [float]) :: [float]
`subtract_vec2` is used to subtract a vec2 from another vec2.
It takes two vec2s and returns the difference of the two.