kaifuzi 发表于 2016-10-11 18:51:00

如何将直线圆弧连接起来

如何将直线圆弧连接起来形成多段线,类似于Join命令。
其实我是想创建一个带倒圆角的矩形。我现在是单独创了4个圆弧和4根直线,之后想把这4个圆弧和4根直线合并。
或者有没有更简单的办法来创建带倒圆角的矩形?

雪山飞狐_lzh 发表于 2016-10-11 19:35:00

参考我的曲线转换类的ge3dex部分 有个topolyline 是把ge复合曲线转成pl的 和你的要求差不多

kaifuzi 发表于 2016-10-11 21:20:00


其实我是想创建一个带倒圆角的矩形。我现在是单独创了4个圆弧和4根直线,之后想把这4个圆弧和4根直线合并。
或者有没有更简单的办法来创建带倒圆角的矩形?

kaifuzi 发表于 2016-10-11 21:22:00

Friend Function CreateArcRectanglePolyline(ByVal acTrans As Transaction, ByVal acBlkTblRec As BlockTableRecord, ByVal sLayerName As String, ByVal rad As Double, _
                                             ByVal ptLowLeft As Point2d, ByVal ptLowRight As Point2d, ByVal ptTopRight As Point2d, ByVal ptTopLeft As Point2d) As Polyline
      Dim acArc1 As Arc = New Arc(New Point3d(ptLowLeft.X + rad, ptLowLeft.Y + rad, 0), rad, Math.PI, 1.5 * Math.PI)'左下角倒圆角
      Dim acLine1 As Line = New Line(New Point3d(ptLowLeft.X + rad, ptLowLeft.Y, 0), New Point3d(ptLowRight.X - rad, ptLowRight.Y, 0))
      Dim acArc2 As Arc = New Arc(New Point3d(ptLowRight.X - rad, ptLowRight.Y + rad, 0), rad, 1.5 * Math.PI, 2 * Math.PI)'右下角倒圆角
      Dim acLine2 As Line = New Line(New Point3d(ptLowRight.X, ptLowRight.Y + rad, 0), New Point3d(ptTopRight.X, ptTopRight.Y - rad, 0))
      Dim acArc3 As Arc = New Arc(New Point3d(ptTopRight.X - rad, ptTopRight.Y - rad, 0), rad, 0, 0.5 * Math.PI)'右上角倒圆角
      Dim acLine3 As Line = New Line(New Point3d(ptTopRight.X - rad, ptTopRight.Y, 0), New Point3d(ptTopLeft.X + rad, ptTopLeft.Y, 0))
      Dim acArc4 As Arc = New Arc(New Point3d(ptTopLeft.X + rad, ptTopLeft.Y - rad, 0), rad, 0.5 * Math.PI, Math.PI)'左上角倒圆角
      Dim acLine4 As Line = New Line(New Point3d(ptTopLeft.X, ptTopRight.Y - rad, 0), New Point3d(ptLowLeft.X, ptLowLeft.Y + rad, 0))
      Dim acPoly As Polyline = New Polyline()
      '将新对象添加到块表记录和事务
      acBlkTblRec.AppendEntity(acArc1)
      acTrans.AddNewlyCreatedDBObject(acArc1, True)
      acBlkTblRec.AppendEntity(acLine1)
      acTrans.AddNewlyCreatedDBObject(acLine1, True)
      acBlkTblRec.AppendEntity(acArc2)
      acTrans.AddNewlyCreatedDBObject(acArc2, True)
      acBlkTblRec.AppendEntity(acLine2)
      acTrans.AddNewlyCreatedDBObject(acLine2, True)
      acBlkTblRec.AppendEntity(acArc3)
      acTrans.AddNewlyCreatedDBObject(acArc3, True)
      acBlkTblRec.AppendEntity(acLine3)
      acTrans.AddNewlyCreatedDBObject(acLine3, True)
      acBlkTblRec.AppendEntity(acArc4)
      acTrans.AddNewlyCreatedDBObject(acArc4, True)
      acBlkTblRec.AppendEntity(acLine4)
      acTrans.AddNewlyCreatedDBObject(acLine4, True)
      
      Return acPoly
    End Function

kaifuzi 发表于 2016-10-11 21:27:00


请问哪里可以找到ge3dex这个类,我在贴子中没搜到哦。

雪山飞狐_lzh 发表于 2016-10-11 21:45:00

http://bbs.mjtd.com/forum.php?mod=viewthread&tid=77565&mobile=2

kaifuzi 发表于 2016-10-12 10:07:00


    Friend Function CreateArcRectanglePolyline(ByVal acTrans As Transaction, ByVal acBlkTblRec As BlockTableRecord, ByVal sLayerName As String, ByVal rad As Double, _
                                             ByVal ptLowLeft As Point2d, ByVal ptLowRight As Point2d, ByVal ptTopRight As Point2d, ByVal ptTopLeft As Point2d) As Polyline
      '每部分单独来创建倒圆角矩形
      'Dim acArc1 As Arc = New Arc(New Point3d(ptLowLeft.X + rad, ptLowLeft.Y + rad, 0), rad, Math.PI, 1.5 * Math.PI)'左下角倒圆角
      'Dim acLine1 As Line = New Line(New Point3d(ptLowLeft.X + rad, ptLowLeft.Y, 0), New Point3d(ptLowRight.X - rad, ptLowRight.Y, 0))
      'Dim acArc2 As Arc = New Arc(New Point3d(ptLowRight.X - rad, ptLowRight.Y + rad, 0), rad, 1.5 * Math.PI, 2 * Math.PI)'右下角倒圆角
      'Dim acLine2 As Line = New Line(New Point3d(ptLowRight.X, ptLowRight.Y + rad, 0), New Point3d(ptTopRight.X, ptTopRight.Y - rad, 0))
      'Dim acArc3 As Arc = New Arc(New Point3d(ptTopRight.X - rad, ptTopRight.Y - rad, 0), rad, 0, 0.5 * Math.PI)'右上角倒圆角
      'Dim acLine3 As Line = New Line(New Point3d(ptTopRight.X - rad, ptTopRight.Y, 0), New Point3d(ptTopLeft.X + rad, ptTopLeft.Y, 0))
      'Dim acArc4 As Arc = New Arc(New Point3d(ptTopLeft.X + rad, ptTopLeft.Y - rad, 0), rad, 0.5 * Math.PI, Math.PI)'左上角倒圆角
      'Dim acLine4 As Line = New Line(New Point3d(ptTopLeft.X, ptTopRight.Y - rad, 0), New Point3d(ptLowLeft.X, ptLowLeft.Y + rad, 0))
      ''将新对象添加到块表记录和事务
      'acBlkTblRec.AppendEntity(acArc1)
      'acTrans.AddNewlyCreatedDBObject(acArc1, True)
      'acBlkTblRec.AppendEntity(acLine1)
      'acTrans.AddNewlyCreatedDBObject(acLine1, True)
      'acBlkTblRec.AppendEntity(acArc2)
      'acTrans.AddNewlyCreatedDBObject(acArc2, True)
      'acBlkTblRec.AppendEntity(acLine2)
      'acTrans.AddNewlyCreatedDBObject(acLine2, True)
      'acBlkTblRec.AppendEntity(acArc3)
      'acTrans.AddNewlyCreatedDBObject(acArc3, True)
      'acBlkTblRec.AppendEntity(acLine3)
      'acTrans.AddNewlyCreatedDBObject(acLine3, True)
      'acBlkTblRec.AppendEntity(acArc4)
      'acTrans.AddNewlyCreatedDBObject(acArc4, True)
      'acBlkTblRec.AppendEntity(acLine4)
      'acTrans.AddNewlyCreatedDBObject(acLine4, True)
      Dim acPoly As Polyline = New Polyline()
      acPoly.Layer = sLayerName
      acPoly.AddVertexAt(0, New Point2d(ptLowLeft.X, ptLowLeft.Y + rad), Math.Tan(0.5 * Math.PI / 4), 0, 0)'左下角倒圆角起点
      acPoly.AddVertexAt(1, New Point2d(ptLowLeft.X + rad, ptLowLeft.Y), 0, 0, 0)'左下角倒圆角终点
      acPoly.AddVertexAt(2, New Point2d(ptLowRight.X - rad, ptLowRight.Y), Math.Tan(0.5 * Math.PI / 4), 0, 0)'右下角倒圆角起点
      acPoly.AddVertexAt(3, New Point2d(ptLowRight.X, ptLowRight.Y + rad), 0, 0, 0)'右下角倒圆角终点
      acPoly.AddVertexAt(4, New Point2d(ptTopRight.X, ptTopRight.Y - rad), Math.Tan(0.5 * Math.PI / 4), 0, 0)'右上角倒圆角起点
      acPoly.AddVertexAt(5, New Point2d(ptTopRight.X - rad, ptTopRight.Y), 0, 0, 0)'右上角倒圆角终点
      acPoly.AddVertexAt(6, New Point2d(ptTopLeft.X + rad, ptTopLeft.Y), Math.Tan(0.5 * Math.PI / 4), 0, 0)'左上角倒圆角起点
      acPoly.AddVertexAt(7, New Point2d(ptTopLeft.X, ptTopLeft.Y - rad), 0, 0, 0)'左上角倒圆角终点
      acPoly.Closed = True'闭合多段线
      '将新对象添加到块表记录和事务
      acBlkTblRec.AppendEntity(acPoly)
      acTrans.AddNewlyCreatedDBObject(acPoly, True)
      Return acPoly
    End Function

kaifuzi 发表于 2016-10-12 10:09:00

http://379910987.blog.163.com/blog/static/33523797201011184552167/

630051689 发表于 2017-7-29 15:41:00


我的土办法,还挺管用的
Public Sub 转为多段线()
      Dim dm As DocumentCollection = Application.DocumentManager
      Dim ed As Editor = dm.MdiActiveDocument.Editor
      '获取当前数据库作为目标数据库
      Dim Db As Database = dm.MdiActiveDocument.Database
      Dim 起始图形 As Entity
      Dim pl As Polyline
      '拾取对象----------------------------------------------------------
      Dim optEnt As New PromptEntityOptions(vbCrLf & "请选择对象")
      Dim resEnt As PromptEntityResult = ed.GetEntity(optEnt)
      If resEnt.Status = PromptStatus.OK Then
            Using trans As Transaction = Db.TransactionManager.StartTransaction()
                起始图形 = trans.GetObject(resEnt.ObjectId, OpenMode.ForWrite)
                pl = Polyline_Select.转换为多段线(起始图形, False)
                起始图形.Erase()
                Db.AddToCurrentSpace(pl)
                Dim resSel As PromptSelectionResult = ed.SelectAll
                ' 得到选择集对象.
                Dim sSet As SelectionSet = resSel.Value
                ' 得到选择集中所有对象的ObjectId集合.
                Dim ids As ObjectId() = sSet.GetObjectIds()
                Dim rb As ResultBuffer = New ResultBuffer
                rb.Add(New TypedValue(ResBufCode.String, "_PEDIT"))
                rb.Add(New TypedValue(ResBufCode.ObjectId, pl.ObjectId))
                rb.Add(New TypedValue(ResBufCode.String, "_J"))
                rb.Add(New TypedValue(ResBufCode.PickSet, sSet))
                ed.AcedCmd(rb)
                dm.MdiActiveDocument.SendCommand("")
                trans.Commit()
            End Using
      End If
    End Sub
Public Shared Function 转换为多段线(ent As Entity, ByRef isOK As Boolean) As Polyline
      Dim pl As Polyline = New Polyline
      Dim l As Line
      Dim ac As Arc
      Dim pol As Polyline = New Polyline
      isOK = False
      Try
            If TypeOf ent Is Line Then
                l = ent
                pl.AddVertexAt(0, New Point2d(l.StartPoint.X, l.StartPoint.Y), 0, 0, 0)
                pl.AddVertexAt(1, New Point2d(l.EndPoint.X, l.EndPoint.Y), 0, 0, 0)
                isOK = True
            ElseIf TypeOf ent Is Arc Then
                ac = ent
                Dim 角度差 As Double = ac.EndAngle - ac.StartAngle
                If 角度差 < 0.0 Then 角度差 += Math.PI * 2
                Dim tD As Double = Math.Tan(角度差 / 4)
                pl.AddVertexAt(0, New Point2d(ac.StartPoint.X, ac.StartPoint.Y), tD, 0, 0)
                pl.AddVertexAt(1, New Point2d(ac.EndPoint.X, ac.EndPoint.Y), tD, 0, 0)
                isOK = True
            ElseIf TypeOf ent Is Polyline Then
                pol = ent
                pl = pol.Clone
                isOK = True
            End If
      Catch
            MsgBox("转换失败")
      End Try
      Return pl
    End Function
页: [1]
查看完整版本: 如何将直线圆弧连接起来