PostGIS  2.5.0beta2dev-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 1678 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().

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