Line segment (LineSegment)

LazySets.LineSegmentType
LineSegment{N, VN<:AbstractVector{N}} <: AbstractZonotope{N}

Type that represents a line segment in 2D between two points $p$ and $q$.

Fields

  • p – first point
  • q – second point

Examples

A line segment along the $x = y$ diagonal:

julia> s = LineSegment([0., 0], [1., 1.])
LineSegment{Float64, Vector{Float64}}([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. If it is desired to remove the endpoints, pass the options markershape=:none and seriestype=:shape.

Membership is checked with ∈ (in):

julia> [0., 0] ∈ s && [.25, .25] ∈ s && [1., 1] ∈ s && [.5, .25] ∉ s
true

We can check whether the intersection with another line segment is empty, and optionally compute a witness (which is the unique common point in this case):

julia> sn = LineSegment([1., 0], [0., 1.])
LineSegment{Float64, Vector{Float64}}([1.0, 0.0], [0.0, 1.0])

julia> isdisjoint(s, sn)
false

julia> isdisjoint(s, sn, true)
(false, [0.5, 0.5])
source
LazySets.dimMethod
dim(L::LineSegment)

Return the ambient dimension of a 2D line segment.

Input

  • L – 2D line segment

Output

The ambient dimension of the 2D line segment, which is $2$.

source
LazySets.σMethod
σ(d::AbstractVector, L::LineSegment)

Return the support vector of a 2D line segment in a given direction.

Input

  • d – direction
  • L – 2D 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$.

source
LazySets.ρMethod
ρ(d::AbstractVector, L::LineSegment)

Evaluate the support function of a 2D line segment in a given direction.

Input

  • d – direction
  • L – 2D line segment

Output

Evaluation of the support function in the given direction.

source
Base.:∈Method
∈(x::AbstractVector, L::LineSegment)

Check whether a given point is contained in a 2D line segment.

Input

  • x – point/vector
  • L – 2D line segment

Output

true iff $x ∈ L$.

Algorithm

Let $L = (p, q)$ be the line segment with extreme points $p$ and $q$, and let $x$ be the given point.

  1. A necessary condition for $x ∈ (p, q)$ is that the three points are aligned, thus their cross product should be zero.
  2. 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.

source
LazySets.centerMethod
center(L::LineSegment)

Return the center of a 2D line segment.

Input

  • L – 2D line segment

Output

The center of the line segment.

source
LazySets.an_elementMethod
an_element(L::LineSegment)

Return some element of a 2D line segment.

Input

  • L – 2D line segment

Output

The first vertex of the line segment.

source
Base.randMethod
rand(::Type{LineSegment}; [N]::Type{<:Real}=Float64, [dim]::Int=2,
     [rng]::AbstractRNG=GLOBAL_RNG, [seed]::Union{Int, Nothing}=nothing)

Create a random 2D line segment.

Input

  • LineSegment – type for dispatch
  • N – (optional, default: Float64) numeric type
  • dim – (optional, default: 2) dimension
  • rng – (optional, default: GLOBAL_RNG) random number generator
  • seed – (optional, default: nothing) seed for reseeding

Output

A random 2D line segment.

Algorithm

All numbers are normally distributed with mean 0 and standard deviation 1.

source
LazySets.halfspace_leftMethod
halfspace_left(L::LineSegment)

Return a half-space describing the 'left' of a two-dimensional 2D line segment through two points.

Input

  • L – 2D 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.

source
LazySets.halfspace_rightMethod
halfspace_right(L::LineSegment)

Return a half-space describing the 'right' of a two-dimensional 2D line segment through two points.

Input

  • L – 2D 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.

source
LazySets.vertices_listMethod
vertices_list(L::LineSegment)

Return the list of vertices of a 2D line segment.

Input

  • L – 2D line segment

Output

The list of end points of the line segment.

source
LazySets.constraints_listMethod
constraints_list(L::LineSegment)

Return a list of constraints defining a 2D line segment in 2D.

Input

  • L – 2D line segment

Output

A vector of constraints defining 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 a vector parallel to the line segment passing through one of the vertices.

source
LazySets.translateMethod
translate(L::LineSegment, v::AbstractVector)

Translate (i.e., shift) a 2D line segment by a given vector.

Input

  • L – 2D line segment
  • v – translation vector

Output

A translated line segment.

Algorithm

We add the vector to both defining points of the line segment.

source
LazySets.generatorsMethod
generators(L::LineSegment)

Return an iterator over the (single) generator of a 2D line segment.

Input

  • L – 2D line segment

Output

An iterator over the generator of L, if any.

source
LazySets.ngensMethod
ngens(L::LineSegment)

Return the number of generators of a 2D line segment.

Input

  • L – 2D line segment

Output

The number of generators.

Algorithm

A line segment has either one generator, or zero generators if it is a degenerated line segment of length zero.

source
LazySets.genmatMethod

genmat(L::LineSegment)

Return the generator matrix of a 2D line segment.

Input

  • L – 2D line segment

Output

A matrix with at most one column representing the generator of L.

source

Inherited from LazySet:

Inherited from AbstractPolytope:

Inherited from AbstractCentrallySymmetricPolytope:

Inherited from AbstractZonotope: