通过半径和角度在地图上绘制一个圆

时间:2014-09-24 12:03:01

标签: c# map geometry dynamic-data-display

我正在使用Microsoft visual studio 2010,带有参考动态数据显示。 我想在地图上画一个圆,我有2个点,其中一个是圆的中心,另一个是圆上的点,它们之间的距离是圆的半径。 结果应如下所示:

http://sizmedia.com/my.php?i=mjmynzim2nhy.png

当我用一个点画一个圆并且const距离是这样的(距离=半径= 15)时的结果:

http://sizmedia.com/my.php?i=hm2zuv5yyenj.png

***** I don't care if the circle will look like my result(the ellipse) 
    because as I understood the earth is circle and its type of reasonable. ****

但是当我绘制距离在2点(距离= 3400 +)之间的圆圈时,我无法看到我绘制的圆圈。 我很乐意得到一些帮助,我的代码可以找到2分之间的距离。

 // Calculating the distance between the two points 
double dLat = (ps.X - centerPoint.X) / 180 * Math.PI;
double dLong = (
       double.Parse(this.plotter.Viewport.Transform.DataTransform.ViewportToData(ps).Y.ToString()) -
       double.Parse(this.plotter.Viewport.Transform.DataTransform.ViewportToData(centerPoint).Y.ToString())) / 180 * Math.PI;

double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2)
            + Math.Cos(ps.X / 180 * Math.PI) * Math.Cos(pointLine1.X / 180 * Math.PI)
            * Math.Sin(dLong / 2) * Math.Sin(dLong / 2);
double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

//Calculate radius of earth
double radiusE = 6378135; // Equatorial radius, in metres
double radiusP = 6356750; // Polar Radius

//Numerator part of function
double nr = Math.Pow(radiusE * radiusP * Math.Cos(ps.X / 180 * Math.PI), 2);
//Denominator part of the function
double dr = Math.Pow(radiusE * Math.Cos(ps.X / 180 * Math.PI), 2)
                + Math.Pow(radiusP * Math.Sin(ps.X / 180 * Math.PI), 2);
double radius = Math.Sqrt(nr / dr);

//Calculate distance in meters.
distance = (radius * c); // resualt in meters
distance /= 1000; // resualt in KM

还有我的代码添加圆圈:

while (a < 360) // Doing one round around the point (The angels)
{
    // Get the X position of the pointClicked
    cx = (double)prePs.X;
    // Get the Y position of the pointClicked
    cy = double.Parse(this.plotter.Viewport.Transform.DataTransform.ViewportToData(prePs).Y.ToString());

    // Get the new X position of the pointClicked by the angel with math calculation
    xEndP = (float)(distance * Math.Cos(a * Math.PI / 180F)) + cx;
    // Get the new Y position of the pointClicked by the angel with math calculation
    yEndP = (float)(distance * Math.Sin(a * Math.PI / 180F)) + cy;

    // Creating the new point 
    globalPoint = new DraggablePoint(new Point(xEndP, yEndP));
    globalPoint.Position = new Point(xEndP, yEndP);
    globalPoint.Visibility = Visibility.Visible;

    // Increas the angel
    a++;
    //Creat new point on the circle with new angel
    xEndPNext = (float)(distance * Math.Cos(a * Math.PI / 180F)) + cx;
    yEndPNext = (float)(distance * Math.Sin(a * Math.PI / 180F)) + cy;

    // Creat line between the two new points that we creat now
    segmentHelper = new Segment(new Point(xEndP, yEndP), new Point(xEndPNext, yEndPNext));

    // Brush between the points by line
    SolidColorBrush mySolidColorBrush = new SolidColorBrush();
    mySolidColorBrush.Color = Color.FromArgb(255, 47, 79, 49);
    segmentHelper.Stroke = mySolidColorBrush;

    // Add the line to the chartplotter
    plotter.Children.Add(segmentHelper);

    // Add the angel
    a++;
}

我的算法取一个点,下一个点并在它们之间绘制线条(当点是可见的假时)然后我得到一个漂亮的圆圈。 非常感谢你:))

0 个答案:

没有答案