Published
Edited
Dec 26, 2020
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
q0 = {
const θ = toRad(angle); //Generally θ as acos(dot(p0,p1))
const factor1 = sin(θ*(1-t))/sin(θ);
const factor2 = sin(θ*t)/sin(θ);
return [p0[0]*factor1 + p1[0]*factor2, p0[1]*factor1 + p1[1]*factor2]
}
Insert cell
Insert cell
Insert cell
q1 = {
const α = toRad(angle * t); // interpolated angle
return [p0[0]*cos(α)-p0[1]*sin(α), p0[0]*sin(α)+p0[1]*cos(α)] // 2D rotation of p0
}
Insert cell
Insert cell
Insert cell
draw(p0,p1,q0)
Insert cell
draw(p0,p1,q1)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dot = ([ax,ay], [bx,by]) => ax*bx+ay*by
Insert cell
cos = Math.cos
Insert cell
acos = Math.acos
Insert cell
sin = Math.sin
Insert cell
π = Math.PI
Insert cell
toRad = deg => π*deg/180
Insert cell
Insert cell
texVec = v => {
const vec = Array.from(v);
return `\\begin{bmatrix}
${vec.map(d => `${oneDecimalMax(d)}\\\\`).join("")}
\\end{bmatrix}`;
}
Insert cell
function oneDecimalMax(num) {
return Math.round(num*10)/10
}
Insert cell
import {texBI,arrowhead,drawAxes} from "@harrystevens/linear-algebra"
Insert cell
d3 = require("d3@5")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more