-
Notifications
You must be signed in to change notification settings - Fork 33
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
#5 - Implement hrep from vrep for VPolygon #376
Conversation
using LazySets
points_all = [[0.9,0.2], [0.4,0.6], [0.2,0.1], [0.1,0.3], [0.3,0.28]]
for i in [0, 1, 2, 5]
points = i == 0 ? Vector{Vector{Float64}}() : points_all[1:i]
V = VPolygon(points, apply_convex_hull=i > 0)
H1 = tohrep(V)
H2 = HPolygon{Float64}() # check that constraints are sorted correctly
for c in H1.constraints
addconstraint!(H2, c)
end
println(V)
println(H1)
println(H1.constraints == H2.constraints)
println()
end Output: LazySets.VPolygon{Float64}(Array{Float64,1}[])
LazySets.HPolygon{Float64}(LazySets.HalfSpace{Float64}[])
true
LazySets.VPolygon{Float64}(Array{Float64,1}[[0.9, 0.2]])
LazySets.HPolygon{Float64}(LazySets.HalfSpace{Float64}[LazySets.HalfSpace{Float64}([1.0, 1.0], 1.1), LazySets.HalfSpace{Float64}([-1.0, 0.0], -0.9), LazySets.HalfSpace{Float64}([0.0, -1.0], -0.2)])
true
LazySets.VPolygon{Float64}(Array{Float64,1}[[0.9, 0.2], [0.4, 0.6]])
LazySets.HPolygon{Float64}(LazySets.HalfSpace{Float64}[LazySets.HalfSpace{Float64}([0.4, 0.5], 0.46), LazySets.HalfSpace{Float64}([-0.5, 0.4], 0.04), LazySets.HalfSpace{Float64}([-0.4, -0.5], -0.46), LazySets.HalfSpace{Float64}([0.5, -0.4], 0.37)])
true
LazySets.VPolygon{Float64}(Array{Float64,1}[[0.1, 0.3], [0.2, 0.1], [0.9, 0.2], [0.4, 0.6]])
LazySets.HPolygon{Float64}(LazySets.HalfSpace{Float64}[LazySets.HalfSpace{Float64}([0.4, 0.5], 0.46), LazySets.HalfSpace{Float64}([-0.3, 0.3], 0.06), LazySets.HalfSpace{Float64}([-0.2, -0.1], -0.05), LazySets.HalfSpace{Float64}([0.1, -0.7], -0.05)])
true |
i didn't check the details yet, but i would suppose that we want to exploit that fact that a |
Yes, I do that. Even better, I start with the vertex pair that corresponds to the first constraint in the resulting |
Thanks for the documentation.
No, that is why it is called |
src/HalfSpace.jl
Outdated
""" | ||
function halfspace_left(p::AbstractVector{N}, | ||
q::AbstractVector{N})::HalfSpace{N} where {N<:Real} | ||
@assert p != q "the points must not be equal" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this notion of "left", i think, only makes sense in 2D, but HalfSpace
is general so i think we should make this check here and throw an error otherwise. i can add it and see if you agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- EDIT: Forget it, this was silly.
- Do you think we should also add a version from a
LineSegment
(which is just the one-liner which unwraps the two vertices and calls this function here)? - Should we move the function to
AbstractHPolygon
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should also add a version from a LineSegment (which is just the one-liner which unwraps the two vertices and calls this function here)?
sounds good, i'll do in the next push.
also and while we are at this, add halfspace_right
.
Should we move the function to AbstractHPolygon instead?
i think that in HalfSpace.jl
is fine.
My formulation was not the best, my point being that for choosing |
That said, i think that it looks better without that part. |
line_dir = -line_dir | ||
addconstraint!(H, LinearConstraint(line_dir, dot(L.p, line_dir))) | ||
return H | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well done!
I wonder how does this (EDIT) constraints_list = vcat([halfspace_left(P.vertices_list[i], P.vertices_list[i+1]) for i in 1:length(P.vertices_list)-1],
[halfspace_left(P.vertices_list[end], P.vertices_list[1])])
return HPolygon(constraints_list) |
### Examples | ||
|
||
The left half-space of the "east" and "west" directions in two-dimensions are the | ||
upper and lower half-spaces: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good!
Good thinking, but you need to start at the index that was found before ( vl = P.vertices_list
constraints_list = vcat(
[halfspace_left(vl[j], vl[j+1]) for j in i:length(vl)-1],
[halfspace_left(vl[end], vl[1])],
[halfspace_left(vl[j], vl[j+1]) for j in 1:i-1])
return HPolygon(constraints_list) My usual way of thinking is to write the code myself, but I prefer your version. Do you want to add it? |
ok. it took me a while to understand what was wrong with my version 😄 |
I just realized that this PR conflicts with #386. We should merge only one of them (the order does not matter) and then rebase and replace the missing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
function halfspace_right(p::AbstractVector{N}, | ||
q::AbstractVector{N})::HalfSpace{N} where {N<:Real} | ||
return halfspace_right(q, p) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a line
src/LineSegment.jl
Outdated
|
||
halfspace_left(L::LineSegment) = halfspace_left(L.p, L.q) | ||
|
||
halfspace_right(L::LineSegment) = halfspace_right(L.p, L.q) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a line
The build fail with Julia v0.6 is the same as in #386. It could also be a recent bug in |
Hmm in my machine the tests pass (v0.6.1) and julia> Pkg.installed("IntervalArithmetic")
v"0.13.0+" |
Hmm we can always pick the version that we use in Sooner or later we should also switch to 0.7 .. 1.0 |
Here (v0.6.2) they pass as well (I also updated the package). Note that the Travis builds for v0.6.1 and v0.6.1 pass; only v0.6 fails. The thing is that as soon as we merge, the green badge on the front page will become red 😞 |
Note to myself: I want to do this before merging. |
Closes #5.