Segmentize an arc.
253 double angle_shift = 0;
257 int points_added = 0;
261 LWDEBUG(2,
"lwarc_linearize called.");
263 LWDEBUGF(2,
" curve is CIRCULARSTRING(%.15g %.15f, %.15f %.15f, %.15f %15f)",
264 t1->
x, t1->
y, t2->
x, t2->
y, t3->
x, t3->
y);
268 LWDEBUGF(2,
" p2 side is %d", p2_side);
283 LWDEBUGF(2,
" center is POINT(%.15g %.15g) - radius:%g", center.
x, center.
y, radius);
286 if ( p1->
x == p3->
x && p1->
y == p3->
y )
290 if ( (radius < 0.0 || p2_side == 0) && ! is_circle )
302 switch(tolerance_type)
314 lwerror(
"lwarc_linearize: unsupported tolerance type %d", tolerance_type);
327 a1 = atan2(p1->
y - center.
y, p1->
x - center.
x);
328 a2 = atan2(p2->
y - center.
y, p2->
x - center.
x);
329 a3 = atan2(p3->
y - center.
y, p3->
x - center.
x);
331 LWDEBUGF(2,
"lwarc_linearize A1:%g (%g) A2:%g (%g) A3:%g (%g)",
332 a1, a1*180/M_PI, a2, a2*180/M_PI, a3, a3*180/M_PI);
335 double total_angle = clockwise ? a1 - a3 : a3 - a1;
336 if ( total_angle <= 0 ) total_angle += M_PI * 2;
342 int min_segs = is_circle ? 3 : 2;
343 segments = ceil(total_angle / increment);
344 if (segments < min_segs)
347 increment = total_angle / min_segs;
352 LWDEBUGF(2,
"lwarc_linearize SYMMETRIC requested - total angle %g deg", total_angle * 180 / M_PI);
357 segments = trunc(total_angle / increment);
362 double angle_remainder = total_angle - (increment * segments);
367 angle_shift = angle_remainder / 2.0;
370 "lwarc_linearize RETAIN_ANGLE operation requested - "
371 "total angle %g, steps %d, increment %g, remainder %g",
372 total_angle * 180 / M_PI,
374 increment * 180 / M_PI,
375 angle_remainder * 180 / M_PI);
380 segments = ceil(total_angle / increment);
382 increment = total_angle / segments;
385 "lwarc_linearize SYMMETRIC operation requested - "
386 "total angle %g degrees - LINESTRING(%g %g,%g %g,%g %g) - S:%d - I:%g",
387 total_angle * 180 / M_PI,
395 increment * 180 / M_PI);
402 LWDEBUG(2,
" Clockwise sweep");
414 LWDEBUG(2,
" Counterclockwise sweep");
425 increment = fabs(increment);
426 segments = ceil(total_angle / increment);
430 increment = total_angle / 3;
432 a3 = a1 + 2.0 * M_PI;
438 LWDEBUGF(2,
"lwarc_linearize angle_shift:%g, increment:%g",
439 angle_shift * 180/M_PI, increment * 180/M_PI);
445 const int capacity = 8;
460 int seg_end = segments;
461 if (angle_shift != 0.0)
466 seg_end = segments + 1;
468 LWDEBUGF(2,
"a1:%g (%g deg), a3:%g (%g deg), inc:%g, shi:%g, cw:%d",
469 a1, a1 * 180 / M_PI, a3, a3 * 180 / M_PI, increment, angle_shift, clockwise);
470 for (
int s = seg_start;
s < seg_end;
s++)
472 double angle = a1 + increment *
s + angle_shift;
473 LWDEBUGF(2,
" SA: %g ( %g deg )", angle, angle*180/M_PI);
474 pt.
x = center.
x + radius * cos(angle);
475 pt.
y = center.
y + radius * sin(angle);
493 for ( i=pa->
npoints; i>0; i-- ) {
int ptarray_remove_point(POINTARRAY *pa, uint32_t where)
Remove a point from an existing POINTARRAY.
@ LW_LINEARIZE_TOLERANCE_TYPE_MAX_ANGLE
Tolerance expresses the maximum angle between the radii generating approximation line vertices,...
@ LW_LINEARIZE_TOLERANCE_TYPE_SEGS_PER_QUAD
Tolerance expresses the number of segments to use for each quarter of circle (quadrant).
@ LW_LINEARIZE_TOLERANCE_TYPE_MAX_DEVIATION
Tolerance expresses the maximum distance between an arbitrary point on the curve and the closest poin...
@ LW_LINEARIZE_FLAG_SYMMETRIC
Symmetric linearization means that the output vertices would be the same no matter the order of the p...
@ LW_LINEARIZE_FLAG_RETAIN_ANGLE
Retain angle instructs the engine to try its best to retain the requested angle between generating ra...
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
void ptarray_free(POINTARRAY *pa)
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,...
#define LW_TRUE
Return types for functions with status returns.
double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result)
Determines the center of the circle defined by the three given points.
int ptarray_has_z(const POINTARRAY *pa)
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
int ptarray_has_m(const POINTARRAY *pa)
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static double angle_increment_using_max_deviation(double max_deviation, double radius)
static double interpolate_arc(double angle, double a1, double a2, double a3, double zm1, double zm2, double zm3)
static double angle_increment_using_segments_per_quad(double tol)
static double angle_increment_using_max_angle(double tol)