简体   繁体   English

使用GPS坐标从圆弧上移除圆弧

[英]Remove an arc from circle using GPS coordinates

How to remove the arc coordinates from the circle? 如何从圆中删除圆弧坐标? I can't really use the latitude or longitude to compare the coordinate. 我真的不能使用纬度或经度来比较坐标。

I have 3 coordinates to work with. 我有3个坐标要使用。

A is the start coordinate A是开始坐标

B is the stop coordinate B是停止坐标

C is the center coordinate C是中心坐标

C also has the radius 13 miles from A or B or any coordinates from the circle C的半径也距A或B 13英里,或者距圆的任何坐标

Please notes that the coordinates could be anywhere on the circle and in any orders. 请注意,坐标可以在圆上的任何位置,也可以以任何顺序排列。

Sample of the image 图片样本

Let's say that arc creates a angle of θ, so A and B difference of y coordinates gives the length of bottom triangle. 假设弧产生一个角度θ,因此y坐标的A和B差给出了下三角形的长度。 So we say A (x1,y1) and B (x2,y2), 所以我们说A(x1,y1)和B(x2,y2),

2rsin( θ/2 ) = y1-y2 2rsin(θ/ 2)= y1-y2

solve this and you will get the θ. 解决此问题,您将获得θ。 So and arc would be 2πr(θ/360). 因此,弧将为2πr(θ/ 360)。

Took all night to come up with this. 花了一整夜想出这个办法。

 /// <summary>
        /// Draw an arc with .Net code
        /// </summary>
        /// <param name="a">Start point</param>
        /// <param name="b">Stop oint</param>
        /// <param name="centerPoint">Center point</param>
        /// <param name="nauticalMiles"></param>
        /// <returns></returns>
        public static string ExactArtGpsCoordinate(TfrXY a, TfrXY b, TfrXY centerPoint, decimal nauticalMiles)
        {
            //Notice database store longitude then latitude
            StringBuilder coordinates = new StringBuilder();
            DbGeography point = DbGeography.PointFromText(string.Format("POINT ({0} {1})", centerPoint.LngX, centerPoint.LatY), DbGeography.DefaultCoordinateSystemId);
            // create a circle around a point, convert from Nautical Miles to Kilometers
            var radius = UniversalWeather.Weather.API.Utility.MetricConversions.MetricConversions.NauticalMilesToMeters(nauticalMiles);
            DbGeography orig = point.Buffer(Convert.ToDouble(radius));
            string resultData = orig.AsText();

            //Clean data
            resultData = resultData.Replace("POLYGON ((", "");
            resultData = resultData.Replace(", ", ",0\n");
            resultData = resultData.Replace("))", ",0");
            resultData = resultData.Replace(" ", ",");

            //Convert the circular coordinate into array
            string[] splitCoordinates = resultData.Split('\n');
            bool IsEastToWest = false;
            #region Determinte direction
            if (a.LngX > b.LngX)
            {
                IsEastToWest = true;
            }
            #endregion

            //Add stop point
            coordinates.Append(b.LngX.ToString() + "," + b.LatY.ToString() + ",0\n");

            //Help to split the calculation for the arc
            double middleX = (a.LngX + b.LngX) / 2f;
            double middleY = (a.LatY + b.LatY) / 2f;

            for (int i = 0; i < splitCoordinates.Length; i++)
            {
                //split data to long then lat
                string[] temp = splitCoordinates[i].Split(',');
                //Current longitude
                double cx = Convert.ToDouble(temp[0]);
                double cy = Convert.ToDouble(temp[1]);

                #region Logic for East to West
                if (IsEastToWest)
                {
                    ////Half East
                    if (a.LatY > cy && middleX <= cx)
                    {
                        coordinates.Append(splitCoordinates[i] + "\n");
                    }
                    //Half West
                    else if (middleX >= cx && b.LatY >= cy)
                    {
                        coordinates.Append(splitCoordinates[i] + "\n");
                    }
                }
                #endregion
                #region Logic for West to EAST
                else
                {
                    //Half West
                    if (a.LatY < cy && middleX >= cx)
                    {
                        coordinates.Append(splitCoordinates[i] + "\n");
                    }
                    //Half East
                    else if (middleX <= cx && cx < b.LngX && cy > centerPoint.LatY)
                    {
                        coordinates.Append(splitCoordinates[i] + "\n");
                    }
                } 
                #endregion
            }
            //Add start point
             coordinates.Append(a.LngX.ToString() + "," + a.LatY.ToString() + ",0\n");
            return coordinates.ToString();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM