再次向您问好
我有一个外部参照,它是一个分解的多面网格,因此由三角形面组成。我正在编写代码,用网格中的三角形计算一条线上的高度。我已经写了一个版本,它可以工作,但速度很慢——对于折线上的每个点,它会遍历网格中的每个三角形,直到找到该点所在的三角形,然后对其进行插值。所以我想我可以通过减少要循环的三角形数量来加快速度,通过找出哪些三角形与折线相交,然后我只需要循环这些三角形。问题是我的代码不起作用——它说网格中的每个三角形都与直线相交。
代码如下(这只是用来过滤三角形的位,而不是插值位):
- Sub LevelFromTria2()
- Dim objPLine As AcadLWPolyline
- Dim objTria As Acad3DFace
- Dim varCoords As Variant '
- Dim objBlock As AcadBlock
- Dim lngCount As Long
- Dim objTriaSides As AcadLWPolyline
- Dim varIntPoints As Variant
- Dim dblTriaSidesCoords(0 To 5) As Double
- Dim varPnt As Variant
-
-
- On Error Resume Next '* Do so that if layer exists no error
- ThisDrawing.Layers.Add ("Temp Triangles")
- On Error GoTo 0
- ThisDrawing.Utility.GetEntity objPLine, varPnt, "Select polyline: "
- Set objBlock = ThisDrawing.Blocks("draw tria exploded")
-
- '* Go through all the items in the xref
- For lngCount = 0 To objBlock.Count - 1
-
- '* See if the item is a 3d face
- If objBlock.Item(lngCount).ObjectName = "AcDbFace" Then
- '* If it is get the face element
- Set objTria = objBlock.Item(lngCount)
- '* See if the face intersects with the polyline
- varIntPoints = objTria.IntersectWith(objPLine, acExtendNone)
-
- '* If it does, draw the triangle - TEMP MEASURE TO SEE IF IT IS FINDING THE RIGHT TRIANGLES
- If VarType(varIntPoints) vbEmpty Then
- '* Get co-ords of the 3d face
- varCoords = objTria.Coordinates
- '* Set up 2d coords for the triangle edge
- dblTriaSidesCoords(0) = varCoords(0)
- dblTriaSidesCoords(1) = varCoords(1)
- dblTriaSidesCoords(2) = varCoords(3)
- dblTriaSidesCoords(3) = varCoords(4)
- dblTriaSidesCoords(4) = varCoords(6)
- dblTriaSidesCoords(5) = varCoords(7)
- '* Add a LW polyline to show the triangle which intersects with the polyline
- Set objTriaSides = ThisDrawing.ModelSpace.AddLightWeightPolyline(dblTriaSidesCoords)
- objTriaSides.Closed = True
- objTriaSides.Layer = "Temp Triangles"
- objTriaSides.color = acMagenta
- objTriaSides.Update
- End If
-
- End If
-
- Next lngCount
-
- End Sub
附件是我正在测试的图纸。我试图得到水平的线是黄线,所以当提示时选择这个。
我想我的intersect方法有问题。除了使用面本身,我还试着用它做了一条LW折线,但是也不行。
对于如何实现上述功能,我们将非常感谢您的任何建议。(或者,如果你有另一个概念来加速它从三角测量到直线上的方式,我也很想听听!)
谢谢
乔恩
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |