Graphmath.Vec3
This is the 3D mathematics library for graphmath.
Summary
| add(a, b) |
|
| create() |
|
| create(vec) |
|
| create(x, y, z) |
|
| cross(a, b) |
|
| dot(a, b) |
|
| length(a) |
|
| length_manhattan(a) |
|
| length_squared(a) |
|
| lerp(a, b, t) |
|
| multiply(a, b) |
|
| near(a, b, distance) |
|
| normalize(a) |
|
| rotate(v, k, theta) |
|
| scale(a, scale) |
|
| subtract(a, b) |
|
Functions
Specs:
- add([float], [float]) :: [float]
add( a, b) adds a vec3 (a) to a vec3 (b).
It returns a list of the form [ ax + bx, ay + by, az + bz ].
Specs:
- create :: [float]
create() is used to create a 3d vector.
It takes a list of numbers and converts it into an array of form [x,y,z].
Specs:
- create([float]) :: [float]
create(vec) creates a vec3 of value (x,y,z) out of a list of 3 or more numbers.
It will return a list of the form [x,y,z].
Specs:
- create(float, float, float) :: [float]
create(x,y,z) creates a vec3 of value (x,y,z).
It will return a list of the form [x,y,z].
Specs:
- cross([float], [float]) :: [float]
cross( a, b) finds the cross productof a vec3 (a) with another vec3 (b).
The cross product of two vectors is a vector perpendicular to the two soure vectors. Its magnitude will be the area of the parallelogram made by the two souce vectors.
It returns a float of the value ( y1z2 - z1y2, z1x2 - x1z2, x1y2 - y1x2 ).
Specs:
- dot([float], [float]) :: float
dot( a, b) finds the dot (inner) product of a vec3 (a) with another vec3 (b).
It returns a float of the value (axbx + ayby + az*bz).
Specs:
- length([float]) :: float
length(a) finds the length (L2 norm) of a vec3 (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 + az*az).
Specs:
- length_manhattan([float]) :: float
length_manhattan(a) finds the Manhattan (L1 norm) length of a vec3 (a).
The Manhattan length is the sum of the components.
It returns a float of the value (ax + ay + az).
Specs:
- length_squared([float]) :: float
length_squared(a) finds the square of the length of a vec3 (a).
In many cases, this is sufficient for comparisions and avaoids a sqrt.
It returns a float of the value (axax + ayay + az*az).
Specs:
- lerp([float], [float], float) :: [float]
lerp(a,b,t) linearly interpolates between one vec3 (a) and another vec3 (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]
multiply( a, b) mulitplies element-wise a vec3 (a) by a vec3 (b).
It returns a list of the form [ ax*bx, ay*by ].
Specs:
- near([float], [float], float) :: boolean
near(a,b, distance) checks whether two vectors are within a length of each other.
Specs:
- normalize([float]) :: [float]
normalize(a) finds the unit vector with the same direction as a vec3 (a).
This is done by dividing each component by the vector’s magnitude.
It returns a list of the form [ normx, normy, normz ].
rotate( v, k, theta) rotates a vector (v) about a unit vector (k) by theta radians.
This uses the Formula of Rodriguez:
Vrot = Vcos(theta) + (K x V)sin(theta) + K(K*V)(1-cos(theta))
Specs:
- scale([float], float) :: [float]
scale( a, scale) uniformly scales a vec3 (a) by an amount (x).
It returns a list of the form [ ax*scale, ay*scale, az*scale ].