2014-05-23 122 views
3

我試圖從多段線自動創建一個多邊形 到目前爲止,我堅持正確計算多段線每個部分上的外推邊。來自多段線的多邊形?

條件 - 基線與邊之間的距離是常數。

Polyline from Polygon blueprint

  • 如何計算從據點(紅的)邊(藍點)的角點?
+0

多義線的長度是多少? –

+1

你想[緩衝](http://stackoverflow.com/search?q=%5Bgoogle-maps%5D+buffer+polyline)折線。 – geocodezip

+0

多段線的長度約爲100米,整體約爲幾公里。 –

回答

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; 
} 
1

讓我們兩個相鄰邊緣(紅色線段)是AB和BC(在頂點B相交)。
查找標準化(單位)載體abcb
計算值單元平分線矢量
b =歸一化的(AB + CB)(vector normalizing
平分線節段的計算值長度(紅點藍點)作爲l=d/sin(fi)
其中d是偏移量,和FI是矢量bAB之間角度:

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

查找偏移(藍色)指出

'= + 1 * b

''= - L * b

+1

我想它會是'Math.atan2()' - 一個實際的代碼示例會很好。 – davidkonrad

+0

我不知道如何規範化它,既沒有關於B'和B「你可以請發表一些代碼塊的話題。在此先感謝:) –

+0

鏈接添加。你有沒有處理矢量代數?這是絕對必要的幾何工作 – MBo