折线多边形?

时间:2014-05-23 07:34:52

标签: google-maps math google-maps-api-3

我正在尝试自动从折线创建多边形 到目前为止,我仍然坚持在折线的每个部分上正确计算外推边。

条件 - 基线和边之间的距离是常数。

Polyline from Polygon blueprint

  • 如何从基点(红色点)计算边(角点)的角点?

2 个答案:

答案 0 :(得分:1)

让两个相邻边(红色段)分别为AB和BC(在顶点B相交)。
查找标准化(单位)向量 ab cb Calc单位平分矢量
b =标准化( ab + cb )(vector normalizing
平分段的计算长度(红点蓝点)为l=d/sin(fi)
 其中d是偏移量,fi是矢量 b ab 之间的角度:

fi = atan2(crossproduct(b,ab), dotproduct(b,ab))

查找偏移(蓝色)点

<强>乙&#39; = B + l * b

<强>乙&#39;&#39; = B - l * b

答案 1 :(得分:1)

这是我在Qt中的代码。这对我来说很好用

    QPolygonF projectPLineToScreenAsPolygon(QPolygonF pline, qreal halfWidth)
{
QPolygonF ret;
QLineF l2_last;
QLineF l4_last;
for(int i = 0; i < pline.size() - 2; i++){

float x1 = pline.at(i).x();
float y1 = pline.at(i).y();

float x2 = pline.at(i + 1).x();
float y2 = pline.at(i + 1).y();

float x3 = pline.at(i + 2).x();
float y3 = pline.at(i + 2).y();

float dist = sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
float dist2 = sqrt(((x3-x2)*(x3-x2))+((y3-y2)*(y3-y2)));

QLineF l1;
QLineF l2;
QLineF l3;
QLineF l4;

if(i > 0){
l1 = l2_last;
l3 = l4_last;

l2 = QLineF (QPointF(x2 + halfWidth * (y3 - y2) / dist2, y2 + halfWidth * (x2 - x3) / dist2), QPointF(x3 + halfWidth * (y3 - y2) / dist2, y3 + halfWidth * (x2 - x3) / dist2));
l4 = QLineF (QPointF(x2 - halfWidth * (y3 - y2) / dist2, y2 - halfWidth * (x2 - x3) / dist2), QPointF(x3 - halfWidth * (y3 - y2) / dist2, y3 - halfWidth * (x2 - x3) / dist2));
} else {
l2 = QLineF (QPointF(x2 + halfWidth * (y3 - y2) / dist2, y2 + halfWidth * (x2 - x3) / dist2), QPointF(x3 + halfWidth * (y3 - y2) / dist2, y3 + halfWidth * (x2 - x3) / dist2));
l4 = QLineF (QPointF(x2 - halfWidth * (y3 - y2) / dist2, y2 - halfWidth * (x2 - x3) / dist2), QPointF(x3 - halfWidth * (y3 - y2) / dist2, y3 - halfWidth * (x2 - x3) / dist2));

l1 = QLineF (QPointF(x1 + halfWidth * (y2 - y1) / dist, y1 + halfWidth * (x1 - x2) / dist), QPointF(x2 + halfWidth * (y2 - y1) / dist, y2 + halfWidth * (x1 - x2) / dist));
l3 = QLineF (QPointF(x1 - halfWidth * (y2 - y1) / dist, y1 - halfWidth * (x1 - x2) / dist), QPointF(x2 - halfWidth * (y2 - y1) / dist, y2 - halfWidth * (x1 - x2) / dist));
}
l2_last = l2;
l4_last = l4;

QPointF pi1;

if(i == 0){
ret.append(l1.p1());
ret.prepend(l3.p1());
}

if(l1.intersect(l2, &pi1) != QLineF::NoIntersection){
ret.append(pi1);
} else {
ret.append(l2.p1());
}

QPointF pi2;
if(l3.intersect(l4, &pi2) != QLineF::NoIntersection){
ret.prepend(pi2);
} else {
ret.prepend(l4.p1());
}

if(i == pline.size() - 3){
ret.append(l2.p2());
ret.append(l4.p2());
}
}
return ret;
}