Platform
Resources
Pricing
Sign in
Get started
UnluckyNinja
Workspace
Fork
Public
Computational Geometry
By
UnluckyNinja
Edited
Oct 2, 2024
Importers
Computational Geometry
[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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
pointSize
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
randomPoints
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
random
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
ghshull
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
convexHullGHS
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
dnchull
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
convexHullDnC
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
jmhull
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
convexHullJM
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
drawSVG
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
lineOrient
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
normalizedSqrOrient
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
signedSquaredNormalizedDot
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML