Platform
Resources
Pricing
Sign in
Get started
tau
math animations, geometric visuals, always learning
Workspace
Fork
Published
By
tau
Edited
Aug 23, 2019
Importers
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function
convexHull2D
(
p
)
{
const
p_
=
p
.
slice
(
)
;
const
sorted
=
p_
.
sort
(
(
a
,
b
)
=>
sortByX
(
a
,
b
)
)
;
const
upper
=
upperHull
(
sorted
)
;
const
lower
=
lowerHull
(
sorted
)
;
return
[
...
upper
,
...
lower
]
;
}
Insert cell
function
upperHull
(
p
)
{
const
n
=
p
.
length
;
const
u
=
[
]
;
for
(
let
i
=
0
;
i
<
n
;
++
i
)
{
while
(
u
.
length
>=
2
&&
det3
(
u
[
u
.
length
-
2
]
,
u
[
u
.
length
-
1
]
,
p
[
i
]
)
<=
0
)
{
u
.
pop
(
)
;
}
u
.
push
(
p
[
i
]
)
;
}
return
u
;
}
Insert cell
function
lowerHull
(
p
)
{
const
n
=
p
.
length
;
const
b
=
p
.
slice
(
)
.
reverse
(
)
;
const
l
=
[
]
;
for
(
let
i
=
0
;
i
<
b
.
length
;
++
i
)
{
while
(
l
.
length
>=
2
&&
det3
(
l
[
l
.
length
-
2
]
,
l
[
l
.
length
-
1
]
,
b
[
i
]
)
<=
0
)
{
l
.
pop
(
)
;
}
l
.
push
(
b
[
i
]
)
;
}
l
.
shift
(
)
;
return
l
;
}
Insert cell
function
drawHull
(
hull
,
context
)
{
const
hl
=
hull
.
length
;
hull
.
forEach
(
(
p
,
i
)
=>
line
(
p
,
hull
[
(
i
+
1
)
%
hl
]
,
context
)
)
;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
n
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
offset
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
smallest
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
direction
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
convexHull2D
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
upperHull
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
lowerHull
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
drawHull
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sortByX
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
det3
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
arrow
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
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