Graphmath.Vec3.List

This is the 3D mathematics library for graphmath.

This submodule handles 3D vectors using lists of floats.

Summary

add(a, b)

add( a, b) adds a vec3 (a) to a vec3 (b)

create()

create() is used to create a 3d vector

create(vec)

create(vec) creates a vec3 of value (x,y,z) out of a list of 3 or more numbers

create(x, y, z)

create(x,y,z) creates a vec3 of value (x,y,z)

cross(a, b)

cross( a, b) finds the cross productof a vec3 (a) with another vec3 (b)

dot(a, b)

dot( a, b) finds the dot (inner) product of a vec3 (a) with another vec3 (b)

length(a)

length(a) finds the length (L2 norm) of a vec3 (a)

length_manhattan(a)

length_manhattan(a) finds the Manhattan (L1 norm) length of a vec3 (a)

length_squared(a)

length_squared(a) finds the square of the length of a vec3 (a)

lerp(a, b, t)

lerp(a,b,t) linearly interpolates between one vec3 (a) and another vec3 (b) along an interpolant t

multiply(a, b)

multiply( a, b) mulitplies element-wise a vec3 (a) by a vec3 (b)

near(a, b, distance)

near(a,b, distance) checks whether two vectors are within a length of each other

normalize(a)

normalize(a) finds the unit vector with the same direction as a vec3 (a)

rotate(v, k, theta)

rotate( v, k, theta) rotates a vector (v) about a unit vector (k) by theta radians

scale(a, scale)

scale( a, scale) uniformly scales a vec3 (a) by an amount (x)

subtract(a, b)

subtract(a, b) subtracts a vec3 (b) from a vec3 (a)

Functions

add(a, b)

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 ].

create()

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].

create(vec)

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].

create(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].

cross(a, b)

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 ).

dot(a, b)

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).

length(a)

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).

length_manhattan(a)

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).

length_squared(a)

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).

lerp(a, b, t)

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.

multiply(a, b)

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 ].

near(a, b, distance)

Specs:

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

near(a,b, distance) checks whether two vectors are within a length of each other.

normalize(a)

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)

Specs:

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

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))

scale(a, scale)

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 ].

subtract(a, b)

Specs:

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

subtract(a, b) subtracts a vec3 (b) from a vec3 (a).

It returns a list of the form [ ax - bx, ay - by, az - bz ].