PostGIS  2.3.7dev-r@@SVN_REVISION@@
LWPOLY* lwpoly_construct_circle ( int  srid,
double  x,
double  y,
double  radius,
uint32_t  segments_per_quarter,
char  exterior 
)

Definition at line 98 of file lwpoly.c.

References LW_FALSE, LW_TRUE, lwerror(), lwpoly_add_ring(), lwpoly_construct_empty(), ptarray_append_point(), ptarray_construct_empty(), POINT4D::x, and POINT4D::y.

Referenced by ST_MinimumBoundingCircle(), and test_lwpoly_construct_circle().

99 {
100  const int segments = 4*segments_per_quarter;
101  const double theta = 2*M_PI / segments;
102  LWPOLY *lwpoly;
103  POINTARRAY *pa;
104  POINT4D pt;
105  uint32_t i;
106 
107  if (segments_per_quarter < 1)
108  {
109  lwerror("Need at least one segment per quarter-circle.");
110  return NULL;
111  }
112 
113  if (radius < 0)
114  {
115  lwerror("Radius must be positive.");
116  return NULL;
117  }
118 
119  lwpoly = lwpoly_construct_empty(srid, LW_FALSE, LW_FALSE);
120  pa = ptarray_construct_empty(LW_FALSE, LW_FALSE, segments + 1);
121 
122  if (exterior)
123  radius *= sqrt(1 + pow(tan(theta/2), 2));
124 
125  for (i = 0; i <= segments; i++)
126  {
127  pt.x = x + radius*sin(i * theta);
128  pt.y = y + radius*cos(i * theta);
129  ptarray_append_point(pa, &pt, LW_TRUE);
130  }
131 
132  lwpoly_add_ring(lwpoly, pa);
133  return lwpoly;
134 }
double x
Definition: liblwgeom.h:351
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring to a polygon.
Definition: lwpoly.c:225
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:137
tuple x
Definition: pixval.py:53
double y
Definition: liblwgeom.h:351
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: