Skip to content

Commit

Permalink
approximation of Rectification
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jul 18, 2020
1 parent 6d0c893 commit df59a08
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Approximations/Approximations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ include("box_approximations.jl")
include("template_directions.jl")
include("overapproximate.jl")
include("underapproximate.jl")
include("approximate.jl")
include("decompositions.jl")
include("distance.jl")
include("hausdorff_distance.jl")
Expand Down
42 changes: 42 additions & 0 deletions src/Approximations/approximate.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
approximate(R::Rectification; apply_convex_hull::Bool=false)
Approximate a rectification of a polytopic set with a convex polytope.
### Input
- `R` -- rectification
- `apply_convex_hull` -- (optional; default: `false`) option to remove redundant
vertices
### Output
A polytope in vertex representation.
There is no guarantee that the result over- or underapproximates `R`.
### Algorithm
Let ``X`` be the set that is rectified.
We compute the vertices of ``X``, rectify them, and return the convex hull of
the result.
### Notes
Let ``X`` be the set that is rectified and let ``p`` and ``q`` be two vertices
on a facet of ``X``.
Intuitively, an approximation may occur if the line segment connecting these
vertices crosses a coordinate hyperplane and if the line segment connecting the
rectified vertices has a different angle.
As a corollary, the approximation is exact for the special cases that the
original set is contained in either the positive or negative orthant or
is axis-aligned.
"""
function approximate(R::Rectification; apply_convex_hull::Bool=false)
vlist = [rectify(v) for v in vertices_list(set(R))]
if apply_convex_hull
vlist = convex_hull(vlist)
end
T = dim(R) == 2 ? VPolygon : VPolytope
return T(vlist)
end
22 changes: 22 additions & 0 deletions test/unit_approximate.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
for N in [Float64, Rational{Int}, Float32]
# approximate rectification by rectifying the vertices
# - exact approximation
X = Ball1(N[1, 1], N(1))
Y = approximate(Rectification(X))
@test isequivalent(Y, X)
# - underapproximation
X = Ball1(N[2, 2], N(3))
Y = approximate(Rectification(X))
Z = VPolygon([N[5, 2], N[2, 5], N[2, 0], N[0, 2]])
@test Y Z && Z Y
# - overapproximation
X = Ball1(N[-1, -1], N(2))
Y = approximate(Rectification(X))
Z = VPolygon([N[0, 0], N[0, 1], N[1, 0]])
@test Y Z && Z Y
# - neither over- nor underapproximation
X = VPolygon([N[3, 2], N[1, -1], N[-1, 2], N[-1, 4]])
Y = approximate(Rectification(X))
Z = VPolygon([N[3, 2], N[1, 0], N[0, 2], N[0, 4]])
@test Y Z && Z Y
end

0 comments on commit df59a08

Please sign in to comment.