Graphmath.Vec2.Tuple
This is the 2D mathematics library for graphmath.
This submodule handles vectors stored as a tuple.
Summary
add(a, b) |
|
create() |
|
create(vec) |
|
create(x, y) |
|
dot(a, b) |
|
length(a) |
|
length_manhattan(a) |
|
length_squared(a) |
|
lerp(a, b, t) |
|
multiply(a, b) |
|
near(a, b, distance) |
|
normalize(a) |
|
perp_prod(a, b) |
|
project(a, b) |
|
rotate(a, theta) |
|
scale(a, scale) |
|
subtract(a, b) |
|
Functions
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 }.
Specs:
- create :: {float, float}
create()
creates a zero vec2.
It will return a tuple of the form {0.0,0.0}.
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}.
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}.
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).
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).
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).
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).
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.
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 }.
Specs:
- near({float, float}, {float, float}, float) :: boolean
near(a,b, distance)
checks whether two vectors are within a length of each other.
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 }.
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).
Specs:
- project({float, float}, {float, float}) :: {float, float}
project(a,b)
projects one vector onto another, and returns the resulting image.
Specs:
- rotate({float, float}, float) :: {float, float}
rotate(a,theta)
rotates a vec2 (a) CCW about the +Z axis theta
radians.
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 }.