PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lw_dist2d_circle_intersections()

static int lw_dist2d_circle_intersections ( const POINT2D A1,
const POINT2D A2,
const POINT2D A3,
const POINT2D center_A,
double  radius_A,
const POINT2D P,
POINT2D I,
uint32_t *  ni 
)
static

Calculates the intersection points of a circle and line.

This function assumes the center and test point are distinct. Finds the line between the circle center and test point, and the two intersection points on the circle defined by that line. If those points fall within the provided arc (A1,A2,A3) then the points are added to the provided array (I) and the array length counter is incremented.

Parameters
A1Point of arc
A2Point of arc
A3Point of arc
center_ACenter of arc A circle
radius_ARadius of arc A circle
PPoint to use in calculating intersection line
I[out] Pointer to an return value array
ni[out] Pointer to return array size counter
Returns
int

Definition at line 1566 of file measures.c.

1573{
1574 POINT2D R;
1575
1576 // If the test point is on the center of the other
1577 // arc, some other point has to be closer, by definition.
1578 if (p2d_same(center_A, P))
1579 return 0;
1580
1581 // Calculate vector from the center to the pt
1582 double dir_x = center_A->x - P->x;
1583 double dir_y = center_A->y - P->y;
1584 double dist = sqrt(dir_x * dir_x + dir_y * dir_y);
1585
1586 // Normalize the direction vector to get a unit vector (length = 1)
1587 double unit_x = dir_x / dist;
1588 double unit_y = dir_y / dist;
1589
1590 // Calculate the two intersection points on the circle
1591 // Point 1: Move from center_A along the unit vector by distance radius_A
1592 R.x = center_A->x + unit_x * radius_A;
1593 R.y = center_A->y + unit_y * radius_A;
1594 if (lw_pt_in_arc(&R, A1, A2, A3))
1595 I[(*ni)++] = R;
1596
1597 // Point 2: Move from center_A against the unit vector by distance radius_A
1598 R.x = center_A->x - unit_x * radius_A;
1599 R.y = center_A->y - unit_y * radius_A;
1600 if (lw_pt_in_arc(&R, A1, A2, A3))
1601 I[(*ni)++] = R;
1602
1603 return 0;
1604}
int lw_pt_in_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns true if P is on the same side of the plane partition defined by A1/A3 as A2 is.
Definition lwalgorithm.c:91
int p2d_same(const POINT2D *p1, const POINT2D *p2)
Definition lwalgorithm.c:57
double y
Definition liblwgeom.h:390
double x
Definition liblwgeom.h:390

References lw_pt_in_arc(), p2d_same(), POINT2D::x, and POINT2D::y.

Referenced by lw_dist2d_arc_arc().

Here is the call graph for this function:
Here is the caller graph for this function: