明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1382|回复: 8

如何将直线圆弧连接起来

[复制链接]
发表于 2016-10-11 18:51:47 | 显示全部楼层 |阅读模式
本帖最后由 kaifuzi 于 2016-10-11 21:22 编辑

如何将直线圆弧连接起来形成多段线,类似于Join命令。[em0]

其实我是想创建一个带倒圆角的矩形。我现在是单独创了4个圆弧和4根直线,之后想把这4个圆弧和4根直线合并。

或者有没有更简单的办法来创建带倒圆角的矩形?


发表于 2016-10-11 19:35:59 来自手机 | 显示全部楼层
参考我的曲线转换类的ge3dex部分 有个topolyline 是把ge复合曲线转成pl的 和你的要求差不多
 楼主| 发表于 2016-10-11 21:20:06 | 显示全部楼层
雪山飞狐_lzh 发表于 2016-10-11 19:35
参考我的曲线转换类的ge3dex部分 有个topolyline 是把ge复合曲线转成pl的 和你的要求差不多

其实我是想创建一个带倒圆角的矩形。我现在是单独创了4个圆弧和4根直线,之后想把这4个圆弧和4根直线合并。
或者有没有更简单的办法来创建带倒圆角的矩形?
 楼主| 发表于 2016-10-11 21:22:59 | 显示全部楼层
  1. Friend Function CreateArcRectanglePolyline(ByVal acTrans As Transaction, ByVal acBlkTblRec As BlockTableRecord, ByVal sLayerName As String, ByVal rad As Double, _
  2.                                                ByVal ptLowLeft As Point2d, ByVal ptLowRight As Point2d, ByVal ptTopRight As Point2d, ByVal ptTopLeft As Point2d) As Polyline
  3.         Dim acArc1 As Arc = New Arc(New Point3d(ptLowLeft.X + rad, ptLowLeft.Y + rad, 0), rad, Math.PI, 1.5 * Math.PI)  '左下角倒圆角
  4.         Dim acLine1 As Line = New Line(New Point3d(ptLowLeft.X + rad, ptLowLeft.Y, 0), New Point3d(ptLowRight.X - rad, ptLowRight.Y, 0))
  5.         Dim acArc2 As Arc = New Arc(New Point3d(ptLowRight.X - rad, ptLowRight.Y + rad, 0), rad, 1.5 * Math.PI, 2 * Math.PI)  '右下角倒圆角
  6.         Dim acLine2 As Line = New Line(New Point3d(ptLowRight.X, ptLowRight.Y + rad, 0), New Point3d(ptTopRight.X, ptTopRight.Y - rad, 0))
  7.         Dim acArc3 As Arc = New Arc(New Point3d(ptTopRight.X - rad, ptTopRight.Y - rad, 0), rad, 0, 0.5 * Math.PI)  '右上角倒圆角
  8.         Dim acLine3 As Line = New Line(New Point3d(ptTopRight.X - rad, ptTopRight.Y, 0), New Point3d(ptTopLeft.X + rad, ptTopLeft.Y, 0))
  9.         Dim acArc4 As Arc = New Arc(New Point3d(ptTopLeft.X + rad, ptTopLeft.Y - rad, 0), rad, 0.5 * Math.PI, Math.PI)  '左上角倒圆角
  10.         Dim acLine4 As Line = New Line(New Point3d(ptTopLeft.X, ptTopRight.Y - rad, 0), New Point3d(ptLowLeft.X, ptLowLeft.Y + rad, 0))

  11.         Dim acPoly As Polyline = New Polyline()

  12.         '将新对象添加到块表记录和事务
  13.         acBlkTblRec.AppendEntity(acArc1)
  14.         acTrans.AddNewlyCreatedDBObject(acArc1, True)
  15.         acBlkTblRec.AppendEntity(acLine1)
  16.         acTrans.AddNewlyCreatedDBObject(acLine1, True)
  17.         acBlkTblRec.AppendEntity(acArc2)
  18.         acTrans.AddNewlyCreatedDBObject(acArc2, True)
  19.         acBlkTblRec.AppendEntity(acLine2)
  20.         acTrans.AddNewlyCreatedDBObject(acLine2, True)
  21.         acBlkTblRec.AppendEntity(acArc3)
  22.         acTrans.AddNewlyCreatedDBObject(acArc3, True)
  23.         acBlkTblRec.AppendEntity(acLine3)
  24.         acTrans.AddNewlyCreatedDBObject(acLine3, True)
  25.         acBlkTblRec.AppendEntity(acArc4)
  26.         acTrans.AddNewlyCreatedDBObject(acArc4, True)
  27.         acBlkTblRec.AppendEntity(acLine4)
  28.         acTrans.AddNewlyCreatedDBObject(acLine4, True)
  29.       

  30.         Return acPoly
  31.     End Function
 楼主| 发表于 2016-10-11 21:27:54 | 显示全部楼层
雪山飞狐_lzh 发表于 2016-10-11 19:35
参考我的曲线转换类的ge3dex部分 有个topolyline 是把ge复合曲线转成pl的 和你的要求差不多

请问哪里可以找到ge3dex这个类,我在贴子中没搜到哦。
发表于 2016-10-11 21:45:13 来自手机 | 显示全部楼层
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=77565&mobile=2
 楼主| 发表于 2016-10-12 10:07:50 | 显示全部楼层
本帖最后由 kaifuzi 于 2016-10-12 10:09 编辑

  1.     Friend Function CreateArcRectanglePolyline(ByVal acTrans As Transaction, ByVal acBlkTblRec As BlockTableRecord, ByVal sLayerName As String, ByVal rad As Double, _
  2.                                                ByVal ptLowLeft As Point2d, ByVal ptLowRight As Point2d, ByVal ptTopRight As Point2d, ByVal ptTopLeft As Point2d) As Polyline
  3.         '每部分单独来创建倒圆角矩形
  4.         'Dim acArc1 As Arc = New Arc(New Point3d(ptLowLeft.X + rad, ptLowLeft.Y + rad, 0), rad, Math.PI, 1.5 * Math.PI)  '左下角倒圆角
  5.         'Dim acLine1 As Line = New Line(New Point3d(ptLowLeft.X + rad, ptLowLeft.Y, 0), New Point3d(ptLowRight.X - rad, ptLowRight.Y, 0))
  6.         'Dim acArc2 As Arc = New Arc(New Point3d(ptLowRight.X - rad, ptLowRight.Y + rad, 0), rad, 1.5 * Math.PI, 2 * Math.PI)  '右下角倒圆角
  7.         'Dim acLine2 As Line = New Line(New Point3d(ptLowRight.X, ptLowRight.Y + rad, 0), New Point3d(ptTopRight.X, ptTopRight.Y - rad, 0))
  8.         'Dim acArc3 As Arc = New Arc(New Point3d(ptTopRight.X - rad, ptTopRight.Y - rad, 0), rad, 0, 0.5 * Math.PI)  '右上角倒圆角
  9.         'Dim acLine3 As Line = New Line(New Point3d(ptTopRight.X - rad, ptTopRight.Y, 0), New Point3d(ptTopLeft.X + rad, ptTopLeft.Y, 0))
  10.         'Dim acArc4 As Arc = New Arc(New Point3d(ptTopLeft.X + rad, ptTopLeft.Y - rad, 0), rad, 0.5 * Math.PI, Math.PI)  '左上角倒圆角
  11.         'Dim acLine4 As Line = New Line(New Point3d(ptTopLeft.X, ptTopRight.Y - rad, 0), New Point3d(ptLowLeft.X, ptLowLeft.Y + rad, 0))
  12.         ''将新对象添加到块表记录和事务
  13.         'acBlkTblRec.AppendEntity(acArc1)
  14.         'acTrans.AddNewlyCreatedDBObject(acArc1, True)
  15.         'acBlkTblRec.AppendEntity(acLine1)
  16.         'acTrans.AddNewlyCreatedDBObject(acLine1, True)
  17.         'acBlkTblRec.AppendEntity(acArc2)
  18.         'acTrans.AddNewlyCreatedDBObject(acArc2, True)
  19.         'acBlkTblRec.AppendEntity(acLine2)
  20.         'acTrans.AddNewlyCreatedDBObject(acLine2, True)
  21.         'acBlkTblRec.AppendEntity(acArc3)
  22.         'acTrans.AddNewlyCreatedDBObject(acArc3, True)
  23.         'acBlkTblRec.AppendEntity(acLine3)
  24.         'acTrans.AddNewlyCreatedDBObject(acLine3, True)
  25.         'acBlkTblRec.AppendEntity(acArc4)
  26.         'acTrans.AddNewlyCreatedDBObject(acArc4, True)
  27.         'acBlkTblRec.AppendEntity(acLine4)
  28.         'acTrans.AddNewlyCreatedDBObject(acLine4, True)

  29.         Dim acPoly As Polyline = New Polyline()
  30.         acPoly.Layer = sLayerName
  31.         acPoly.AddVertexAt(0, New Point2d(ptLowLeft.X, ptLowLeft.Y + rad), Math.Tan(0.5 * Math.PI / 4), 0, 0)  '左下角倒圆角起点
  32.         acPoly.AddVertexAt(1, New Point2d(ptLowLeft.X + rad, ptLowLeft.Y), 0, 0, 0)  '左下角倒圆角终点
  33.         acPoly.AddVertexAt(2, New Point2d(ptLowRight.X - rad, ptLowRight.Y), Math.Tan(0.5 * Math.PI / 4), 0, 0)  '右下角倒圆角起点
  34.         acPoly.AddVertexAt(3, New Point2d(ptLowRight.X, ptLowRight.Y + rad), 0, 0, 0)  '右下角倒圆角终点
  35.         acPoly.AddVertexAt(4, New Point2d(ptTopRight.X, ptTopRight.Y - rad), Math.Tan(0.5 * Math.PI / 4), 0, 0)  '右上角倒圆角起点
  36.         acPoly.AddVertexAt(5, New Point2d(ptTopRight.X - rad, ptTopRight.Y), 0, 0, 0)  '右上角倒圆角终点
  37.         acPoly.AddVertexAt(6, New Point2d(ptTopLeft.X + rad, ptTopLeft.Y), Math.Tan(0.5 * Math.PI / 4), 0, 0)  '左上角倒圆角起点
  38.         acPoly.AddVertexAt(7, New Point2d(ptTopLeft.X, ptTopLeft.Y - rad), 0, 0, 0)  '左上角倒圆角终点
  39.         acPoly.Closed = True  '闭合多段线

  40.         '将新对象添加到块表记录和事务
  41.         acBlkTblRec.AppendEntity(acPoly)
  42.         acTrans.AddNewlyCreatedDBObject(acPoly, True)

  43.         Return acPoly
  44.     End Function
 楼主| 发表于 2016-10-12 10:09:36 | 显示全部楼层
http://379910987.blog.163.com/blog/static/33523797201011184552167/
发表于 2017-7-29 15:41:57 | 显示全部楼层

我的土办法,还挺管用的

<CommandMethod("S2")> 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








您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-2-23 02:30 , Processed in 0.147110 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表