问题描述
我正在使用 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 (将#修改为@)