Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
o2scl::pinside Class Reference

Test line intersection and point inside polygon. More...

#include <pinside.h>

Classes

struct  line
 Internal line definition for pinside. More...
 
struct  point
 Internal point definition for pinside. More...
 

Public Types

typedef boost::numeric::ublas::vector< double > ubvector
 

Public Member Functions

int intersect (double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
 Determine if two line segments intersect. More...
 
int inside (double x, double y, const ubvector &xa, const ubvector &ya)
 Determine if point (x,y) is inside a polygon. More...
 
template<class vec_t >
int inside (double x, double y, size_t n, const vec_t &xa, const vec_t &ya)
 Determine if point (x,y) is inside a polygon. More...
 
int test (test_mgr &t)
 Perform some simple testing.
 

Protected Member Functions

int intersect (line P, line Q)
 Test if line segments P and Q intersect.
 
int inside (point t, point p[], int N)
 Test if point t is inside polygon p of size N.
 

Detailed Description

This is a fast and dirty implementation of the point inside polygon test from Jerome L. Lewis, SIGSCE Bulletin, 34 (2002) 81.

Note that an error in that article ("count-" should have been "count--") has been corrected here.

Idea for Future:
The inside() functions actually copy the points twice. This can be made more efficient.

Definition at line 70 of file pinside.h.

Member Function Documentation

◆ inside() [1/2]

int o2scl::pinside::inside ( double  x,
double  y,
const ubvector xa,
const ubvector ya 
)

This returns 1 if the point (x,y) is inside the polygon defined by xa and ya, and 0 otherwise.

Note that if the point (x,y) is exactly on the polygon, then the result of this function is not well-defined and it will return either 0 or 1.

◆ inside() [2/2]

template<class vec_t >
int o2scl::pinside::inside ( double  x,
double  y,
size_t  n,
const vec_t &  xa,
const vec_t &  ya 
)
inline

This returns 1 if the point (x,y) is inside the polygon defined by xa and ya, and 0 otherwise.

The parameter n should be the number of polygon points specified in vectors xa and ya.

Note that if the point (x,y) is exactly on the polygon, then the result of this function is not well-defined and it will return either 0 or 1.

Definition at line 138 of file pinside.h.

◆ intersect()

int o2scl::pinside::intersect ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3,
double  x4,
double  y4 
)
inline

The function returns 1 if the line segment determined by the endpoints $ (x_1,y_1) $ and $ (x_2,y_2) $ and the line segment determined by the endpoints $ (x_3,y_3) $ and $ (x_4,y_4) $ intersect, and 0 otherwise.

Definition at line 106 of file pinside.h.


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

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).