-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgeom_poly.h
54 lines (44 loc) · 2.51 KB
/
geom_poly.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef GEOM_POLY_H_INCLUDED
#define GEOM_POLY_H_INCLUDED
float geom_polygon_area2f(unsigned int nv, const float *v);
double geom_polygon_area2d(unsigned int nv, const double *v);
// Returns 1 if inside, 0 otherwise
int geom_polygon_inside2f(unsigned int nv, const float *v, const float p[2]);
int geom_polygon_inside2d(unsigned int nv, const double *v, const double p[2]);
// Returns a normal vector for a point on (near) the polygon's boundary
// For points far from the boundary, no guarantee is made about how reasonable
// the result is.
void geom_polygon_normal2f(unsigned int nv, const float *v, const float p[2], float n[2]);
void geom_polygon_normal2d(unsigned int nv, const double *v, const double p[2], double n[2]);
// A convex region defined as the intersection of n halfspaces.
// Each halfspace is defined by:
// p[3*i+0]*r[0] + p[3*i+1]*r[1] <= p[3*i+2]
// Therefore, treating p as a column major matrix with three rows
// and np columns, the convex region is defined by:
// |p^T . r|_inf <= 0
int geom_convex_inside2f(unsigned int np, const float *p, const float r[2]);
int geom_convex_inside2d(unsigned int np, const double *p, const double r[2]);
void geom_convex_normal2f(unsigned int np, const float *p, const float r[2], float n[2]);
void geom_convex_normal2d(unsigned int np, const double *p, const double r[2], double n[2]);
// All the above considerations are analogous in 3D.
int geom_convex_inside3f(unsigned int np, const float *p, const float r[3]);
int geom_convex_inside3d(unsigned int np, const double *p, const double r[3]);
void geom_convex_normal3f(unsigned int np, const float *p, const float r[3], float n[3]);
void geom_convex_normal3d(unsigned int np, const double *p, const double r[3], double n[3]);
// Computes the most extremal point r in the direction dir
// wksp can be NULL, or size 18*np+21
int geom_convex_bound3d(unsigned int np, const double *p, const double dir[3], double r[3], double *wksp);
// An n-sided polygon always has n-2 triangles in its triangulation.
int geom_polygon_triangulate2d(
unsigned int nv, const double *v, // the polygon
unsigned int *t // length 3*(n-2), stores the triangle as triples of vertex indices into v
);
int geom_convex_polygon_intersection2d(
unsigned int nP, // >= 3
const double *P,
unsigned int nQ, // >= 3
const double *Q,
unsigned int *ni, // on input, size of Pi (>= nP+nQ), on output, numer of points in Pi
double *Pi // output intersection polygon
);
#endif // GEOM_POLY_H_INCLUDED