(html (head (title "sph-lib (sph math)") (link (@ (rel "stylesheet") (type "text/css") (href "/css/sph.css"))) (meta (@ (name "viewport") (content "width=device-width,initial-scale=1"))) #f) (body () (div (@ (class top)) (nav (a (@ (href "/")) "start") ", " (a (@ (href "/feed.xml")) "feed")) "") (div (@ (class "middle")) (div (@ (class mtime) (title "last modification time of the current page")) "2023-04-05") (section (h1 "(sph math)") (div (p "mathematics related procedures") (p "part of " (a (@ (href "../../sph-lib.html")) "sph-lib")) (#f (section (@ (class "library-name")) (h1 "module name") (p "(sph math)")) (section (@ (class "library-exports")) (h1 "exported bindings") (div (div (@ (class "doc-bindings")) (div (@ (id "doc-b-" "absolute-difference") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "absolute-difference") " " (span (@ (class "first-sig")) "n-1 n-2 ->")) (div (@ (class "rest-sig")) (div "number number -> number")) (div (@ (class "description")) (("give the non-negative difference of two numbers")))) (div (@ (id "doc-b-" "absolute-threshold") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "absolute-threshold") " " (span (@ (class "first-sig")) "b limit ->")) "" (div (@ (class "description")) (("return zero if the absolute value of b is below limit")))) (div (@ (id "doc-b-" "angle-between") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "angle-between") " " (span (@ (class "first-sig")) "p1 p2 ->")) (div (@ (class "rest-sig")) (div "#(number number) #(number number) -> number")) (div (@ (class "description")) (("only for two dimensions")))) (div (@ (id "doc-b-" "arithmetic-mean") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "arithmetic-mean") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "(number ...) -> number")) (div (@ (class "description")) (("calculate the arithmetic mean of the given numbers")))) (div (@ (id "doc-b-" "bessel") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "bessel") " " (span (@ (class "first-sig")) "order x term-count ->")) "" (div (@ (class "description")) (("bessel function of the first kind. higher term-counts improve precision. example term-count: 6")))) (div (@ (id "doc-b-" "bezier-curve") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "bezier-curve") " " (span (@ (class "first-sig")) "t points ... ->")) (div (@ (class "rest-sig")) (div "number:0..1 (number ...) ... -> (number ...)")) (div (@ (class "description")) (("get a point for a bezier curve at fractional offset t." (br) "no limit on the number of control points." (br) "no limit on the dimension of point vectors." (br) "at least one point must be given." (br) "uses the \\\"de casteljau\\\" algorithm")))) (div (@ (id "doc-b-" "bezier-curve-cubic") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "bezier-curve-cubic") " " (span (@ (class "first-sig")) "n p1 p2 p3 p4 ->")) (div (@ (class "rest-sig")) (div "number vector ... -> vector")) (div (@ (class "description")) (("return coordinates for one point of a cubic 4-point bezier curve at fractional offset n." (br) "like bezier-curve but optimised for cubic bezier curves." (br) "the intermediate points between p1 and p4 are the control points." (br) "there is no limit on the dimensions of point vectors")))) (div (@ (id "doc-b-" "catmull-rom-interpolate-f") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "catmull-rom-interpolate-f") " " (span (@ (class "first-sig")) "p0 p1 p2 p3 [alpha tension] ->")) "" "") (div (@ (id "doc-b-" "catmull-rom-path") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "catmull-rom-path") " " (span (@ (class "first-sig")) "alpha tension resolution points ->")) "" "") (div (@ (id "doc-b-" "circle") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "circle") " " (span (@ (class "first-sig")) "n radius ->")) (div (@ (class "rest-sig")) (div "number:0..1 number -> (x y)")) (div (@ (class "description")) (("return a point on a circle with given radius at fractional offset n (on the circumference)")))) (div (@ (id "doc-b-" "complex-from-magnitude-and-imaginary") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "complex-from-magnitude-and-imaginary") " " (span (@ (class "first-sig")) "m i ->")) "" "") (div (@ (id "doc-b-" "differences") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "differences") " " (span (@ (class "first-sig")) "a ->")) "" (div (@ (class "description")) (("return the differences between each pair of subsequent values in a given list." (br) "result length is input length minus one." (br) "example: (differences (list 1 3 7 8 6)) -> (2 4 1 -2)")))) (div (@ (id "doc-b-" "ellipse") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ellipse") " " (span (@ (class "first-sig")) "n radius-x radius-y rotation ->")) "" "") (div (@ (id "doc-b-" "exponential-decay") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "exponential-decay") " " (span (@ (class "first-sig")) "x from change ->")) (div (@ (class "rest-sig")) (div "number number number -> number")) (div (@ (class "description")) (("from / ((x + 1) ** change)")))) (div (@ (id "doc-b-" "factorial") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "factorial") " " (span (@ (class "first-sig")) "n ->")) "" "") (div (@ (id "doc-b-" "golden-ratio") (class "doc-b")) (div (span (@ (class "type")) "variable") ": " (span (@ (class "name")) "golden-ratio")) "" "") (div (@ (id "doc-b-" "hermite-interpolate") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "hermite-interpolate") " " (span (@ (class "first-sig")) "n tension bias p1 p2 p3 p4 ->")) (div (@ (class "rest-sig")) (div "number:0..1 number-1..1 symbol:-1..1 vector vector vector vector -> vector")) (div (@ (class "description")) (("tension: -1 low, 0 normal, 1 high" (br) "bias: negative: towards p1, zero: even, positive: towards p4")))) (div (@ (id "doc-b-" "integer-summands") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "integer-summands") " " (span (@ (class "first-sig")) "int count minimum [random-state] ->")) "" "") (div (@ (id "doc-b-" "line-path") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "line-path") " " (span (@ (class "first-sig")) "n points ... ->")) "" "") (div (@ (id "doc-b-" "linearly-interpolate") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "linearly-interpolate") " " (span (@ (class "first-sig")) "offset a b ->")) (div (@ (class "rest-sig")) (div "real:0..1 (number ...) ... -> point")) (div (@ (class "description")) (("return a point on a straight line between a and b at fractional offset." (br) "also known as lerp")))) (div (@ (id "doc-b-" "list-average") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "list-average") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "(number ...) -> number")) (div (@ (class "description")) (("calculate the arithmetic mean of the given numbers")))) (div (@ (id "doc-b-" "list-center-of-mass") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "list-center-of-mass") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "(number ...) -> number")) (div (@ (class "description")) (("the distribution of mass is balanced around the center of mass and the average" (br) "of the weighted position coordinates of the distributed mass defines its coordinates." (br) "the result is an index, possibly fractional." (br) "c = sum(n * x(n)) / sum(x(n))")))) (div (@ (id "doc-b-" "list-median") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "list-median") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "(number ...) -> number")) (div (@ (class "description")) (("return the median value of list. the median is the value separating the" (br) "higher half from the lower half in a sorted list of samples." (br) "it may be thought of as the \\\"middle\\\" value")))) (div (@ (id "doc-b-" "list-mode") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "list-mode") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "(number ...) -> number")) (div (@ (class "description")) (("return the most common value in list or zero if none repeats")))) (div (@ (id "doc-b-" "list-range") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "list-range") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "(number ...) -> number")) (div (@ (class "description")) (("return the difference of the largest and the smallest value in list")))) (div (@ (id "doc-b-" "log2") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "log2") " " (span (@ (class "first-sig")) "b ->")) "" (div (@ (class "description")) (("calculate the base two logarithm for b")))) (div (@ (id "doc-b-" "percent") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "percent") " " (span (@ (class "first-sig")) "value base ->")) "" (div (@ (class "description")) (("how many percent is value from base")))) (div (@ (id "doc-b-" "pi") (class "doc-b")) (div (span (@ (class "type")) "variable") ": " (span (@ (class "name")) "pi")) "" "") (div (@ (id "doc-b-" "relative-change") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "relative-change") " " (span (@ (class "first-sig")) "a b ->")) (div (@ (class "rest-sig")) (div "number number -> number")) (div (@ (class "description")) (("give the relative change between two numbers." (br) "result times 100 gives the percentage change." (br) "if a or b is zero then 1 is used in place." (br) "example: 4 to 1 -> -3/4")))) (div (@ (id "doc-b-" "scale-to-mean") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "scale-to-mean") " " (span (@ (class "first-sig")) "mean b ->")) (div (@ (class "rest-sig")) (div "number (number ...) -> (number ...)")) (div (@ (class "description")) (("scale the numbers in b to the given mean while keeping ratios between values the same")))) (div (@ (id "doc-b-" "taylor-series-sin") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "taylor-series-sin") " " (span (@ (class "first-sig")) "x term-count ->")) "" (div (@ (class "description")) (("calculates the taylor series sin(x) = x - x ** 3 / 3! + x ** 5 / 5! - x ** 7 / 7! + ..." (br) "minimum term-count to create a sine is 6")))) (div (@ (id "doc-b-" "vector-linearly-interpolate") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "vector-linearly-interpolate") " " (span (@ (class "first-sig")) "offset a b ->")) (div (@ (class "rest-sig")) (div "real:0..1 (number ...) ... -> point")) (div (@ (class "description")) (("return a point on a straight line between a and b at fractional offset"))))))))))) ()))