# How to use convexhull in Meshes.jl?

**URL:** https://discourse.julialang.org/t/how-to-use-convexhull-in-meshes-jl/119440
**Category:** General Usage
**Tags:** question, package, meshes
**Created:** [September 15, 2024, 4:46pm UTC](https://discourse.julialang.org/t/how-to-use-convexhull-in-meshes-jl/119440 "2024-09-15T16:46:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![p\_f](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@p\_f](https://discourse.julialang.org/u/p_f)
#### Post date: [September 15, 2024, 4:46pm UTC](https://discourse.julialang.org/t/how-to-use-convexhull-in-meshes-jl/119440/1 "2024-09-15T16:46:53Z")

</div>

I found the `convexhull` function in Meshes.jl:  
[convexhull doc](https://docs.juliahub.com/Meshes/FuRcu/0.51.6/algorithms/hulls/#Meshes.convexhull)

The docs description “Convex hull of `object`.”

I have a vector of 2d points:

```julia
julia> points
1000-element Vector{Vector{Float64}}:
 [0.5090075873973284, 0.7935895094356397]
 [0.5896006255338349, 0.8640965436930047]
 [0.31107945002334914, 0.1282829645428072]
 ⋮
 [0.6629464927439436, 0.27566263195149276]
 [0.5735250132020138, 0.6521340975802663]

```

I tried `convexhull(points)`, but I got `ERROR: StackOverflowError:...`

Am I doing this wrong? I am not sure what `object` the function is expecting, but since I didn’t get a method error I’m assuming I’m using it correctly?

I also tried `convexhull(Point2f.(points))` and got the same

---

<div class="post-metadata">

### Author: ![p\_f](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@p\_f](https://discourse.julialang.org/u/p_f)
#### Post date: [September 15, 2024, 5:10pm UTC](https://discourse.julialang.org/t/how-to-use-convexhull-in-meshes-jl/119440/2 "2024-09-15T17:10:34Z")

</div>

figured it out:

```julia
points = [rand(2) for _ in 1:1000]
points2 = [Meshes.Point(p...) for p in points]
chul = convexhull(points2)
coords=[[vert.coords.x.val,vert.coords.y.val] for vert in chul.rings[1].vertices]
push!(coords,coords[1])
lines(Point2f.(coords))

```

I assume there is a nicer way to convert back to regulat floats as opposed to:  
`coords=[[vert.coords.x.val,vert.coords.y.val] for vert in chul.rings[1].vertices]`

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [September 15, 2024, 5:13pm UTC](https://discourse.julialang.org/t/how-to-use-convexhull-in-meshes-jl/119440/3 "2024-09-15T17:13:11Z")

</div>

You need to construct a vector of `Point`. It is all explained in the docs.

Your example above is accessing internal fields of the point, which is not recommended. Rely on `coords(point)` to access the coordinates, or on `to(point)` to get the vector from the origin.

---

<div class="post-metadata">

### Author: ![p\_f](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@p\_f](https://discourse.julialang.org/u/p_f)
#### Post date: [September 15, 2024, 5:35pm UTC](https://discourse.julialang.org/t/how-to-use-convexhull-in-meshes-jl/119440/4 "2024-09-15T17:35:18Z")

</div>

Apologies for giving up and asking on discourse, I had already spent a lot of time (compared to just using convhull in matlab) trying to find a usable convexhull function in Julia…the first two packages I tried gave errors when I added them…

Although shouldn’t the input types of the function be in its docstring? Upon reading `?convexhull` I gave up pretty quickly. I appreciate it is _somewhere_ in the docs.

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [September 15, 2024, 7:58pm UTC](https://discourse.julialang.org/t/how-to-use-convexhull-in-meshes-jl/119440/5 "2024-09-15T19:58:22Z")

</div>

We provide examples in the docs. We will add more examples.
