PostGIS  2.4.9dev-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 1675 of file measures.c.

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(), and lw_dist2d_pt_arc().

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