我正在使用 Xamarin 框架在 C# 中开发移动应用程序。我试图在地图上以固定角度移动一个点,如下面的 gif 的第一部分。我相信我正在使用正确的数学函数来计算移位点的坐标,因为在 GIF 的第一部分,在 GeoGebra 中,一切似乎都很好。
但实际应用内实现时,结果很奇怪:角度不一致,中心与点之间的距离随着目标的移动而变化。
我不知道代码有什么问题。在下面的代码中,我polylineOptions
用来绘制线条,但我尝试使用 aPolygon
并显示相同的结果。可能是因为customMap.UserPin.Position
返回十进制度格式 (ig 34.00462, -4.512221
) 的坐标,并且两个位置之间的差距对于 a 来说太小了double
。
这是用于绘制线条的两个函数。
// 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;
}
我希望有人可以帮助我!
谢谢你。