PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 1769 of file measures.c.

1779{
1780 int seg_size;
1781 double dist_sqr, shortest_sqr;
1782 const POINT2D *P1;
1783 const POINT2D *P2;
1784 POINT2D proj;
1785
1786 if (radius_A == radius_B)
1787 {
1788 /* Check if B1 or B3 are in the same side as A2 in the A1-A3 arc */
1789 seg_size = lw_segment_side(A1, A3, A2);
1790 if (seg_size == lw_segment_side(A1, A3, B1))
1791 {
1792 dl->p1 = *B1;
1793 dl->p2 = *B1;
1794 dl->distance = 0;
1795 return LW_TRUE;
1796 }
1797 if (seg_size == lw_segment_side(A1, A3, B3))
1798 {
1799 dl->p1 = *B3;
1800 dl->p2 = *B3;
1801 dl->distance = 0;
1802 return LW_TRUE;
1803 }
1804 /* Check if A1 or A3 are in the same side as B2 in the B1-B3 arc */
1805 seg_size = lw_segment_side(B1, B3, B2);
1806 if (seg_size == lw_segment_side(B1, B3, A1))
1807 {
1808 dl->p1 = *A1;
1809 dl->p2 = *A1;
1810 dl->distance = 0;
1811 return LW_TRUE;
1812 }
1813 if (seg_size == lw_segment_side(B1, B3, A3))
1814 {
1815 dl->p1 = *A3;
1816 dl->p2 = *A3;
1817 dl->distance = 0;
1818 return LW_TRUE;
1819 }
1820 }
1821 else
1822 {
1823 /* Check if any projection of B ends are in A*/
1824 seg_size = lw_segment_side(A1, A3, A2);
1825
1826 /* B1 */
1827 proj.x = CENTER->x + (B1->x - CENTER->x) * radius_A / radius_B;
1828 proj.y = CENTER->y + (B1->y - CENTER->y) * radius_A / radius_B;
1829
1830 if (seg_size == lw_segment_side(A1, A3, &proj))
1831 {
1832 dl->p1 = proj;
1833 dl->p2 = *B1;
1834 dl->distance = fabs(radius_A - radius_B);
1835 return LW_TRUE;
1836 }
1837 /* B3 */
1838 proj.x = CENTER->x + (B3->x - CENTER->x) * radius_A / radius_B;
1839 proj.y = CENTER->y + (B3->y - CENTER->y) * radius_A / radius_B;
1840 if (seg_size == lw_segment_side(A1, A3, &proj))
1841 {
1842 dl->p1 = proj;
1843 dl->p2 = *B3;
1844 dl->distance = fabs(radius_A - radius_B);
1845 return LW_TRUE;
1846 }
1847
1848 /* Now check projections of A in B */
1849 seg_size = lw_segment_side(B1, B3, B2);
1850
1851 /* A1 */
1852 proj.x = CENTER->x + (A1->x - CENTER->x) * radius_B / radius_A;
1853 proj.y = CENTER->y + (A1->y - CENTER->y) * radius_B / radius_A;
1854 if (seg_size == lw_segment_side(B1, B3, &proj))
1855 {
1856 dl->p1 = proj;
1857 dl->p2 = *A1;
1858 dl->distance = fabs(radius_A - radius_B);
1859 return LW_TRUE;
1860 }
1861
1862 /* A3 */
1863 proj.x = CENTER->x + (A3->x - CENTER->x) * radius_B / radius_A;
1864 proj.y = CENTER->y + (A3->y - CENTER->y) * radius_B / radius_A;
1865 if (seg_size == lw_segment_side(B1, B3, &proj))
1866 {
1867 dl->p1 = proj;
1868 dl->p2 = *A3;
1869 dl->distance = fabs(radius_A - radius_B);
1870 return LW_TRUE;
1871 }
1872 }
1873
1874 /* Check the shortest between the distances of the 4 ends */
1875 shortest_sqr = dist_sqr = distance2d_sqr_pt_pt(A1, B1);
1876 P1 = A1;
1877 P2 = B1;
1878
1879 dist_sqr = distance2d_sqr_pt_pt(A1, B3);
1880 if (dist_sqr < shortest_sqr)
1881 {
1882 shortest_sqr = dist_sqr;
1883 P1 = A1;
1884 P2 = B3;
1885 }
1886
1887 dist_sqr = distance2d_sqr_pt_pt(A3, B1);
1888 if (dist_sqr < shortest_sqr)
1889 {
1890 shortest_sqr = dist_sqr;
1891 P1 = A3;
1892 P2 = B1;
1893 }
1894
1895 dist_sqr = distance2d_sqr_pt_pt(A3, B3);
1896 if (dist_sqr < shortest_sqr)
1897 {
1898 shortest_sqr = dist_sqr;
1899 P1 = A3;
1900 P2 = B3;
1901 }
1902
1903 dl->p1 = *P1;
1904 dl->p2 = *P2;
1905 dl->distance = sqrt(shortest_sqr);
1906
1907 return LW_TRUE;
1908}
#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
POINT2D p1
Definition measures.h:52
POINT2D p2
Definition measures.h:53
double distance
Definition measures.h:51
double y
Definition liblwgeom.h:376
double x
Definition liblwgeom.h:376

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: