# Why is the intersection of a polyhedra with itself not equal to itself?

**URL:** <https://discourse.julialang.org/t/why-is-the-intersection-of-a-polyhedra-with-itself-not-equal-to-itself/72585>\
**Category:** General Usage\
**Tags:** linearalgebra, combinatorics, polygons, polyhedra\
**Created:** [December 4, 2021, 5:24pm UTC](https://discourse.julialang.org/t/why-is-the-intersection-of-a-polyhedra-with-itself-not-equal-to-itself/72585 "2021-12-04T17:24:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![XLVII](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xlvii/32/37099_2.png) [@XLVII](https://discourse.julialang.org/u/XLVII)\
**Post date:** [December 4, 2021, 5:24pm UTC](https://discourse.julialang.org/t/why-is-the-intersection-of-a-polyhedra-with-itself-not-equal-to-itself/72585/1 "2021-12-04T17:24:34Z")

</div>

> using Polyhedra  
> import CDDLib  
> lib = CDDLib.Library()
> 
> P = polyhedron(vrep(Acolums,Is),lib) #(lines=Acolums , rays = Is)
> 
> println(intersect(P,P) == P ) # it should be true but it gives false

How can it be made to return true

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [December 4, 2021, 5:34pm UTC](https://discourse.julialang.org/t/why-is-the-intersection-of-a-polyhedra-with-itself-not-equal-to-itself/72585/2 "2021-12-04T17:34:40Z")

</div>

what is `Acolums`? is it possible to post runnable code?

The answer seems to be that `intersect` gives you

```julia
Polyhedron CDDLib.Polyhedron{Float64}:
10-element iterator of HalfSpace{Float64, Vector{Float64}}:

```

which is not `VRep`.

---

<div class="post-metadata">

**Author:** ![XLVII](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xlvii/32/37099_2.png) [@XLVII](https://discourse.julialang.org/u/XLVII)\
**Post date:** [December 4, 2021, 6:00pm UTC](https://discourse.julialang.org/t/why-is-the-intersection-of-a-polyhedra-with-itself-not-equal-to-itself/72585/3 "2021-12-04T18:00:01Z")

</div>

@jling

> P=polyhedron(vrep([Line([1, 0, -1, 0, 1]), Line([0, 1, 0, -1, 1])],[Ray([0, 0, 1, 0, 0]), Ray([0, 0, 0, 1, 0]), Ray([0, 0, 0, 0, 1])]),lib )
> 
> println(intersect(P,P) == P)

is this no vrep ?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [December 4, 2021, 6:03pm UTC](https://discourse.julialang.org/t/why-is-the-intersection-of-a-polyhedra-with-itself-not-equal-to-itself/72585/4 "2021-12-04T18:03:02Z")

</div>

the result of `interset` is not Vrep

---

<div class="post-metadata">

**Author:** ![XLVII](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xlvii/32/37099_2.png) [@XLVII](https://discourse.julialang.org/u/XLVII)\
**Post date:** [December 4, 2021, 6:04pm UTC](https://discourse.julialang.org/t/why-is-the-intersection-of-a-polyhedra-with-itself-not-equal-to-itself/72585/5 "2021-12-04T18:04:49Z")

</div>

@jling how to overcome this situation?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [December 4, 2021, 6:06pm UTC](https://discourse.julialang.org/t/why-is-the-intersection-of-a-polyhedra-with-itself-not-equal-to-itself/72585/6 "2021-12-04T18:06:35Z")

</div>

no idea, `convexhull(P, P)` gets you closer, but you need to remove redundant, and then the order of the vertices still different.

I think this package is not meant to be used like this, it’s like you can’t use floating point calculation to make sure to expressions evaluate to the same result. This package is numerical.

---

<div class="post-metadata">

**Author:** ![XLVII](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xlvii/32/37099_2.png) [@XLVII](https://discourse.julialang.org/u/XLVII)\
**Post date:** [December 4, 2021, 6:12pm UTC](https://discourse.julialang.org/t/why-is-the-intersection-of-a-polyhedra-with-itself-not-equal-to-itself/72585/7 "2021-12-04T18:12:11Z")

</div>

@jling Is there a suitable package-library where I can create polyhedra with rays and lines and find their intersects?

---

<div class="post-metadata">

**Author:** ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)\
**Post date:** [December 4, 2021, 7:38pm UTC](https://discourse.julialang.org/t/why-is-the-intersection-of-a-polyhedra-with-itself-not-equal-to-itself/72585/8 "2021-12-04T19:38:42Z")

</div>

Oscar.jl has intersection functionality for polyhedra:  
[https://oscar-system.github.io/Oscar.jl/stable/PolyhedralGeometry/Polyhedra/constructions/#intersect-Tuple{Polyhedron,%20Polyhedron}](https://oscar-system.github.io/Oscar.jl/stable/PolyhedralGeometry/Polyhedra/constructions/#intersect-Tuple%7BPolyhedron,%20Polyhedron%7D)

Happy to help (or find someone to help) if you have problems using it.
