如何解决使用 Xamarin.Forms.Map.Position 的三角学问题
我正在使用 Xamarin 框架在 C# 中开发一个移动应用程序。我试图在地图上以固定角度移动一个点,如下面 gif 的第一部分所示。我相信我正在使用正确的数学函数来计算移动点的坐标,因为在 GIF 的第一部分,在 GeoGebra 中,一切似乎都很好。
但是到了实际的应用内实现时,结果却很奇怪:角度不一致,中心和点之间的距离随着目标的移动而变化。
我不知道代码有什么问题。在下面的代码中,我使用 polylineOptions
绘制线条,但我尝试使用 Polygon
并且它显示相同的结果。可能是因为 customMap.UserPin.Position
以十进制格式返回坐标(例如 34.00462,-4.512221
),并且两个位置之间的差距对于 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;
}
希望有人能帮我解决这个问题!
谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。