2010-07-14 92 views
1

我有一个圆,实际上是一个以米为单位测量半径的latlon位置。而且我还有一条道路A-B被定义为两个经纬位置。我如何找到这条路是否跨越了圈内。没有投影拉伸位置到xy位置可能吗?如果可能的话,请告诉我如何去做。实际上我试图在导航软件中实现捕捉到道路功能。所以这不是一项家庭作业,而且直截了当的可用程序非常值得赞赏,因为我在数学上非常糟糕。圆和线段交点检测(LatLon点,仪表半径和LatLon线)

谢谢。

回答

2

我不知道纬度长的表示法。
但是 - 通常这个问题并不需要很高的数学。
首先建立A到B之间的线的方程(称为线L1)。
然后找到穿过圆心的L1垂直线的方程(称之为L2)。
然后找到两个方程的交点,并检查交点是否在圆内,是否在[A-B]中。

+0

@意大利,我的数学是倾销。我甚至不知道如何建立一条线的方程。更多提示请求? – VOX 2010-07-14 11:42:00

+0

@VOX:你有试过Google吗? – 2010-07-14 11:54:19

+0

是的。到目前为止,唷... – VOX 2010-07-14 12:07:25

0

Itay的,解决方案是优雅的,不需要太多垫子。

但是你可以去一个比较幼稚(CPU重)实现:

让你的行成点的阵列,然后测量到你的圈子的中心从每个点的距离:

方法变换两点成坐标的阵列(I只测试此方法简述)

public static Point[] generatePath(int startX, int startY, int endX, int endY) { 
     _deltaX = Math.Abs(endX - startX); 
     _deltaY = Math.Abs(endY - startY); 
     if (_deltaX >=_deltaY) { 
     //x is independent variable 
     _numpixels = _deltaX + 1; 
     _d = (2 * _deltaY) - _deltaY; 
     _dinc1 = _deltaY << 1; 
     _dinc2 = (_deltaY - _deltaX) << 1; 
     _xinc1 = 1; 
     _xinc2 = 1; 
     _yinc1 = 0; 
     _yinc2 = 1; 
     } else { 
     //y is independent variable 
     _numpixels = _deltaY + 1; 
     _d = (2 * _deltaX) - _deltaY; 
     _dinc1 = _deltaX << 1; 
     _dinc2 = (_deltaX - _deltaY) << 1; 
     _xinc1 = 0; 
     _xinc2 = 1; 
     _yinc1 = 1; 
     _yinc2 = 1; 
     } 
     // Make sure x and y move in the right directions 
     if (startX > endX) { 
     _xinc1 = -_xinc1; 
     _xinc2 = -_xinc2; 
     } 
     if (startY > endY) { 
     _yinc1 = -_yinc1; 
     _yinc2 = -_yinc2; 
     } 
     _x = startX; 
     _y = startY; 
     Point[] returnPath = new Point[_numpixels]; 
     for (int i = 0;i < _numpixels;i++) { 
     returnPath[i].X =_x; 
     returnPath[i].Y =_y; 
     if (_d < 0) { 
      _d = _d + _dinc1; 
      _x = _x + _xinc1; 
      _y = _y + _yinc1; 
     } else { 
      _d = _d + _dinc2; 
      _x = _x + _xinc2; 
      _y = _y + _yinc2; 
     } 
     } 
     return returnPath; 
    } 

方法来计算,以在线的每一点从圆的中心距:

public static double GetLenghtBetweenPoints(Point Source, Point Distination) { 
     return Math.Sqrt((Math.Pow((Source.X-Distination.X), 2) + Math.Pow((Source.Y-Distination.Y), 2))); 
    } 
+0

这真的不会为我工作。我在.NET CF上使用较少的CPU功率器件。不过谢谢。 – VOX 2010-07-14 16:12:31