2023-04-05

mathematics related procedures

part of sph-lib

(sph math)

procedure: absolute-difference n-1 n-2 ->

number number -> number

give the non-negative difference of two numbers

procedure: absolute-threshold b limit ->

return zero if the absolute value of b is below limit

procedure: angle-between p1 p2 ->

#(number number) #(number number) -> number

only for two dimensions

procedure: arithmetic-mean a ->

(number ...) -> number

calculate the arithmetic mean of the given numbers

procedure: bessel order x term-count ->

bessel function of the first kind. higher term-counts improve precision. example term-count: 6

procedure: bezier-curve t points ... ->

number:0..1 (number ...) ... -> (number ...)

get a point for a bezier curve at fractional offset t.

no limit on the number of control points.

no limit on the dimension of point vectors.

at least one point must be given.

uses the \"de casteljau\" algorithm

no limit on the number of control points.

no limit on the dimension of point vectors.

at least one point must be given.

uses the \"de casteljau\" algorithm

procedure: bezier-curve-cubic n p1 p2 p3 p4 ->

number vector ... -> vector

return coordinates for one point of a cubic 4-point bezier curve at fractional offset n.

like bezier-curve but optimised for cubic bezier curves.

the intermediate points between p1 and p4 are the control points.

there is no limit on the dimensions of point vectors

like bezier-curve but optimised for cubic bezier curves.

the intermediate points between p1 and p4 are the control points.

there is no limit on the dimensions of point vectors

procedure: catmull-rom-interpolate-f p0 p1 p2 p3 [alpha tension] ->

procedure: catmull-rom-path alpha tension resolution points ->

procedure: circle n radius ->

number:0..1 number -> (x y)

return a point on a circle with given radius at fractional offset n (on the circumference)

procedure: complex-from-magnitude-and-imaginary m i ->

procedure: differences a ->

return the differences between each pair of subsequent values in a given list.

result length is input length minus one.

example: (differences (list 1 3 7 8 6)) -> (2 4 1 -2)

result length is input length minus one.

example: (differences (list 1 3 7 8 6)) -> (2 4 1 -2)

procedure: ellipse n radius-x radius-y rotation ->

procedure: exponential-decay x from change ->

number number number -> number

from / ((x + 1) ** change)

procedure: factorial n ->

variable: golden-ratio

procedure: hermite-interpolate n tension bias p1 p2 p3 p4 ->

number:0..1 number-1..1 symbol:-1..1 vector vector vector vector -> vector

tension: -1 low, 0 normal, 1 high

bias: negative: towards p1, zero: even, positive: towards p4

bias: negative: towards p1, zero: even, positive: towards p4

procedure: integer-summands int count minimum [random-state] ->

procedure: line-path n points ... ->

procedure: linearly-interpolate offset a b ->

real:0..1 (number ...) ... -> point

return a point on a straight line between a and b at fractional offset.

also known as lerp

also known as lerp

procedure: list-average a ->

(number ...) -> number

calculate the arithmetic mean of the given numbers

procedure: list-center-of-mass a ->

(number ...) -> number

the distribution of mass is balanced around the center of mass and the average

of the weighted position coordinates of the distributed mass defines its coordinates.

the result is an index, possibly fractional.

c = sum(n * x(n)) / sum(x(n))

of the weighted position coordinates of the distributed mass defines its coordinates.

the result is an index, possibly fractional.

c = sum(n * x(n)) / sum(x(n))

procedure: list-median a ->

(number ...) -> number

return the median value of list. the median is the value separating the

higher half from the lower half in a sorted list of samples.

it may be thought of as the \"middle\" value

higher half from the lower half in a sorted list of samples.

it may be thought of as the \"middle\" value

procedure: list-mode a ->

(number ...) -> number

return the most common value in list or zero if none repeats

procedure: list-range a ->

(number ...) -> number

return the difference of the largest and the smallest value in list

procedure: log2 b ->

calculate the base two logarithm for b

procedure: percent value base ->

how many percent is value from base

variable: pi

procedure: relative-change a b ->

number number -> number

give the relative change between two numbers.

result times 100 gives the percentage change.

if a or b is zero then 1 is used in place.

example: 4 to 1 -> -3/4

result times 100 gives the percentage change.

if a or b is zero then 1 is used in place.

example: 4 to 1 -> -3/4

procedure: scale-to-mean mean b ->

number (number ...) -> (number ...)

scale the numbers in b to the given mean while keeping ratios between values the same

procedure: taylor-series-sin x term-count ->

calculates the taylor series sin(x) = x - x ** 3 / 3! + x ** 5 / 5! - x ** 7 / 7! + ...

minimum term-count to create a sine is 6

minimum term-count to create a sine is 6

procedure: vector-linearly-interpolate offset a b ->

real:0..1 (number ...) ... -> point

return a point on a straight line between a and b at fractional offset