Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::MinkowskiSumConvex Class Reference

Exact Minkowski sum of two closed convex polygons. More...

#include <geom_algorithms.H>

Public Member Functions

Polygon operator() (const Polygon &P, const Polygon &Q) const
 Compute the Minkowski sum of two convex polygons.
 

Static Private Member Functions

static Array< Pointextract_vertices (const Polygon &poly)
 
static Geom_Number signed_double_area (const Array< Point > &v)
 
static bool is_convex (const Array< Point > &verts)
 
static Array< Pointnormalize (Array< Point > v)
 Ensure CCW and rotate so that the bottom-most vertex is first.
 
static Point edge_vec (const Array< Point > &v, const size_t i)
 
static Geom_Number cross (const Point &a, const Point &b)
 

Detailed Description

Exact Minkowski sum of two closed convex polygons.

The Minkowski sum P ⊕ Q of two convex polygons P and Q is a convex polygon whose vertices are sums of vertex pairs from P and Q. The algorithm merges the edge vectors of both polygons sorted by polar angle in O(n + m).

Requirements

  • Both polygons must be closed and convex with ≥ 3 vertices.
  • Vertices may be CW or CCW (normalized internally to CCW).

Complexity

  • Time: O(n + m)
  • Space: O(n + m)
Example
P.add_vertex(Point(0,0)); P.add_vertex(Point(1,0)); P.add_vertex(Point(0,1));
P.close();
Q.add_vertex(Point(0,0)); Q.add_vertex(Point(2,0)); Q.add_vertex(Point(0,2));
Q.close();
Polygon R = ms(P, Q);
Exact Minkowski sum of two closed convex polygons.
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:229
A general (irregular) 2D polygon defined by a sequence of vertices.
Definition polygon.H:246
void add_vertex(const Point &point)
Add a vertex to the polygon.
Definition polygon.H:677
pair< size_t, string > P
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.

Definition at line 7391 of file geom_algorithms.H.

Member Function Documentation

◆ cross()

static Geom_Number Aleph::MinkowskiSumConvex::cross ( const Point a,
const Point b 
)
inlinestaticprivate

Definition at line 7437 of file geom_algorithms.H.

References Aleph::Point::get_x(), and Aleph::Point::get_y().

Referenced by operator()().

◆ edge_vec()

static Point Aleph::MinkowskiSumConvex::edge_vec ( const Array< Point > &  v,
const size_t  i 
)
inlinestaticprivate

Definition at line 7431 of file geom_algorithms.H.

References Aleph::Array< T >::size().

Referenced by operator()().

◆ extract_vertices()

static Array< Point > Aleph::MinkowskiSumConvex::extract_vertices ( const Polygon poly)
inlinestaticprivate

Definition at line 7394 of file geom_algorithms.H.

References Aleph::GeomPolygonUtils::extract_vertices().

Referenced by operator()().

◆ is_convex()

static bool Aleph::MinkowskiSumConvex::is_convex ( const Array< Point > &  verts)
inlinestaticprivate

◆ normalize()

static Array< Point > Aleph::MinkowskiSumConvex::normalize ( Array< Point v)
inlinestaticprivate

Ensure CCW and rotate so that the bottom-most vertex is first.

Definition at line 7412 of file geom_algorithms.H.

References Aleph::and, Aleph::Array< T >::append(), Aleph::divide_and_conquer_partition_dp(), Aleph::GeomPolygonUtils::ensure_ccw(), Aleph::Array< T >::reserve(), and Aleph::Array< T >::size().

Referenced by operator()().

◆ operator()()

Polygon Aleph::MinkowskiSumConvex::operator() ( const Polygon P,
const Polygon Q 
) const
inline

Compute the Minkowski sum of two convex polygons.

Parameters
PFirst convex polygon.
QSecond convex polygon.
Returns
Convex polygon P ⊕ Q.
Exceptions
domain_errorif either polygon is not closed, has < 3 vertices, or is not convex.

Definition at line 7453 of file geom_algorithms.H.

References Aleph::Polygon::add_vertex(), ah_domain_error_if, Aleph::and, Aleph::Array< T >::append(), cross(), Aleph::divide_and_conquer_partition_dp(), edge_vec(), Aleph::eq(), extract_vertices(), is_convex(), normalize(), Aleph::Array< T >::reserve(), and Aleph::Array< T >::size().

◆ signed_double_area()

static Geom_Number Aleph::MinkowskiSumConvex::signed_double_area ( const Array< Point > &  v)
inlinestaticprivate

Definition at line 7399 of file geom_algorithms.H.

References Aleph::GeomPolygonUtils::signed_double_area().


The documentation for this class was generated from the following file: