개정판 a6dfdec2
QEngineeringLineItem의 Intersect 부분 수정
DTI_PID/DTI_PID/Shapes/QEngineeringLineItem.py | ||
---|---|---|
14 | 14 |
|
15 | 15 |
from QGraphicsPolylineItem import QGraphicsPolylineItem |
16 | 16 |
from QGraphicsBoundingBoxItem import QGraphicsBoundingBoxItem |
17 |
import shapely |
|
17 | 18 |
|
18 | 19 |
class QEngineeringLineItem(QGraphicsPolylineItem): |
19 | 20 |
removed = pyqtSignal(QGraphicsPathItem) |
... | ... | |
200 | 201 |
@brief get intersection point between this and given line |
201 | 202 |
@author humkyung |
202 | 203 |
@date 2018.04.21 |
204 |
@history Jeongwoo 2018.05.15 Add normalize |
|
203 | 205 |
''' |
204 | 206 |
def intersection(self, line): |
207 |
import math |
|
205 | 208 |
from shapely.geometry import Point, LineString |
206 | 209 |
|
207 | 210 |
startPt = self.startPoint() |
208 | 211 |
endPt = self.endPoint() |
209 |
lhs = LineString([(startPt[0], startPt[1]), (endPt[0], endPt[1])]) |
|
212 |
dx = endPt[0] - startPt[0] |
|
213 |
dy = endPt[1] - startPt[1] |
|
214 |
length = math.sqrt(dx*dx + dy*dy) |
|
215 |
dx /= length |
|
216 |
dy /= length |
|
217 |
lhs = LineString([(startPt[0] - dx*20, startPt[1] - dy*20), (endPt[0] + dx*20, endPt[1] + dy*20)]) |
|
210 | 218 |
rhs = LineString(line) |
211 | 219 |
return lhs.intersection(rhs) |
212 | 220 |
|
... | ... | |
214 | 222 |
@brief check if two lines are connectable |
215 | 223 |
@author humkyung |
216 | 224 |
@date 2018.05.12 |
225 |
@history Jeongwoo 18.05.15 Add check pt's type |
|
217 | 226 |
''' |
218 | 227 |
def isConnectable(self, line): |
219 | 228 |
import math |
... | ... | |
226 | 235 |
length = math.sqrt(dx*dx + dy*dy) |
227 | 236 |
dx /= length |
228 | 237 |
dy /= length |
229 |
extendedLine = [(startPt[0]+dx*20, startPt[1]+dy*20), (endPt[0]-dx*20, endPt[1]-dy*20)]
|
|
238 |
extendedLine = [(startPt[0] - dx*20, startPt[1] - dy*20), (endPt[0] + dx*20, endPt[1] + dy*20)]
|
|
230 | 239 |
pt = self.intersection(extendedLine) |
231 | 240 |
|
232 |
return (pt is not None) |
|
241 |
return (pt is not None) and (type(pt) == shapely.geometry.point.Point)
|
|
233 | 242 |
|
234 | 243 |
''' |
235 | 244 |
@brief connect line and symbol is able to be connected and return symbol |
내보내기 Unified diff