Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HPolygon vs HPolygon intersection in floating point #672

Closed
mforets opened this issue Sep 25, 2018 · 5 comments
Closed

Fix HPolygon vs HPolygon intersection in floating point #672

mforets opened this issue Sep 25, 2018 · 5 comments
Assignees
Labels
bug 🐛 Something isn't working

Comments

@mforets
Copy link
Member

mforets commented Sep 25, 2018

Let

p = VPolygon([[0.161915, 0.780202], 
              [0.264545, 0.293386],  
              [0.54406, 0.0902449],  
              [0.801169, 0.00964868],
              [0.954425, 0.155487],
              [0.8336, 0.636783],
              [0.656131, 0.737161]])

q = VPolygon([[0.0800543, 0.318534],
              [0.122886, 0.0980148],
              [0.655319, 0.143195],
              [0.627578, 0.699661],
              [0.245012, 0.953383]])

plot([p, q], alpha=0.1)

screen shot 2018-09-25 at 10 33 34

Compute the intersection with CDD:

using Polyhedra

pv = convert(VPolytope, p)
qv = convert(VPolytope, q)
plot!(intersection(pv, qv), alpha=0.6, color="orange")

screen shot 2018-09-25 at 10 41 19

Compute the intersection using intersection(::HPolygon, ::HPolygon):

ph = convert(HPolygon, p)
qh = convert(HPolygon, q)
plot!(intersection(ph, qh), alpha=0.3, color="black")

screen shot 2018-09-25 at 10 42 46

@mforets mforets added the bug 🐛 Something isn't working label Sep 25, 2018
@mforets
Copy link
Member Author

mforets commented Sep 25, 2018

FWIW note that

function intersection2(P1, P2)
    P = HPolygon()
    addconstraint!.(P, constraints_list(P1))
    addconstraint!.(P, constraints_list(P2))
    return P
end

plot(intersection2(tohrep(p), tohrep(q)), alpha=0.3, color="black")

screen shot 2018-09-25 at 10 44 50

@schillic
Copy link
Member

😟

@schillic
Copy link
Member

schillic commented Oct 7, 2018

This could be a problem with redundant constraints, see #381.

@mforets
Copy link
Member Author

mforets commented May 7, 2019

Just checked this again, and it has been fixed by now 🎉

ph = convert(HPolygon, p)
qh = convert(HPolygon, q)
plot!(intersection(ph, qh))

Screen Shot 2019-05-08 at 08 35 30


Regarding computation time, 

  • intersection(::HPolygon, ::HPolygon) ... 140us
  • intersection(::HPolytope, ::HPolytope) ... 284us
  • intersection(::HPolytope, ::HPolytope, backend=CDDLib.Library()) ... 645us

@mforets mforets closed this as completed May 7, 2019
@mforets
Copy link
Member Author

mforets commented May 7, 2019

On the other hand intersection of original VPolygon is slow:

@btime intersection($p, $q) # as VPolygon
2.594 ms (32355 allocations: 1.84 MiB)

(this passes through Polyhedra through this function, i'm thinking if we should rather use a 2D implementation, or at least convert to HPolygon and then use the intersection of HPolygon should be cheaper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants