diff --git a/docs/src/lib/representations.md b/docs/src/lib/representations.md index 070ce6c2b9..4f8100b7d3 100644 --- a/docs/src/lib/representations.md +++ b/docs/src/lib/representations.md @@ -175,6 +175,7 @@ constrained_dimensions(::HalfSpace{N}) where {N<:Real} halfspace_left(::AbstractVector{N}, ::AbstractVector{N}) where {N<:Real} halfspace_right(::AbstractVector{N}, ::AbstractVector{N}) where {N<:Real} tosimplehrep(::AbstractVector{HalfSpace{N}}) where {N<:Real} +linear_map(::AbstractMatrix{N}, ::HalfSpace{N}) where {N} ``` Inherited from [`LazySet`](@ref): * [`norm`](@ref norm(::LazySet, ::Real)) diff --git a/src/HalfSpace.jl b/src/HalfSpace.jl index 0d4d889557..5c5553be76 100644 --- a/src/HalfSpace.jl +++ b/src/HalfSpace.jl @@ -6,7 +6,8 @@ import Base: rand, export HalfSpace, LinearConstraint, an_element, constrained_dimensions, - halfspace_left, halfspace_right + halfspace_left, halfspace_right, + linear_map """ HalfSpace{N<:Real} <: LazySet{N} @@ -356,3 +357,21 @@ function halfspace_right(p::AbstractVector{N}, q::AbstractVector{N})::HalfSpace{N} where {N<:Real} return halfspace_left(q, p) end + +""" + linear_map(M::AbstractMatrix{N}, hs::HalfSpace{N}) where {N} + +Return the concrete linear map of a half-space. + +### Input + +- `M` -- matrix +- `hs` -- half-space + +### Output + +The half-space obtained by applying the given linear map to the half-space. +""" +function linear_map(M::AbstractMatrix{N}, hs::HalfSpace{N}) where {N} + return linear_map(M, HPolyhedron([hs])) +end diff --git a/test/unit_HalfSpace.jl b/test/unit_HalfSpace.jl index 7f3eeb0abe..8ea33729b7 100644 --- a/test/unit_HalfSpace.jl +++ b/test/unit_HalfSpace.jl @@ -81,4 +81,10 @@ for N in [Float64, Rational{Int}, Float32] hs4 = HalfSpace(N[-1, 0], N(0)) # x >= 0 empty_intersection, v = is_intersection_empty(hs1, hs4, true) @test !is_intersection_empty(hs1, hs4) && !empty_intersection && v ∈ hs1 && v ∈ hs4 + + # test linear map of a half-space + H = HalfSpace(N[1.0, -1.0], N(0.0)) # x <= y + M = Matrix(-N(1.0)*I, 2, 2) + MH = linear_map(M, H) + @test constraints_list(MH)[1] == HalfSpace(N[-1.0, 1.0], N(0.0)) # x >= y end