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

Compute the shortest Euclidean path between two points inside a simple polygon. More...

#include <geom_algorithms.H>

Collaboration diagram for Aleph::ShortestPathInPolygon:
[legend]

Classes

struct  ITri
 

Public Member Functions

DynList< Pointoperator() (const Polygon &polygon, const Point &source, const Point &target) const
 Compute the shortest path between two points in a simple polygon.
 

Static Private Member Functions

static size_t find_index (const Array< Point > &pts, const Point &p)
 Match a Point from a Triangle to an index in pts (exact comparison).
 
static Array< ITribuild_tris (const Array< Point > &pts, const DynList< Triangle > &tl)
 Build indexed triangulation with adjacency.
 
static bool point_in_triangle (const Array< Point > &pts, const ITri &t, const Point &p)
 Point-in-triangle test.
 
static size_t find_tri (const Array< Point > &pts, const Array< ITri > &tris, const Point &p)
 Find a triangle containing point p.
 
static Array< size_t > find_sleeve (const Array< ITri > &tris, const size_t src, const size_t dst)
 BFS on dual graph → sleeve.
 
static Geom_Number cross (const Point &a, const Point &b, const Point &c)
 Cross product (b-a) x (c-a).
 

Static Private Attributes

static constexpr size_t NONE = ~static_cast<size_t>(0)
 

Detailed Description

Compute the shortest Euclidean path between two points inside a simple polygon.

Uses ear-cutting triangulation, BFS on the dual graph to find the triangle sleeve, and the Lee-Preparata funnel algorithm.

Complexity

Example
Polygon poly;
poly.add_vertex(Point(0,0)); poly.add_vertex(Point(5,0));
poly.add_vertex(Point(5,5)); poly.add_vertex(Point(0,5));
poly.close();
auto path = sp(poly, Point(1,1), Point(4,4));
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
void close()
Close the polygon.
Definition polygon.H:840
Compute the shortest Euclidean path between two points inside a simple polygon.
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 9940 of file geom_algorithms.H.

Member Function Documentation

◆ build_tris()

◆ cross()

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

Cross product (b-a) x (c-a).

Definition at line 10123 of file geom_algorithms.H.

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

Referenced by operator()().

◆ find_index()

static size_t Aleph::ShortestPathInPolygon::find_index ( const Array< Point > &  pts,
const Point p 
)
inlinestaticprivate

Match a Point from a Triangle to an index in pts (exact comparison).

Definition at line 9951 of file geom_algorithms.H.

References Aleph::divide_and_conquer_partition_dp(), and NONE.

Referenced by build_tris().

◆ find_sleeve()

static Array< size_t > Aleph::ShortestPathInPolygon::find_sleeve ( const Array< ITri > &  tris,
const size_t  src,
const size_t  dst 
)
inlinestaticprivate

◆ find_tri()

static size_t Aleph::ShortestPathInPolygon::find_tri ( const Array< Point > &  pts,
const Array< ITri > &  tris,
const Point p 
)
inlinestaticprivate

Find a triangle containing point p.

Definition at line 10063 of file geom_algorithms.H.

References Aleph::divide_and_conquer_partition_dp(), NONE, and point_in_triangle().

Referenced by operator()().

◆ operator()()

DynList< Point > Aleph::ShortestPathInPolygon::operator() ( const Polygon polygon,
const Point source,
const Point target 
) const
inline

Compute the shortest path between two points in a simple polygon.

Parameters
polygonA closed simple polygon.
sourceStart point (inside or on the boundary).
targetEnd point (inside or on the boundary).
Returns
Ordered sequence of waypoints from source to target.

Definition at line 10140 of file geom_algorithms.H.

References ah_domain_error_if, Aleph::and, Aleph::Array< T >::append(), Aleph::DynList< T >::append(), build_tris(), Aleph::PointInPolygonWinding::contains(), cross(), Aleph::divide_and_conquer_partition_dp(), find_sleeve(), find_tri(), Aleph::DynList< T >::get_last(), Aleph::Polygon::Segment_Iterator::has_curr(), Aleph::Dlink::Iterator::has_curr(), Aleph::Segment::intersects_properly_with(), Aleph::Polygon::is_closed(), NONE, Aleph::Polygon::size(), and Aleph::Array< T >::size().

◆ point_in_triangle()

static bool Aleph::ShortestPathInPolygon::point_in_triangle ( const Array< Point > &  pts,
const ITri t,
const Point p 
)
inlinestaticprivate

Member Data Documentation

◆ NONE

constexpr size_t Aleph::ShortestPathInPolygon::NONE = ~static_cast<size_t>(0)
staticconstexprprivate

Definition at line 9942 of file geom_algorithms.H.

Referenced by build_tris(), find_index(), find_sleeve(), find_tri(), and operator()().


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