我有两个位置,在这两个位置之间,我必须根据半径绘制一条曲线。我画了一幅画:

我知道怎么画圆圈。但如何只画圆圈的一部分呢?
以下是已知的参数:
如果有人能告诉我如何在当前位置和下一个位置之间的圆圈上得到点,我可以用polyline来绘制曲线。但是如何计算位置呢?
发布于 2014-08-05 08:46:52
我为我的问题找到了解决办法。
我所做的是

矢状面可以用以下公式计算:

哪里,
l是当前位置与下一个位置之间距离的一半。
r是曲线半径
s是射手
我使用的代码是:
function DrawCurvedLine(startLatitude, startLongitude, endLatitude, endLongitude, roc, lineColor) {
var distance;
var latLng1, latLng2;
var sagitta;
var midPoint;
var heading;
var roc;
var center;
var arc = new Array();
curvePoints = [];
// Create current and predicted latlng objects
latLng1 = new google.maps.LatLng(startLatitude, startLongitude);
latLng2 = new google.maps.LatLng(endLatitude, endLongitude);
// Compute the distance between current location and predicted location
distance = google.maps.geometry.spherical.computeDistanceBetween(currentLatLng, predictedLatLng);
sagitta = computeSagitta(roc, (distance / 2));
midPoint = getMidPoint(latLng1, latLng2);
heading = google.maps.geometry.spherical.computeHeading(latLng1, latLng2);
heading = headingClPl + 90;
center = google.maps.geometry.spherical.computeOffset(midPoint, (roc - sagitta), headingClPl);
var Heading1 = google.maps.geometry.spherical.computeHeading(center, latLng1);
var Heading2 = google.maps.geometry.spherical.computeHeading(center, latLng2);
var i = 0;
while ((Heading1 + i) <= Heading2 || (Heading2 + i) <= Heading1) {
if (radiusOfCurve < 0) {
arcPts.push(google.maps.geometry.spherical.computeOffset(centerOfCurve, roc, Heading1 - i));
}
else {
arcPts.push(google.maps.geometry.spherical.computeOffset(centerOfCurve, roc, Heading1 + i));
}
i++;
}
var curvedLine = new google.maps.Polyline({
path: arcPts,
icons: [{
icon: {
path: google.maps.SymbolPath.FORWARD_OPEN_ARROW,
scale: 3,
strokeColor: lineColor,
strokeOpacity: 1,
strokeWeight: 1.3,
fillColor: 'transparent',
fillOpacity: 0
},
offset: '100%'
}],
strokeColor: lineColor,
strokeOpacity: 0.5,
strokeWeight: 2,
map: map
});
function computeSagitta(radius, length){
// radius is radius of circle. length is the half length of chord
return (radius - (Math.sqrt((radius * radius) - (length * length))));
}发布于 2014-07-26 07:43:36
你可以用这个Answer画弧。
找到弧形的中心。
您可以使用Google Geometry库来查找两个标记之间的弦长、其方位和弧点的位置。
来自文档的
computeDistanceBetween(从:LatLng,到:LatLng,半径?:number )返回两个LatLngs之间的距离,以米为单位。半径默认为以米为单位的地球半径(6378137)。 computeHeading( from : LatLng,to: LatLng )将标题从一个LatLng返回到另一个LatLng。标题以顺时针方向在范围内从北表示[-180,180]为一个数字。 computeOffset(出发地: LatLng,距离:number,标题:number,radius?:number)返回从指定标题中的原点(从北顺时针方向表示)的距离为LatLng的LatLng。
先找到两个标记之间的距离
var spherical = google.maps.geometry.spherical;
var point1 = markers[0].getPosition();
var point2 = markers[1].getPosition();
var length = google.maps.geometry.spherical.computeDistanceBetween(point1,point2);那就找轴承
var heading = google.maps.geometry.spherical.computeHeading(point1,point2);

正如你现在所知道的三角形的三边(弦长,半径(其它两面)),你用law of cosines计算圆弧中心的方位。(注意,注释中有两个解。)
function solveAngle(a, b, c) { // Returns angle C using law of cosines
var temp = (b * b + c * c - a * a) / (2 * b * c);
if (temp >= -1 && temp <= 1)
return Math.acos(temp);
else
throw "No solution";
}
var baseAngle = solveAngle(radius, radius, c);
var vertexAngle = solveAngle(c,radius,radius);利用baseAngle来确定中心点的方位。
vertexAngle是在绘制弧时使用的点数。
知道方位和半径,你可以找到弧的中心。
var centerPoint = spherical.computeOffset(point1,radius,heading+baseAngle);注意到距离,以米为单位。将方法中的半径改为3,959英里。
如果半径改变,中心就会改变。黄点是蓝点半径的2倍。

https://stackoverflow.com/questions/24928317
复制相似问题