PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lw_dist2d_arc_arc_concentric()

int lw_dist2d_arc_arc_concentric ( const POINT2D A1,
const POINT2D A2,
const POINT2D A3,
double  radius_A,
const POINT2D B1,
const POINT2D B2,
const POINT2D B3,
double  radius_B,
const POINT2D CENTER,
DISTPTS dl 
)

Definition at line 1679 of file measures.c.

1684 {
1685  int seg_size;
1686  double dist_sqr, shortest_sqr;
1687  const POINT2D *P1;
1688  const POINT2D *P2;
1689  POINT2D proj;
1690 
1691  if (radius_A == radius_B)
1692  {
1693  /* Check if B1 or B3 are in the same side as A2 in the A1-A3 arc */
1694  seg_size = lw_segment_side(A1, A3, A2);
1695  if (seg_size == lw_segment_side(A1, A3, B1))
1696  {
1697  dl->p1 = *B1;
1698  dl->p2 = *B1;
1699  dl->distance = 0;
1700  return LW_TRUE;
1701  }
1702  if (seg_size == lw_segment_side(A1, A3, B3))
1703  {
1704  dl->p1 = *B3;
1705  dl->p2 = *B3;
1706  dl->distance = 0;
1707  return LW_TRUE;
1708  }
1709  /* Check if A1 or A3 are in the same side as B2 in the B1-B3 arc */
1710  seg_size = lw_segment_side(B1, B3, B2);
1711  if (seg_size == lw_segment_side(B1, B3, A1))
1712  {
1713  dl->p1 = *A1;
1714  dl->p2 = *A1;
1715  dl->distance = 0;
1716  return LW_TRUE;
1717  }
1718  if (seg_size == lw_segment_side(B1, B3, A3))
1719  {
1720  dl->p1 = *A3;
1721  dl->p2 = *A3;
1722  dl->distance = 0;
1723  return LW_TRUE;
1724  }
1725  }
1726  else
1727  {
1728  /* Check if any projection of B ends are in A*/
1729  seg_size = lw_segment_side(A1, A3, A2);
1730 
1731  /* B1 */
1732  proj.x = CENTER->x + (B1->x - CENTER->x) * radius_A / radius_B;
1733  proj.y = CENTER->y + (B1->y - CENTER->y) * radius_A / radius_B;
1734 
1735  if (seg_size == lw_segment_side(A1, A3, &proj))
1736  {
1737  dl->p1 = proj;
1738  dl->p2 = *B1;
1739  dl->distance = fabs(radius_A - radius_B);
1740  return LW_TRUE;
1741  }
1742  /* B3 */
1743  proj.x = CENTER->x + (B3->x - CENTER->x) * radius_A / radius_B;
1744  proj.y = CENTER->y + (B3->y - CENTER->y) * radius_A / radius_B;
1745  if (seg_size == lw_segment_side(A1, A3, &proj))
1746  {
1747  dl->p1 = proj;
1748  dl->p2 = *B3;
1749  dl->distance = fabs(radius_A - radius_B);
1750  return LW_TRUE;
1751  }
1752 
1753  /* Now check projections of A in B */
1754  seg_size = lw_segment_side(B1, B3, B2);
1755 
1756  /* A1 */
1757  proj.x = CENTER->x + (A1->x - CENTER->x) * radius_B / radius_A;
1758  proj.y = CENTER->y + (A1->y - CENTER->y) * radius_B / radius_A;
1759  if (seg_size == lw_segment_side(B1, B3, &proj))
1760  {
1761  dl->p1 = proj;
1762  dl->p2 = *A1;
1763  dl->distance = fabs(radius_A - radius_B);
1764  return LW_TRUE;
1765  }
1766 
1767  /* A3 */
1768  proj.x = CENTER->x + (A3->x - CENTER->x) * radius_B / radius_A;
1769  proj.y = CENTER->y + (A3->y - CENTER->y) * radius_B / radius_A;
1770  if (seg_size == lw_segment_side(B1, B3, &proj))
1771  {
1772  dl->p1 = proj;
1773  dl->p2 = *A3;
1774  dl->distance = fabs(radius_A - radius_B);
1775  return LW_TRUE;
1776  }
1777  }
1778 
1779  /* Check the shortest between the distances of the 4 ends */
1780  shortest_sqr = dist_sqr = distance2d_sqr_pt_pt(A1, B1);
1781  P1 = A1;
1782  P2 = B1;
1783 
1784  dist_sqr = distance2d_sqr_pt_pt(A1, B3);
1785  if (dist_sqr < shortest_sqr)
1786  {
1787  shortest_sqr = dist_sqr;
1788  P1 = A1;
1789  P2 = B3;
1790  }
1791 
1792  dist_sqr = distance2d_sqr_pt_pt(A3, B1);
1793  if (dist_sqr < shortest_sqr)
1794  {
1795  shortest_sqr = dist_sqr;
1796  P1 = A3;
1797  P2 = B1;
1798  }
1799 
1800  dist_sqr = distance2d_sqr_pt_pt(A3, B3);
1801  if (dist_sqr < shortest_sqr)
1802  {
1803  shortest_sqr = dist_sqr;
1804  P1 = A3;
1805  P2 = B3;
1806  }
1807 
1808  dl->p1 = *P1;
1809  dl->p2 = *P2;
1810  dl->distance = sqrt(shortest_sqr);
1811 
1812  return LW_TRUE;
1813 }
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:64
double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2323
POINT2D p1
Definition: measures.h:52
POINT2D p2
Definition: measures.h:53
double distance
Definition: measures.h:51
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331

References DISTPTS::distance, distance2d_sqr_pt_pt(), lw_segment_side(), LW_TRUE, DISTPTS::p1, DISTPTS::p2, 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: