#include <stdint.h>
Go to the source code of this file.
Classes | |
struct | r2d_rvec2 |
Vector struct. More... | |
struct | r2d_dvec2 |
Integer vector struct for grid indexing. More... | |
struct | r2d_plane |
A plane. More... | |
struct | r2d_vertex |
A doubly-linked vertex. More... | |
struct | r2d_poly |
A polygon. More... | |
Macros | |
#define | R2D_MAX_VERTS 256 |
#define | R2D_NUM_MOMENTS(order) ((order+1)*(order+2)/2) |
Integrate a polynomial density over a polygon using simplicial decomposition. Uses the fast recursive method of Koehl (2012) to carry out the integration. More... | |
Typedefs | |
typedef double | r2d_real |
Real type specifying the precision to be used in calculations. More... | |
typedef int32_t | r2d_int |
Integer types used for indexing. More... | |
typedef int64_t | r2d_long |
Functions | |
void | r2d_clip (r2d_poly *poly, r2d_plane *planes, r2d_int nplanes) |
Clip a polygon against an arbitrary number of clip planes (find its intersection with a set of half-spaces). More... | |
void | r2d_split (r2d_poly *inpolys, r2d_int npolys, r2d_plane plane, r2d_poly *out_pos, r2d_poly *out_neg) |
Splits a list of polygons across a single plane. More... | |
void | r2d_reduce (r2d_poly *poly, r2d_real *moments, r2d_int polyorder) |
r2d_int | r2d_is_good (r2d_poly *poly) |
Checks a polygon to see if all vertices have two valid edges, that all vertices are pointed to by two other vertices, and that there are no vertices that point to themselves. More... | |
r2d_rvec2 | r2d_poly_center (r2d_poly *poly) |
Calculates a center of a polygon. More... | |
void | r2d_shift_moments (r2d_real *moments, r2d_int polyorder, r2d_rvec2 vc) |
Adjust moments according to the shift of polygon vertices to the origin. More... | |
r2d_real | r2d_orient (r2d_rvec2 pa, r2d_rvec2 pb, r2d_rvec2 pc) |
Get the signed volume of the triangle defined by the input vertices. More... | |
void | r2d_print (r2d_poly *poly) |
Prints the vertices and connectivity of a polygon. For debugging. More... | |
void | r2d_rotate (r2d_poly *poly, r2d_real theta) |
Rotate a polygon about the origin. More... | |
void | r2d_translate (r2d_poly *poly, r2d_rvec2 shift) |
Translate a polygon. More... | |
void | r2d_scale (r2d_poly *poly, r2d_real scale) |
Scale a polygon. More... | |
void | r2d_shear (r2d_poly *poly, r2d_real shear, r2d_int axb, r2d_int axs) |
Shear a polygon. Each vertex undergoes the transformation pos.xy[axb] += shear*pos.xy[axs] . More... | |
void | r2d_affine (r2d_poly *poly, r2d_real mat[3][3]) |
Apply a general affine transformation to a polygon. More... | |
void | r2d_init_box (r2d_poly *poly, r2d_rvec2 *rbounds) |
Initialize a polygon as an axis-aligned box. More... | |
void | r2d_init_poly (r2d_poly *poly, r2d_rvec2 *vertices, r2d_int numverts) |
Initialize a (simply-connected) general polygon from a list of vertices. Can use r2d_is_good to check that the output is valid. More... | |
void | r2d_box_faces_from_verts (r2d_plane *faces, r2d_rvec2 *rbounds) |
Get four faces (unit normals and distances to the origin) from a two-vertex description of an axis-aligned box. More... | |
void | r2d_poly_faces_from_verts (r2d_plane *faces, r2d_rvec2 *vertices, r2d_int numverts) |
Get all faces (unit normals and distances to the origin) from a general boundary description of a polygon. More... | |
Macro Definition Documentation
◆ R2D_MAX_VERTS
#define R2D_MAX_VERTS 256 |
◆ R2D_NUM_MOMENTS
#define R2D_NUM_MOMENTS | ( | order | ) | ((order+1)*(order+2)/2) |
Integrate a polynomial density over a polygon using simplicial decomposition. Uses the fast recursive method of Koehl (2012) to carry out the integration.
- Parameters
-
[in] poly The polygon over which to integrate. [in] polyorder Order of the polynomial density field. 0 for constant (1 moment), 1 for linear (4 moments), 2 for quadratic (10 moments), etc. [in,out] moments Array to be filled with the integration results, up to the specified polyorder
. Must be at least(polyorder+1)*(polyorder+2)/2
long. A conventient macro,R2D_NUM_MOMENTS()
is provided to compute the number of moments for a given order. Order of moments is row-major, i.e.1
,x
,y
,x^2
,x*y
,y^2
,x^3
,x^2*y
...
Typedef Documentation
◆ r2d_int
typedef int32_t r2d_int |
Integer types used for indexing.
◆ r2d_long
typedef int64_t r2d_long |
◆ r2d_real
typedef double r2d_real |
Real type specifying the precision to be used in calculations.
Default is double
. float
precision is enabled by compiling with -DSINGLE_PRECISION
.
Function Documentation
◆ r2d_affine()
Apply a general affine transformation to a polygon.
- Parameters
-
[in,out] poly The polygon to transform. [in] mat The 3x3 homogeneous transformation matrix by which to transform the vertices of the polygon.
◆ r2d_box_faces_from_verts()
Get four faces (unit normals and distances to the origin) from a two-vertex description of an axis-aligned box.
- Parameters
-
[out] faces Array of four planes defining the faces of the box. [in] rbounds Array of two vectors defining the bounds of the axis-aligned box
◆ r2d_clip()
Clip a polygon against an arbitrary number of clip planes (find its intersection with a set of half-spaces).
- Parameters
-
[in,out] poly The polygon to be clipped. [in] planes An array of planes against which to clip this polygon. [in] nplanes The number of planes in the input array.
◆ r2d_init_box()
Initialize a polygon as an axis-aligned box.
- Parameters
-
[out] poly The polygon to initialize. [in] rbounds An array of two vectors, giving the lower and upper corners of the box.
◆ r2d_init_poly()
Initialize a (simply-connected) general polygon from a list of vertices. Can use r2d_is_good
to check that the output is valid.
- Parameters
-
[out] poly The polygon to initialize. [in] vertices Array of length numverts
giving the vertices of the input polygon, in counterclockwise order.[in] numverts Number of vertices in the input polygon.
◆ r2d_is_good()
Checks a polygon to see if all vertices have two valid edges, that all vertices are pointed to by two other vertices, and that there are no vertices that point to themselves.
- Parameters
-
[in] poly The polygon to check.
- Returns
- 1 if the polygon is good, 0 if not.
◆ r2d_orient()
Get the signed volume of the triangle defined by the input vertices.
- Parameters
-
[in] pa,pb,pc Vertices defining a triangle from which to calculate an area.
- Returns
- The signed volume of the input triangle.
◆ r2d_poly_center()
Calculates a center of a polygon.
- Parameters
-
[in] poly The polygon to check.
- Returns
- coordinates of a polygon center.
◆ r2d_poly_faces_from_verts()
Get all faces (unit normals and distances to the origin) from a general boundary description of a polygon.
- Parameters
-
[out] faces Array of planes of length numverts
defining the faces of the polygon.[in] vertices Array of length numverts
giving the vertices of the input polygon, in counterclockwise order.[in] numverts Number of vertices in the input polygon.
◆ r2d_print()
void r2d_print | ( | r2d_poly * | poly | ) |
Prints the vertices and connectivity of a polygon. For debugging.
- Parameters
-
[in] poly The polygon to print.
◆ r2d_reduce()
◆ r2d_rotate()
Rotate a polygon about the origin.
- Parameters
-
[in,out] poly The polygon to rotate. [in] theta The angle, in radians, by which to rotate the polygon.
◆ r2d_scale()
Scale a polygon.
- Parameters
-
[in,out] poly The polygon to scale. [in] shift The factor by which to scale the polygon.
◆ r2d_shear()
Shear a polygon. Each vertex undergoes the transformation pos.xy[axb] += shear*pos.xy[axs]
.
- Parameters
-
[in,out] poly The polygon to shear. [in] shear The factor by which to shear the polygon. [in] axb The axis (0 or 1 corresponding to x or y) along which to shear the polygon. [in] axs The axis (0 or 1 corresponding to x or y) across which to shear the polygon.
◆ r2d_shift_moments()
Adjust moments according to the shift of polygon vertices to the origin.
- Parameters
-
[in,out] moments The moments of the shifted polygon. [in] polyorder Order of the polygon. [in] vc Coordinates of the polygon center, which are used to shift the polygon.
◆ r2d_split()
void r2d_split | ( | r2d_poly * | inpolys, |
r2d_int | npolys, | ||
r2d_plane | plane, | ||
r2d_poly * | out_pos, | ||
r2d_poly * | out_neg | ||
) |
Splits a list of polygons across a single plane.
- Parameters
-
[in] inpolys Array input polyhedra to be split [in] npolys The number of input polygons [in] plane The plane about which to split the input polys [out] out_pos The output array of fragments on the positive side of the clip plane. Must be at least npolys long. out_pos[i] and out_neg[i] correspond to inpolys[i], where out_neg[i].nverts or out.pos[i].nverts are set to zero if the poly lies entirely in the positive or negative side of the plane, respectively. [out] out_neg The output array of fragments on the negitive side of the clip plane. Must be at least npolys long.