|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
QuickHull convex hull algorithm. More...
#include <geom_algorithms.H>
Public Member Functions | |
| Polygon | operator() (const DynList< Point > &point_set) const |
| Compute the convex hull of a point set. | |
Static Private Member Functions | |
| static Point | get_farthest_point (const DynList< Point > &point_set, const Segment &s) |
Return the point in point_set farthest from segment s. | |
| static std::pair< DynList< Point >, DynList< Point > > | get_right_points (DynList< Point > &point_set, const Point &a, const Point &b, const Point &c) |
| Partition points to the right of edges (a,c) and (c,b). | |
| static DynList< Point > | quick_hull (DynList< Point > &point_set, const Point &a, const Point &b) |
| Recursive QuickHull step for a directed edge (a,b). | |
| static std::pair< Point, Point > | search_extremes (const DynList< Point > &point_set) |
| Find leftmost and rightmost points by x coordinate. | |
| static std::pair< DynList< Point >, DynList< Point > > | partition (const DynList< Point > &point_set, const Point &a, const Point &b) |
| Split points by the line through directed segment (a,b). | |
QuickHull convex hull algorithm.
Computes the convex hull using a divide-and-conquer approach similar to QuickSort. Recursively finds the farthest point from a line and partitions the remaining points.
Definition at line 5331 of file geom_algorithms.H.
|
inlinestaticprivate |
Return the point in point_set farthest from segment s.
This is the standard QuickHull selection step: pick the point with maximum perpendicular distance to the current hull edge. In this implementation we compare the absolute value of the parallelogram area |area_of_parallelogram(a,b,p)| which is proportional to that distance (the segment length |ab| is constant for all candidates), avoiding square-roots.
| point_set | Candidate points. |
| s | Base segment (a,b) used as reference. |
point_set maximizing |area_of_parallelogram|.point_set is empty, the returned point is default-constructed. Definition at line 5349 of file geom_algorithms.H.
References Aleph::area_of_parallelogram(), Aleph::divide_and_conquer_partition_dp(), Aleph::Segment::get_src_point(), Aleph::Segment::get_tgt_point(), and Aleph::HTList::Iterator::has_curr().
Referenced by quick_hull().
|
inlinestaticprivate |
Partition points to the right of edges (a,c) and (c,b).
Given a triangle (a,c,b) where c is the farthest point from segment (a,b), QuickHull must recursively process the points on the outside (i.e. the same side as the hull) of the sub-edges (a,c) and (c,b).
This function consumes point_set and splits its points into two sets:
ret.first: points strictly on the right side of the directed edge (a,c), excluding endpoints a and c.ret.second: points strictly on the right side of the directed edge (c,b), excluding endpoints c and b.“Right side” is detected with the signed area predicate: area_of_parallelogram(u,v,p) < 0.
| [in,out] | point_set | Input candidate points. This list is emptied by repeated remove_first(). |
| a | First endpoint of the current hull edge. | |
| b | Second endpoint of the current hull edge. | |
| c | Farthest point from edge (a,b) defining the split. |
(S_ac, S_cb) as described above. Definition at line 5402 of file geom_algorithms.H.
References Aleph::and, Aleph::area_of_parallelogram(), and Aleph::divide_and_conquer_partition_dp().
Referenced by quick_hull().
Compute the convex hull of a point set.
| point_set | The input points. |
Definition at line 5514 of file geom_algorithms.H.
References Aleph::DynList< T >::append(), Aleph::divide_and_conquer_partition_dp(), Aleph::HTList::Iterator::has_curr(), partition(), quick_hull(), and search_extremes().
|
inlinestaticprivate |
Split points by the line through directed segment (a,b).
(right, left_or_collinear) where:right: points with area_of_parallelogram(a,b,p) < 0.left_or_collinear: all remaining points. Definition at line 5494 of file geom_algorithms.H.
References Aleph::DynList< T >::append(), Aleph::area_of_parallelogram(), Aleph::divide_and_conquer_partition_dp(), and Aleph::HTList::Iterator::has_curr().
Referenced by operator()().
|
inlinestaticprivate |
Recursive QuickHull step for a directed edge (a,b).
Assumes point_set contains points on the outside of the directed edge (a,b) (in this implementation: points to the right of (a,b)).
| [in,out] | point_set | Candidate points; may be consumed by recursion. |
| a | Edge source. | |
| b | Edge target. |
point_set is empty, it returns an empty list. Definition at line 5437 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), get_farthest_point(), get_right_points(), and quick_hull().
Referenced by operator()(), and quick_hull().
|
inlinestaticprivate |
Find leftmost and rightmost points by x coordinate.
| point_set | Non-empty input set. |
(leftmost, rightmost) where ties are broken by first occurrence during traversal. Definition at line 5462 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::DynList< T >::Iterator::get_curr(), Aleph::Point::get_x(), Aleph::HTList::Iterator::has_curr(), Aleph::HTList::Iterator::next(), and Aleph::HTList::Iterator::next_ne().
Referenced by operator()().