Line segment (LineSegment)
LazySets.LineSegment
— Type.LineSegment{N<:Real, VN<:AbstractVector{N}} <: AbstractZonotope{N}
Type that represents a line segment in 2D between two points $p$ and $q$.
Fields
p
– first pointq
– second point
Examples
A line segment along the $x = y$ diagonal:
julia> s = LineSegment([0., 0], [1., 1.])
LineSegment{Float64,Array{Float64,1}}([0.0, 0.0], [1.0, 1.0])
julia> dim(s)
2
Use plot(s)
to plot the extreme points of s
and the line segment joining them. Membership test is computed with ∈ (in
):
julia> [0., 0] ∈ s && [.25, .25] ∈ s && [1., 1] ∈ s && [.5, .25] ∉ s
true
We can check the intersection with another line segment, and optionally compute a witness (which is just the common point in this case):
julia> sn = LineSegment([1., 0], [0., 1.])
LineSegment{Float64,Array{Float64,1}}([1.0, 0.0], [0.0, 1.0])
julia> isempty(s ∩ sn)
false
julia> is_intersection_empty(s, sn, true)
(false, [0.5, 0.5])
LazySets.dim
— Method.dim(L::LineSegment)
Return the ambient dimension of a line segment.
Input
L
– line segment
Output
The ambient dimension of the line segment, which is 2.
LazySets.σ
— Method.σ(d::AbstractVector{N}, L::LineSegment{N}) where {N<:Real}
Return the support vector of a line segment in a given direction.
Input
d
– directionL
– line segment
Output
The support vector in the given direction.
Algorithm
If the angle between the vector $q - p$ and $d$ is bigger than 90° and less than 270° (measured in counter-clockwise order), the result is $p$, otherwise it is $q$. If the angle is exactly 90° or 270°, or if the direction has norm zero, this implementation returns $q$.
Base.:∈
— Method.∈(x::AbstractVector{N}, L::LineSegment{N}) where {N<:Real}
Check whether a given point is contained in a line segment.
Input
x
– point/vectorL
– line segment
Output
true
iff $x ∈ L$.
Algorithm
Let $L = (p, q)$ be the line segment with extremes $p$ and $q$, and let $x$ be the given point.
- A necessary condition for $x ∈ (p, q)$ is that the three points are aligned, thus their cross product should be zero.
- It remains to check that $x$ belongs to the box approximation of $L$. This amounts to comparing each coordinate with those of the extremes $p$ and $q$.
Notes
The algorithm is inspired from here.
LazySets.center
— Method.center(L::LineSegment{N}) where {N<:Real}
Return the center of a line segment.
Input
L
– line segment
Output
The center of the line segment.
LazySets.an_element
— Method.an_element(L::LineSegment{N}) where {N<:Real}
Return some element of a line segment.
Input
L
– line segment
Output
The first vertex of the line segment.
Base.rand
— Method.rand(::Type{LineSegment}; [N]::Type{<:Real}=Float64, [dim]::Int=2,
[rng]::AbstractRNG=GLOBAL_RNG, [seed]::Union{Int, Nothing}=nothing)
Create a random line segment.
Input
LineSegment
– type for dispatchN
– (optional, default:Float64
) numeric typedim
– (optional, default: 2) dimensionrng
– (optional, default:GLOBAL_RNG
) random number generatorseed
– (optional, default:nothing
) seed for reseeding
Output
A random line segment.
Algorithm
All numbers are normally distributed with mean 0 and standard deviation 1.
LazySets.halfspace_left
— Method.halfspace_left(L::LineSegment)
Return a half-space describing the 'left' of a two-dimensional line segment through two points.
Input
L
– line segment
Output
The half-space whose boundary goes through the two points p
and q
and which describes the left-hand side of the directed line segment pq
.
LazySets.halfspace_right
— Method.halfspace_right(L::LineSegment)
Return a half-space describing the 'right' of a two-dimensional line segment through two points.
Input
L
– line segment
Output
The half-space whose boundary goes through the two points p
and q
and which describes the right-hand side of the directed line segment pq
.
LazySets.vertices_list
— Method.vertices_list(L::LineSegment{N}) where {N<:Real}
Return the list of vertices of a line segment.
Input
L
– line segment
Output
The list of end points of the line segment.
LazySets.constraints_list
— Method.constraints_list(L::LineSegment{N}) where {N<:Real}
Return the list of constraints defining a line segment in 2D.
Input
L
– line segment
Output
A vector of constraints that define the line segment.
Algorithm
$L$ is defined by 4 constraints. In this algorithm, the first two constraints are returned by $halfspace_right$ and $halfspace_left$, and the other two are obtained by considering the vector normal to the line segment that passes through each opposite vertex.
Notes
This function returns a vector of halfspaces. It does not return equality constraints.
LazySets.translate
— Method.translate(L::LineSegment{N}, v::AbstractVector{N}) where {N<:Real}
Translate (i.e., shift) a line segment by a given vector.
Input
L
– line segmentv
– translation vector
Output
A translated line segment.
Algorithm
We add the vector to both defining points of the line segment.
LazySets.generators
— Method.generators(L::LineSegment{N}) where {N<:Real}
Return an iterator over the (single) generator of a line segment.
Input
L
– line segment
Output
A one-element iterator over the generator of L
.
LazySets.genmat
— Method.genmat(L::LineSegment)
Return the generator matrix of a line segment.
Input
L
– line segment
Output
A matrix with a single column representing the generator of L
.
LazySets.plot_recipe
— Method.plot_recipe(L::LineSegment{N}, [ε]::N=zero(N)) where {N<:Real}
Convert a line segment to a pair (x, y)
of points for plotting.
Input
L
– line segmentε
– (optional, default:0
) ignored, used for dispatch
Output
A pair (x, y)
of two points that can be plotted.
RecipesBase.apply_recipe
— Method.plot_linesegment(X::Union{Interval{N}, LineSegment{N}}, [ε]::N=zero(N); ...)
where {N<:Real}
Plot a line segment or an interval.
Input
X
– line segment or intervalε
– (optional, default:0
) ignored, used for dispatch
Examples
julia> L = LineSegment([0., 0.], [1., 1.]);
julia> plot(L)
To control the color of the line, use the linecolor
keyword argument, and to control the color of the end points, use the markercolor
keyword argument. To control the width, use linewidth
.
julia> plot(L, markercolor="green", linecolor="red", linewidth=2.)
To omit the markers, use markershape=:none
. You also need to pass a value for seriestype=:path
explicitly (this seems to be an external bug).
julia> plot(L, seriestype=:path, markershape=:none)
A shorter alternative is to pass marker=0
, but this may result in small dots as markers based on the plotting backend.
julia> plot(L, marker=0)
Inherited from LazySet
:
Inherited from AbstractPolytope
:
Inherited from AbstractCentrallySymmetricPolytope
:
Inherited from AbstractZonotope
: