PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ 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 1577 of file measures.c.

1584 {
1585  POINT2D R;
1586 
1587  // If the test point is on the center of the other
1588  // arc, some other point has to be closer, by definition.
1589  if (p2d_same(center_A, P))
1590  return 0;
1591 
1592  // Calculate vector from the center to the pt
1593  double dir_x = center_A->x - P->x;
1594  double dir_y = center_A->y - P->y;
1595  double dist = sqrt(dir_x * dir_x + dir_y * dir_y);
1596 
1597  // Normalize the direction vector to get a unit vector (length = 1)
1598  double unit_x = dir_x / dist;
1599  double unit_y = dir_y / dist;
1600 
1601  // Calculate the two intersection points on the circle
1602  // Point 1: Move from center_A along the unit vector by distance radius_A
1603  R.x = center_A->x + unit_x * radius_A;
1604  R.y = center_A->y + unit_y * radius_A;
1605  if (lw_pt_in_arc(&R, A1, A2, A3))
1606  I[(*ni)++] = R;
1607 
1608  // Point 2: Move from center_A against the unit vector by distance radius_A
1609  R.x = center_A->x - unit_x * radius_A;
1610  R.y = center_A->y - unit_y * radius_A;
1611  if (lw_pt_in_arc(&R, A1, A2, A3))
1612  I[(*ni)++] = R;
1613 
1614  return 0;
1615 }
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:84
int p2d_same(const POINT2D *p1, const POINT2D *p2)
Definition: lwalgorithm.c:50
double y
Definition: liblwgeom.h:405
double x
Definition: liblwgeom.h:405

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: