Platform
Solutions
Resources
Pricing
Sign in
Sign up
UnluckyNinja
Workspace
Fork
Public
Computational Geometry
By
UnluckyNinja
Edited
Oct 2, 2024
Importers
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
One platform
to build and deploy the best data apps
Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
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