Polygons (AbstractPolygon)

A polygon is a two-dimensional polytope.

LazySets.AbstractPolygonType
AbstractPolygon{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 representation
  • tovrep(::AbstractPolygon) – transform into vertex representation

The subtypes of AbstractPolygon (including abstract interfaces):

julia> subtypes(AbstractPolygon)
2-element Vector{Any}:
 AbstractHPolygon
 VPolygon
source

This interface requires to implement the following functions:

LazySets.tohrepMethod
tohrep(P::AbstractPolygon)

Convert a convex polygon to constraint representation.

Input

  • P – convex polygon

Output

A polygon in constraint representation.

source
LazySets.tovrepMethod
tovrep(P::AbstractPolygon)

Convert a convex polygon to vertex representation.

Input

  • P – convex polygon

Output

A polygon in vertex representation.

source

This interface defines the following functions:

LazySets.API.dimMethod
dim(P::AbstractPolygon)

Return the ambient dimension of a convex polygon.

Input

  • P – convex polygon

Output

The ambient dimension of the polygon, which is 2.

source
LazySets.API.volumeMethod
volume(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.

source

The following helper functions are used for sorting directions:

LazySets.jump2piFunction
jump2pi(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
source
LazySets.:⪯Method
⪯(u::AbstractVector, v::AbstractVector)

Compare two 2D vectors by their direction.

Input

  • u – first 2D direction
  • v – 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.

source
LazySets._leq_trigMethod
_leq_trig(u::AbstractVector{N}, v::AbstractVector{N}) where {N<:AbstractFloat}

Compare two 2D vectors by their direction.

Input

  • u – first 2D direction
  • v – 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.

source
LazySets.quadrantMethod
quadrant(w::AbstractVector{N}) where {N}

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?

source

Implementations