g2d.h
Go to the documentation of this file.
1 /* Copyright (C) 2013-2016, The Regents of The University of Michigan.
2 All rights reserved.
3 
4 This software was developed in the APRIL Robotics Lab under the
5 direction of Edwin Olson, ebolson@umich.edu. This software may be
6 available under alternative licensing terms; contact the address above.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 The views and conclusions contained in the software and documentation are those
29 of the authors and should not be interpreted as representing official policies,
30 either expressed or implied, of the Regents of The University of Michigan.
31 */
32 
33 #ifndef _G2D_H
34 #define _G2D_H
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include "common/zarray.h"
41 
42 // This library tries to avoid needless proliferation of types.
43 //
44 // A point is a double[2]. (Note that when passing a double[2] as an
45 // argument, it is passed by pointer, not by value.)
46 //
47 // A polygon is a zarray_t of double[2]. (Note that in this case, the
48 // zarray contains the actual vertex data, and not merely a pointer to
49 // some other data. IMPORTANT: A polygon must be specified in CCW
50 // order. It is implicitly closed (do not list the same point at the
51 // beginning at the end.
52 //
53 // Where sensible, it is assumed that objects should be allocated
54 // sparingly; consequently "init" style methods, rather than "create"
55 // methods are used.
56 
58 // Lines
59 
60 typedef struct
61 {
62  // Internal representation: a point that the line goes through (p) and
63  // the direction of the line (u).
64  double p[2];
65  double u[2]; // always a unit vector
66 } g2d_line_t;
67 
68 // initialize a line object.
69 void g2d_line_init_from_points(g2d_line_t *line, const double p0[2], const double p1[2]);
70 
71 // The line defines a one-dimensional coordinate system whose origin
72 // is p. Where is q? (If q is not on the line, the point nearest q is
73 // returned.
74 double g2d_line_get_coordinate(const g2d_line_t *line, const double q[2]);
75 
76 // Intersect two lines. The intersection, if it exists, is written to
77 // p (if not NULL), and 1 is returned. Else, zero is returned.
78 int g2d_line_intersect_line(const g2d_line_t *linea, const g2d_line_t *lineb, double *p);
79 
81 // Line Segments. line.p is always one endpoint; p1 is the other
82 // endpoint.
83 typedef struct
84 {
86  double p1[2];
88 
89 void g2d_line_segment_init_from_points(g2d_line_segment_t *seg, const double p0[2], const double p1[2]);
90 
91 // Intersect two segments. The intersection, if it exists, is written
92 // to p (if not NULL), and 1 is returned. Else, zero is returned.
93 int g2d_line_segment_intersect_segment(const g2d_line_segment_t *sega, const g2d_line_segment_t *segb, double *p);
94 
95 void g2d_line_segment_closest_point(const g2d_line_segment_t *seg, const double *q, double *p);
96 double g2d_line_segment_closest_point_distance(const g2d_line_segment_t *seg, const double *q);
97 
99 // Polygons
100 
101 zarray_t *g2d_polygon_create_data(double v[][2], int sz);
102 
104 
106 
107 void g2d_polygon_add(zarray_t *poly, double v[2]);
108 
109 // Takes a polygon in either CW or CCW and modifies it (if necessary)
110 // to be CCW.
111 void g2d_polygon_make_ccw(zarray_t *poly);
112 
113 // Return 1 if point q lies within poly.
114 int g2d_polygon_contains_point(const zarray_t *poly, double q[2]);
115 
116 // Do the edges of the polygons cross? (Does not test for containment).
117 int g2d_polygon_intersects_polygon(const zarray_t *polya, const zarray_t *polyb);
118 
119 // Does polya completely contain polyb?
120 int g2d_polygon_contains_polygon(const zarray_t *polya, const zarray_t *polyb);
121 
122 // Is there some point which is in both polya and polyb?
123 int g2d_polygon_overlaps_polygon(const zarray_t *polya, const zarray_t *polyb);
124 
125 // returns the number of points written to x. see comments.
126 int g2d_polygon_rasterize(const zarray_t *poly, double y, double *x);
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif
void g2d_polygon_add(zarray_t *poly, double v[2])
Definition: g2d.c:51
int g2d_line_segment_intersect_segment(const g2d_line_segment_t *sega, const g2d_line_segment_t *segb, double *p)
Definition: g2d.c:498
void g2d_polygon_make_ccw(zarray_t *poly)
Definition: g2d.c:78
zarray_t * g2d_polygon_create_empty()
Definition: g2d.c:46
void g2d_line_init_from_points(g2d_line_t *line, const double p0[2], const double p1[2])
Definition: g2d.c:412
float p[4][2]
Definition: apriltag.h:53
int g2d_polygon_contains_polygon(const zarray_t *polya, const zarray_t *polyb)
Definition: g2d.c:586
g2d_line_t line
Definition: g2d.h:85
int g2d_polygon_rasterize(const zarray_t *poly, double y, double *x)
Definition: g2d.c:681
void g2d_line_segment_closest_point(const g2d_line_segment_t *seg, const double *q, double *p)
Definition: g2d.c:480
zarray_t * g2d_polygon_create_data(double v[][2], int sz)
Definition: g2d.c:56
int g2d_line_intersect_line(const g2d_line_t *linea, const g2d_line_t *lineb, double *p)
Definition: g2d.c:432
double g2d_line_segment_closest_point_distance(const g2d_line_segment_t *seg, const double *q)
Definition: zarray.h:49
void g2d_line_segment_init_from_points(g2d_line_segment_t *seg, const double p0[2], const double p1[2])
Definition: g2d.c:472
zarray_t * g2d_polygon_create_zeros(int sz)
Definition: g2d.c:66
int g2d_polygon_intersects_polygon(const zarray_t *polya, const zarray_t *polyb)
Definition: g2d.c:556
Definition: g2d.h:60
double g2d_line_get_coordinate(const g2d_line_t *line, const double q[2])
Definition: g2d.c:424
int g2d_polygon_contains_point(const zarray_t *poly, double q[2])
Definition: g2d.c:321
int g2d_polygon_overlaps_polygon(const zarray_t *polya, const zarray_t *polyb)
Definition: g2d.c:614


apriltags2
Author(s): Danylo Malyuta
autogenerated on Fri Oct 19 2018 04:02:32