1

I am working on a mobile app in C# using the Xamarin framework. I am trying to move a point by a fixed angle on a map like in the first part of the gif below. I believe I am using the right mathematical functions to compute the coordinates of the shifted points since in first part of the GIF, in GeoGebra, everything seems to be fine.

But when it comes to the actual in-app implementation, the results are quite weird : the angle is not consistent and the distance between the center and the points varies by moving the target.

The GIF showing the issue

I don't have a clue about what is wrong with the code. In the code below I use polylineOptions to draw the lines but I've tried with a Polygon and it displays the same results. Maybe it's because customMap.UserPin.Position returns the coordinates in Decimal Degree format (i.g. 34.00462, -4.512221) and the gap between two position is too small for a double.

Here are the two functions used to draw the lines.

        // Add a cone's side to the variable coneLines
        private void addConePolyline(double angle, CustomMap customMap, LatLng userPos)
        {
            // The coordinates of the end of the side to be drawn
            LatLng conePoint = movePoint(angle, customMap.UserPin.Position, customMap.TargetPin.Position);

            var polylineOptions = new PolylineOptions();

            polylineOptions.InvokeWidth(10f);
            polylineOptions.InvokeColor(Android.Graphics.Color.Argb(240, 255, 20, 147)); // Pink

            polylineOptions.Add(userPos);
            polylineOptions.Add(conePoint);

            // Add the line to coneLines
            coneLines.Add(map.AddPolyline(polylineOptions));
        }
        // Moves a point by the given angle on a circle of center rotationCenter with respect to p
        private LatLng movePoint(double angle, Position rotationCenter, Position initialPoint)
        {
            // Compute the components of the translation vector between rotationCenter and initialPoint
            double dx = initialPoint.Latitude - rotationCenter.Latitude;
            double dy = initialPoint.Longitude - rotationCenter.Longitude;

            // Compute the moved point's position
            double x = rotationCenter.Latitude + Math.Cos(angle) * dx - Math.Sin(angle) * dy;
            double y = rotationCenter.Longitude + Math.Sin(angle) * dx + Math.Cos(angle) * dy;

            LatLng res = new LatLng(x, y);

            return res;
        }

I hope someone can help me with this!

Thank you.

  • Are you sure the horizontal and vertical scale are the same? If you draw a point and then four points to the North, East, South and West at the same distance, will the distances on the screen be the same? – Thinko Feb 17 '21 at 21:50
  • Turns out that the issue is what you've highlighted: if I draw a cross on a point other than (0,0), distortion occurs [as you can see here](https://imgur.com/a/pGvxy4I). I'll dive into this to try and correct it, thank you for your answer! – spearfish-thread Feb 18 '21 at 10:04
  • @spearfish-thread So you have solution about your problem? – Cherry Bu - MSFT Feb 23 '21 at 01:28
  • @CherryBu-MSFT Unfortunately I've tried different things (multiplying the shifted latitude by cos(rotationCenter.Latitude) for example) but I never got the result I expected. ATM I can't keep my focus on this particular issue so I just left it... – spearfish-thread Feb 24 '21 at 09:06

0 Answers0