Published
Edited
Oct 18, 2021
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
IFS = pedalIFS(...vertices)
Insert cell
vertices = [
[0, 0],
[1, 0],
[0.4, 0.6]
]
Insert cell
function pedalIFS(A, B, C) {
let a = Math.sqrt((B[0] - C[0]) ** 2 + (B[1] - C[1]) ** 2);
let b = Math.sqrt((A[0] - C[0]) ** 2 + (A[1] - C[1]) ** 2);
let c = Math.sqrt((A[0] - B[0]) ** 2 + (A[1] - B[1]) ** 2);

let alpha = (b ** 2 + c ** 2 - a ** 2) / (2 * b * c);
let beta = (a ** 2 + c ** 2 - b ** 2) / (2 * a * c);
let gamma = (a ** 2 + b ** 2 - c ** 2) / (2 * a * b);

if (alpha > 0 && beta > 0 && gamma > 0) {
let AB = [B[0] - A[0], B[1] - A[1]];
let AC = [C[0] - A[0], C[1] - A[1]];
let fa = scale(alpha, A).compose(flip(AB, AC, A));

let BA = [A[0] - B[0], A[1] - B[1]];
let BC = [C[0] - B[0], C[1] - B[1]];
let fb = scale(beta, B).compose(flip(BA, BC, B));

let CA = [A[0] - C[0], A[1] - C[1]];
let CB = [B[0] - C[0], B[1] - C[1]];
let fc = scale(gamma, C).compose(flip(CA, CB, C));

return new IteratedFunctionSystem([fa, fb, fc]);
} else {
throw "Non accute triangle";
}
}
Insert cell
// Suppose two vectors u and v emanate from the point o.
// This function returns the reflection about the line through
// the point o that bisects the angle made by u and v, essentially
// flipping the positions of u and v, though not their magnitudes.

function flip(u, v, o = [0, 0]) {
let [ux, uy] = u;
let [vx, vy] = v;
let normu = Math.sqrt(ux ** 2 + uy ** 2);
ux = ux / normu;
uy = uy / normu;
let normv = Math.sqrt(vx ** 2 + vy ** 2);
vx = vx / normv;
vy = vy / normv;
let bisector = [ux + vx, uy + vy];
let n = [-bisector[1], bisector[0]];
return reflect(n, o);
}
Insert cell
import { scale, reflect } from "@mcmcclur/affinefunction-class"
Insert cell
import { IteratedFunctionSystem } from "@mcmcclur/iteratedfunctionsystem-class"
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