# Intersection of non-overlapping point clouds with Polyhedra.jl

**URL:** https://discourse.julialang.org/t/intersection-of-non-overlapping-point-clouds-with-polyhedra-jl/74500
**Category:** General Usage
**Tags:** package, optimization, geometry, polyhedra
**Created:** [January 12, 2022, 5:30pm UTC](https://discourse.julialang.org/t/intersection-of-non-overlapping-point-clouds-with-polyhedra-jl/74500 "2022-01-12T17:30:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)
#### Post date: [January 12, 2022, 5:30pm UTC](https://discourse.julialang.org/t/intersection-of-non-overlapping-point-clouds-with-polyhedra-jl/74500/1 "2022-01-12T17:30:06Z")

</div>

Hi all,

I need to identify whether two point “clouds” of arbitrary dimension intersect. As a sanity check, I tested two non-overlapping point clouds to see if the results make sense. Strangely, the intersection is non-empty. Am I doing something incorrectly?

```julia
using Polyhedra, Random

# ranges from 0 to 1 in each dimension
points1 = rand(1000, 2)
# ranges from 10 to 11 in each dimension
points2 = rand(1000, 2) .+ 10

ph1 = polyhedron(vrep(points1))

ph2 = polyhedron(vrep(points2))

intersect(ph1, ph2)

```

---

<div class="post-metadata">

### Author: ![brianguenter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brianguenter/32/29519_2.png) [@brianguenter](https://discourse.julialang.org/u/brianguenter)
#### Post date: [January 12, 2022, 10:17pm UTC](https://discourse.julialang.org/t/intersection-of-non-overlapping-point-clouds-with-polyhedra-jl/74500/2 "2022-01-12T22:17:26Z")

</div>

On my machine the intersection is an empty polyhedron, using Polyhedra v0.6.17.

Which version of Polyhedra are you using? Maybe updating the package will fix the problem.

System info:

```julia
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, tigerlake)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 8

```

---

<div class="post-metadata">

### Author: ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)
#### Post date: [January 12, 2022, 11:12pm UTC](https://discourse.julialang.org/t/intersection-of-non-overlapping-point-clouds-with-polyhedra-jl/74500/3 "2022-01-12T23:12:36Z")

</div>

Hi Brian. Thanks for your reply. I am also using the same version:

**Version**

```julia
(@v1.7) pkg> st Polyhedra
      Status `~/.julia/environments/v1.7/Project.toml`
  [67491407] Polyhedra v0.6.17

julia> versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, haswell)
Environment:
  JULIA_CMDSTAN_HOME = /home/dfish/cmdstan
  JULIA_NUM_THREADS = 4
  JULIA_EDITOR = code

```

**Code**

```julia
using Polyhedra, Random

Random.seed!(5448)

points1 = rand(1000, 2)

points2 = rand(1000, 2) .+ 10

ph1 = polyhedron(vrep(points1))

ph2 = polyhedron(vrep(points2))

intersect(ph1, ph2)

```

When I run the code above (with the RNG seed set this time), I get the following result:

```julia
Polyhedron DefaultPolyhedron{Float64, MixedMatHRep{Float64, Matrix{Float64}}, MixedMatVRep{Float64, Matrix{Float64}}}:
38-element iterator of HalfSpace{Float64, Vector{Float64}}:
 HalfSpace([-0.7462477519569687, -0.03845547811729231], -0.013480793553864966)
 HalfSpace([-0.631648303668281, -0.07925921671122552], -0.018694015873781493)
 HalfSpace([-0.6562091647821909, 0.2518118199560842], 0.21274256968080027)
 HalfSpace([-0.7183230037709791, 0.19596921461056738], 0.15986258590309105)
 HalfSpace([-0.003954717247456662, -0.23874782378908826], -0.0015132839275770697)
 HalfSpace([-0.0010517702816531934, -0.23877617777670027], -0.0009270320917026878)
 HalfSpace([-0.006522312712251365, 0.5979383834248235], 0.5958076163402416)
 HalfSpace([0.01792971747635548, 0.5615940039679551], 0.5749463593095993)
 HalfSpace([0.20507167125043874, 0.03585744534363632], 0.23837882028596058)
 HalfSpace([-0.07428990598987983, -0.2256683809307513], -0.006862438464505046)
 HalfSpace([0.1949577049237804, -0.025710282476602772], 0.19227225404479864)
 HalfSpace([0.21621597234019985, 0.0016964974125853165], 0.21629736074799183)
 HalfSpace([0.01574311843644082, -0.2265573697244256], 0.011312917854648953)
 HalfSpace([0.17023892872160043, -0.05653372519373371], 0.1650827541793411)
 HalfSpace([0.00013767154323721662, 0.5965297173714741], 0.5961925181340423)
 HalfSpace([-0.8213607519521141, -0.004166129056533232], -0.004672555440764067)
 HalfSpace([0.17893288766097307, -0.0457972346051876], 0.1745709824015048)

```

Are you saying that you are getting an empty array instead?

---

<div class="post-metadata">

### Author: ![brianguenter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brianguenter/32/29519_2.png) [@brianguenter](https://discourse.julialang.org/u/brianguenter)
#### Post date: [January 13, 2022, 12:50am UTC](https://discourse.julialang.org/t/intersection-of-non-overlapping-point-clouds-with-polyhedra-jl/74500/4 "2022-01-13T00:50:35Z")

</div>

I’m guessing they do lazy evaluation of the polyhedron. If you do this:

```julia
julia> points(intersect(ph1,ph2))
0-element iterator of Vector{Float64}

```

the result looks like an empty polyhedron as opposed to the long list of points that you see returned from `intersect(ph1,ph2)`.

I’m not an expert on this package though. Maybe someone who knows it better can verify if this is true.

---

<div class="post-metadata">

### Author: ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)
#### Post date: [January 13, 2022, 2:39pm UTC](https://discourse.julialang.org/t/intersection-of-non-overlapping-point-clouds-with-polyhedra-jl/74500/5 "2022-01-13T14:39:20Z")

</div>

Thank you. As far as I can tell, using `points` as you suggested seems to be giving a more reasonable result.It looks like the points correspond to the boundary of the intersection. Nonetheless, I would be interested in additional input from someone who is more familiar with this package.
