All of the functions in this module take as their first argument the number of steps to take from 0 to 1, and a function to evaluate, but evaluate that function at a different number of parameter values to obtain different numbers of results:
Function call | Results | Parameter values passed
--------------|---------|-------------------------------
steps 4 | 5 | [ 0, 0.25, 0.5, 0.75, 1 ]
leading 4 | 4 | [ 0, 0.25, 0.5, 0.75 ]
trailing 4 | 4 | [ 0.25, 0.5, 0.75, 1 ]
inBetween 4 | 3 | [ 0.25, 0.5, 0.75 ]
midpoints 4 | 4 | [ 0.125, 0.375, 0.625, 0.875 ]
See the documentation of each function for details.
steps : Basics.Int -> (Basics.Float -> a) -> List a
For a given n
(which must be greater than zero), call the given function
n + 1
times with values evenly spaced between 0 and 1 inclusive, and return
the results as a list:
import Float.Extra as Float
Parameter1d.steps 4 (Float.interpolateFrom 10 20)
--> [ 10, 12.5, 15, 17.5, 20 ]
You can read this as "take 4 steps to interpolate from 10 to 20". More generally,
Parameter1d.steps 4 someFunction
will return
[ someFunction 0.0
, someFunction 0.25
, someFunction 0.5
, someFunction 0.75
, someFunction 1.0
]
Note that the results do not themselves have to be Float
s:
import Point2d
p1 =
Point2d.fromCoordinates ( 0, 0 )
p2 =
Point2d.fromCoordinates ( 100, 200 )
Parameter1d.steps 4 (Point2d.interpolateFrom p1 p2)
--> [ Point2d.fromCoordinates ( 0, 0 )
--> , Point2d.fromCoordinates ( 25, 50 )
--> , Point2d.fromCoordinates ( 50, 100 )
--> , Point2d.fromCoordinates ( 75, 150 )
--> , Point2d.fromCoordinates ( 100, 200 )
--> ]
Passing a negative or zero value as the first argument will result in an empty list being returned.
leading : Basics.Int -> (Basics.Float -> a) -> List a
Like steps
, but with the last value omitted:
import Float.Extra as Float
Parameter1d.leading 4 (Float.interpolateFrom 10 20)
--> [ 10, 12.5, 15, 17.5 ]
trailing : Basics.Int -> (Basics.Float -> a) -> List a
Also like steps
, but with the first value omitted:
import Float.Extra as Float
Parameter1d.trailing 4 (Float.interpolateFrom 10 20)
--> [ 12.5, 15, 17.5, 20 ]
inBetween : Basics.Int -> (Basics.Float -> a) -> List a
Like steps
but with both the first and last values omitted (the
"in-between" values only). Note that the given n
still refers to the number of
steps to take; the number of returned values will be one less than the number of
steps.
import Float.Extra as Float
Parameter1d.inBetween 4 (Float.interpolateFrom 10 20)
--> [ 12.5, 15, 17.5 ]
Parameter1d.inBetween 3 (Float.interpolateFrom 10 20)
--> [ 13.3333, 16.6667 ]
Parameter1d.inBetween 2 (Float.interpolateFrom 10 20)
--> [ 15 ]
Passing a value less than 2 will result in an empty list being returned.
midpoints : Basics.Int -> (Basics.Float -> a) -> List a
For a given n
> 0, construct n
equal-width intervals between 0 and 1 and
call the given function at the midpoint of each interval. This is useful for
some mathematical operations like numerical
integration.
import Float.Extra as Float
Parameter1d.midpoints 4 (Float.interpolateFrom 10 20)
--> [ 11.25, 13.75, 16.25, 18.75 ]