简体   繁体   中英

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.

A is the start coordinate

B is the stop coordinate

C is the center coordinate

C also has the radius 13 miles from A or B or any coordinates from the circle

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. So we say A (x1,y1) and B (x2,y2),

2rsin( θ/2 ) = y1-y2

solve this and you will get the θ. So and arc would be 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();
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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