Overview
Curves
A simple way to plot a curve is with the use of the $from function, which will generate a list of numbers between two given endpoints.
The following code generates 100 points between 1 and 10.
let points = $from(1,10,100);
The following code generates 100 x values between 1 and 10, and then creates a point with the given x value and a y value determined by the function f.
let points = $from(1,10,100).map(p=>{
return {
x:p,
y:f(x)
}
});
Cycloid
{% y(t) = (at - b sin(t), a - b cos(t)) %}
In order to properly chart this graph, we need the x values to be
equally spaced. The interpolation library provides a function
that takes a list of x and y values, and creates a new list with
equally spaced x values and interpolated y values.
let in1 = await import('/lib/interpolation/v1.0.0/interpolation.mjs');
let a = 1;
let b = 1;
let points = $from(1,10,1000).map(t=>{
return {
x: a*t - b*Math.sin(t),
y: a - b*Math.cos(t)
}
});
let npoints = in1.equalSpaced(points.map(p=>[p.x,p.y]), 100);