来自多段线的多边形?(polygon from polyline?)

探讨了从多段线自动创建多边形的方法,重点在于计算每段多段线上的外推边,确保基线与边线间距离恒定。通过详细解析QPolygonF函数,展示了如何精确计算角点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

内容来源于互联网  原文地址https://www.it1352.com/825785.html

仅作为学习笔记用

 

 

I am trying to create a polygon from a polyline automatically So far I am stuck with the proper calculation of the extrapolated sides on each part of the polyline.

Condition - the distance between the base line, and the sides is a constant

Polyline from Polygon blueprint

How to calculate the corner points of the sides (blue points) from the base points (red ones )?

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


 

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

  • 如何计算边(蓝点)的角点基点(红色)?
 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(); ((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))); 
 
 float dist = sqrt ((x3-x2)*(x3-x2))+((y3-y2)*(y3-y2))); 
 float dist2 = sqrt 
 
 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 - 半宽*(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 - 半宽*(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-半宽*(y2-y1)/ dist,y1-半宽*(x1-x2)/ dist),QPointF(x2-半宽*(y2-y1)/ dist,y2 - 半宽*(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; 
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值