PostGIS  3.1.6dev-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 1735 of file measures.c.

1745 {
1746  int seg_size;
1747  double dist_sqr, shortest_sqr;
1748  const POINT2D *P1;
1749  const POINT2D *P2;
1750  POINT2D proj;
1751 
1752  if (radius_A == radius_B)
1753  {
1754  /* Check if B1 or B3 are in the same side as A2 in the A1-A3 arc */
1755  seg_size = lw_segment_side(A1, A3, A2);
1756  if (seg_size == lw_segment_side(A1, A3, B1))
1757  {
1758  lw_dist2d_distpts_set(dl, 0.0, B1, B1);
1759  return LW_TRUE;
1760  }
1761  if (seg_size == lw_segment_side(A1, A3, B3))
1762  {
1763  lw_dist2d_distpts_set(dl, 0.0, B3, B3);
1764  return LW_TRUE;
1765  }
1766  /* Check if A1 or A3 are in the same side as B2 in the B1-B3 arc */
1767  seg_size = lw_segment_side(B1, B3, B2);
1768  if (seg_size == lw_segment_side(B1, B3, A1))
1769  {
1770  lw_dist2d_distpts_set(dl, 0.0, A1, A1);
1771  return LW_TRUE;
1772  }
1773  if (seg_size == lw_segment_side(B1, B3, A3))
1774  {
1775  lw_dist2d_distpts_set(dl, 0.0, A3, A3);
1776  return LW_TRUE;
1777  }
1778  }
1779  else
1780  {
1781  /* Check if any projection of B ends are in A*/
1782  seg_size = lw_segment_side(A1, A3, A2);
1783 
1784  /* B1 */
1785  proj.x = CENTER->x + (B1->x - CENTER->x) * radius_A / radius_B;
1786  proj.y = CENTER->y + (B1->y - CENTER->y) * radius_A / radius_B;
1787 
1788  if (seg_size == lw_segment_side(A1, A3, &proj))
1789  {
1790  lw_dist2d_distpts_set(dl, fabs(radius_A - radius_B), &proj, B1);
1791  return LW_TRUE;
1792  }
1793  /* B3 */
1794  proj.x = CENTER->x + (B3->x - CENTER->x) * radius_A / radius_B;
1795  proj.y = CENTER->y + (B3->y - CENTER->y) * radius_A / radius_B;
1796  if (seg_size == lw_segment_side(A1, A3, &proj))
1797  {
1798  lw_dist2d_distpts_set(dl, fabs(radius_A - radius_B), &proj, B3);
1799  return LW_TRUE;
1800  }
1801 
1802  /* Now check projections of A in B */
1803  seg_size = lw_segment_side(B1, B3, B2);
1804 
1805  /* A1 */
1806  proj.x = CENTER->x + (A1->x - CENTER->x) * radius_B / radius_A;
1807  proj.y = CENTER->y + (A1->y - CENTER->y) * radius_B / radius_A;
1808  if (seg_size == lw_segment_side(B1, B3, &proj))
1809  {
1810  lw_dist2d_distpts_set(dl, fabs(radius_A - radius_B), &proj, A1);
1811  return LW_TRUE;
1812  }
1813 
1814  /* A3 */
1815  proj.x = CENTER->x + (A3->x - CENTER->x) * radius_B / radius_A;
1816  proj.y = CENTER->y + (A3->y - CENTER->y) * radius_B / radius_A;
1817  if (seg_size == lw_segment_side(B1, B3, &proj))
1818  {
1819  lw_dist2d_distpts_set(dl, fabs(radius_A - radius_B), &proj, A3);
1820  return LW_TRUE;
1821  }
1822  }
1823 
1824  /* Check the shortest between the distances of the 4 ends */
1825  shortest_sqr = dist_sqr = distance2d_sqr_pt_pt(A1, B1);
1826  P1 = A1;
1827  P2 = B1;
1828 
1829  dist_sqr = distance2d_sqr_pt_pt(A1, B3);
1830  if (dist_sqr < shortest_sqr)
1831  {
1832  shortest_sqr = dist_sqr;
1833  P1 = A1;
1834  P2 = B3;
1835  }
1836 
1837  dist_sqr = distance2d_sqr_pt_pt(A3, B1);
1838  if (dist_sqr < shortest_sqr)
1839  {
1840  shortest_sqr = dist_sqr;
1841  P1 = A3;
1842  P2 = B1;
1843  }
1844 
1845  dist_sqr = distance2d_sqr_pt_pt(A3, B3);
1846  if (dist_sqr < shortest_sqr)
1847  {
1848  shortest_sqr = dist_sqr;
1849  P1 = A3;
1850  P2 = B3;
1851  }
1852 
1853  lw_dist2d_distpts_set(dl, sqrt(shortest_sqr), P1, P2);
1854  return LW_TRUE;
1855 }
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:65
static double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: lwinline.h:35
static void lw_dist2d_distpts_set(DISTPTS *dl, double distance, const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:78
double y
Definition: liblwgeom.h:404
double x
Definition: liblwgeom.h:404

References distance2d_sqr_pt_pt(), lw_dist2d_distpts_set(), lw_segment_side(), LW_TRUE, 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: