Polygons (AbstractPolygon)
A polygon is a two-dimensional polytope.
LazySets.AbstractPolygon
— TypeAbstractPolygon{N} <: AbstractPolytope{N}
Abstract type for convex polygons (i.e., two-dimensional polytopes).
Notes
Every concrete AbstractPolygon
must define the following functions:
tohrep(::AbstractPolygon)
– transform into constraint representationtovrep(::AbstractPolygon)
– transform into vertex representation
The subtypes of AbstractPolygon
(including abstract interfaces):
julia> subtypes(AbstractPolygon)
2-element Vector{Any}:
AbstractHPolygon
VPolygon
This interface requires to implement the following functions:
LazySets.tohrep
— Methodtohrep(P::AbstractPolygon)
Convert a convex polygon to constraint representation.
Input
P
– convex polygon
Output
A polygon in constraint representation.
LazySets.tovrep
— Methodtovrep(P::AbstractPolygon)
Convert a convex polygon to vertex representation.
Input
P
– convex polygon
Output
A polygon in vertex representation.
This interface defines the following functions:
LazySets.API.dim
— Methoddim(P::AbstractPolygon)
Return the ambient dimension of a convex polygon.
Input
P
– convex polygon
Output
The ambient dimension of the polygon, which is 2.
LazySets.API.volume
— Methodvolume(P::AbstractPolygon)
Compute the volume of a convex polygon.
Input
P
– convex polygon
Output
A number representing the volume of P
.
Notes
In 2D the volume is equivalent to the area.
The following helper functions are used for sorting directions:
LazySets.jump2pi
— Functionjump2pi(x::N) where {N<:AbstractFloat}
Return $x + 2π$ if $x$ is negative, otherwise return $x$.
Input
x
– real scalar
Output
$x + 2π$ if $x$ is negative, $x$ otherwise.
Examples
julia> using LazySets: jump2pi
julia> jump2pi(0.0)
0.0
julia> jump2pi(-0.5)
5.783185307179586
julia> jump2pi(0.5)
0.5
LazySets.:⪯
— Method⪯(u::AbstractVector, v::AbstractVector)
Compare two 2D vectors by their direction.
Input
u
– first 2D directionv
– second 2D direction
Output
true
iff $\arg(u) [2π] ≤ \arg(v) [2π]$.
Notes
The argument is measured in counter-clockwise fashion, with the 0 being the direction (1, 0).
Algorithm
The implementation checks the quadrant of each direction, and compares directions using the right-hand rule. In particular, this method does not use the arctangent.
LazySets._leq_trig
— Method_leq_trig(u::AbstractVector{N}, v::AbstractVector{N}) where {N<:AbstractFloat}
Compare two 2D vectors by their direction.
Input
u
– first 2D directionv
– second 2D direction
Output
true
iff $\arg(u) [2π] ≤ \arg(v) [2π]$.
Notes
The argument is measured in counter-clockwise fashion, with the 0 being the direction (1, 0).
Algorithm
The implementation uses the arctangent function with sign, atan
, which for two arguments implements the atan2
function.
LazySets.quadrant
— Methodquadrant(w::AbstractVector)
Compute the quadrant where the direction w
belongs.
Input
w
– direction
Output
An integer from 0 to 3, with the following convention:
^
1 | 0
---+-->
2 | 3
Algorithm
The idea is to encode the following logic function: $11 ↦ 0, 01 ↦ 1, 00 ↦ 2, 10 ↦ 3$, according to the convention above.
This function is inspired from AGPX's answer in: Sort points in clockwise order?