Public
Edited
Oct 2, 2024
Importers
[CG] Convex Hull
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// from https://observablehq.com/@d3/polygonclip
// y is up, > 0 when left turn (in svg, y is down)
function lineOrient(ax, ay, bx, by, cx, cy) {
return (ax - cx) * (by - cy) - (ay - cy) * (bx - cx);
}
Insert cell
function normalizedSqrOrient(ax, ay, bx, by, cx, cy){
// cx -> bx+(cx-bx)/Math.sqrt((cx-bx)**2+(cy-by)**2)
// const m = (ax - bx)*(by-cy)-(ay-by)*(bx-cx) // = (ax - cx) * (by - cy) - (ay - cy) * (bx - cx)
const m = lineOrient(ax, ay, bx, by, cx, cy)
const s = Math.sign(m)
const n = (cx-bx)**2+(cy-by)**2
return m**2*s/n
}
Insert cell
// close to 1 when c is at the extension of ab
// can we replace the division? better not to bother though
function signedSquaredNormalizedDot(ax, ay, bx, by, cx, cy) {
const dot = (bx-ax)*(cx-bx) + (by-ay)*(cy-by)
const s = Math.sign(dot)
const lensqr = ((bx-ax)**2+(by-ay)**2)*((cx-bx)**2+(cy-by)**2)
return dot**2*s/lensqr
}
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