PostGIS  2.3.8dev-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 1674 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().

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