Graphmath.Vec2
This is the 2D mathematics library for graphmath.
Summary
add(a, b) |
|
compare(list1, list2, l) |
|
create() |
|
create(vec) | |
create(x, y) | |
dot(list1, list2) |
|
length(list1) |
|
length_manhattan(list1) |
|
length_squared(list1) |
|
lerp(list1, list2, t) |
|
normalize(list1) |
|
perp_prod(list1, list2) |
|
project(list1, list2) |
|
rotate(list1, theta) |
|
scale(vec, scale) |
|
subtract(list1, list2) |
|
Functions
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.
Specs:
- compare([float], [float], float) :: boolean
compare
is used to check whether or not two vectors are within a length of each other.
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].
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.
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.
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.
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.
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.
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.
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.
Specs:
- project([float], [float]) :: [float]
project
projects one vector onto another, and returns the resulting image.
Specs:
- rotate([float], float) :: [float]
rotate
is used to rotate a vec CCW about the +Z axis a given number of radians.
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.