BRL-CAD
polygon.h
Go to the documentation of this file.
1 /* P O L Y G O N . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 /*----------------------------------------------------------------------*/
22 /* @file polygon.h */
23 /** @addtogroup poly */
24 /** @{ */
25 
26 /**
27  * @brief Functions for working with polygons
28  */
29 
30 #ifndef BN_POLYGON_H
31 #define BN_POLYGON_H
32 
33 #include "common.h"
34 #include "vmath.h"
35 #include "bn/defines.h"
36 #include "bn/tol.h"
37 
39 
40 /**
41  * @brief
42  * Calculate the interior area of a polygon.
43  *
44  * If npts > 4, Greens Theorem is used. The polygon mustn't
45  * be self-intersecting.
46  *
47  * @param[out] area The interior area of the polygon
48  * @param[in] npts Number of point_ts, stored in pts
49  * @param[in] pts All points of the polygon, sorted counter-clockwise.
50  * The array mustn't contain duplicated points.
51  *
52  * @return 0 if calculation was successful
53  * @return 1 if calculation failed, e.g. because one parameter is a NULL-pointer
54  */
55 BN_EXPORT extern int bn_polygon_area(fastf_t *area, size_t npts, const point_t *pts);
56 
57 
58 /**
59  * @brief
60  * Calculate the centroid of a non self-intersecting polygon
61  *
62  * @param[out] cent The centroid of the polygon
63  * @param[in] npts Number of point_ts, stored in pts
64  * @param[in] pts all points of the polygon, sorted counter-clockwise.
65  * The array mustn't contain duplicated points.
66  *
67  * @return 0 if calculation was successful
68  * @return 1 if calculation failed, e.g. because one in-parameter is a NULL-pointer
69  */
70 BN_EXPORT extern int bn_polygon_centroid(point_t *cent, size_t npts, const point_t *pts);
71 
72 
73 /**
74  * @brief
75  * Calculate for an array of plane_eqs, which build a polyhedron, the
76  * point_t's for each face.
77  *
78  * @param[out] npts Array, which stores for every face the number of
79  * point_ts, added to pts. Needs to be allocated with npts[neqs] already.
80  * @param[out] pts 2D-array which stores the point_ts for every
81  * face. The array needs to be allocated with pts[neqs][neqs-1] already.
82  * @param[in] neqs Number of plane_ts, stored in eqs
83  * @param[in] eqs Array, that contains the plane equations, which
84  * build the polyhedron
85  *
86  * @return 0 if calculation was successful
87  * @return 1 if calculation failed, e.g. because one parameter is a NULL-Pointer
88  */
89 BN_EXPORT extern int bn_polygon_mk_pts_planes(size_t *npts, point_t **pts, size_t neqs, const plane_t *eqs);
90 
91 
92 /**
93  * @brief
94  * Sort an array of point_ts, building a convex polygon, counter-clockwise
95  *
96  *@param[in] npts Number of points, pts contains
97  *@param pts Array of point_ts, building a convex polygon. Duplicated points
98  *aren't allowed. The points in the array will be sorted counter-clockwise.
99  *@param[in] cmp Plane equation of the polygon
100  *
101  *@return 0 if calculation was successful
102  *@return 1 if calculation failed, e.g. because pts is a NULL-pointer
103  */
104 BN_EXPORT extern int bn_polygon_sort_ccw(size_t npts, point_t *pts, plane_t cmp);
105 
107 
108 #endif /* BN_POLYGON_H */
109 /** @} */
110 /*
111  * Local Variables:
112  * mode: C
113  * tab-width: 8
114  * indent-tabs-mode: t
115  * c-file-style: "stroustrup"
116  * End:
117  * ex: shiftwidth=4 tabstop=8
118  */
Header file for the BRL-CAD common definitions.
int bn_polygon_mk_pts_planes(size_t *npts, point_t **pts, size_t neqs, const plane_t *eqs)
Calculate for an array of plane_eqs, which build a polyhedron, the point_t's for each face...
Definition: polygon.c:137
#define __BEGIN_DECLS
Definition: common.h:73
int bn_polygon_area(fastf_t *area, size_t npts, const point_t *pts)
Functions for working with polygons.
Definition: polygon.c:28
int bn_polygon_centroid(point_t *cent, size_t npts, const point_t *pts)
Calculate the centroid of a non self-intersecting polygon.
Definition: polygon.c:72
#define __END_DECLS
Definition: common.h:74
double fastf_t
Definition: defines.h:300
int bn_polygon_sort_ccw(size_t npts, point_t *pts, plane_t cmp)
Sort an array of point_ts, building a convex polygon, counter-clockwise.
Definition: polygon.c:182