乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 141|回复: 10

不同ucs中的圆柱体

[复制链接]

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-11-17 14:52:08 | 显示全部楼层 |阅读模式
好的,我又把自己难住了。我试图定义一个新的ucs并在ucs中绘制一个圆柱体,而不是wcs。这是我到目前为止的代码
  1. Public Sub ucstest()
  2.     Dim ucsObj As AcadUCS
  3.     Dim origin As Variant
  4.     Dim xAxisPnt(0 To 2) As Double
  5.     Dim yAxisPnt(0 To 2) As Double
  6.     Dim ucsorigion(0 To 2) As Double
  7.     ' Define the UCS
  8.     origin = Null
  9.     origin = ThisDrawing.Utility.GetPoint
  10.     xAxisPnt(0) = origin(0): xAxisPnt(1) = origin(1): xAxisPnt(2) = origin(2) - 1
  11.     yAxisPnt(0) = origin(0): yAxisPnt(1) = origin(1) + 1: yAxisPnt(2) = origin(2)
  12.     ' Add the UCS to the UserCoordinatesSystems collection
  13.     Set ucsObj = ThisDrawing.UserCoordinateSystems.Add(origin, xAxisPnt, yAxisPnt, "New_UCS")
  14.     ThisDrawing.ActiveUCS = ucsObj
  15.     ThisDrawing.ModelSpace.AddCylinder origin, 1, 3
  16. End Sub

我认为我需要以某种方式转换我的坐标,但我从来没有这样做过,所以有什么想法我应该做什么?

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

4

主题

206

帖子

6

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
271
发表于 2006-11-17 14:53:20 | 显示全部楼层
气缸使用这种
变体在WCS,我认为这是我的问题
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-11-17 14:55:46 | 显示全部楼层
当您插入圆时,它会插入世界坐标,但它会假设currnt ucs的法线。将circle.normal设置为0,0,1,然后使用ucs矩阵转换圆
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-11-17 15:51:47 | 显示全部楼层
如果你只是想画一个圆圈并挤出,继续...
...但是
有一个圆柱体命令,它要求第一个末端中心和半径,然后提示“圆柱体的高度或[另一端的中心]”,它允许您将另一端的中心放置在空间中的任何位置,而不管UCS如何。 可能值得调查。
回复

使用道具 举报

6

主题

103

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
127
发表于 2006-11-17 16:23:21 | 显示全部楼层
它真的很脏,但我的大脑正在关闭。
这是有效的,但有一些怪癖:
1-你选择一条定义圆柱体位置的线
2-你选择线的中点b/c圆柱体被形心放置
3-你必须选择线的第三个点perp(正交/极性on是一件好事)
  1. Public Sub ucstest()
  2.     Dim origin As Variant
  3.     Dim xAxisPnt As Variant
  4.     Dim yAxisPnt(0 To 2) As Double
  5.     Dim ucsorigion(0 To 2) As Double
  6.     Dim objcyl As Acad3DSolid
  7.     Dim dblLength As Double
  8.     Dim objLine As AcadLine
  9.     Dim varpick As Variant
  10.     Dim obje As AcadEntity
  11.     ThisDrawing.Utility.GetEntity obje, varpick
  12.     Set objLine = obje
  13.     dblLength = objLine.Length
  14.     origin = Null
  15.     origin = ThisDrawing.Utility.GetPoint
  16.     xAxisPnt = ThisDrawing.Utility.GetPoint(origin)
  17.     Set objcyl = ThisDrawing.ModelSpace.AddCylinder(origin, 1, dblLength)
  18.     Dim ang As Double
  19.     ang = 90
  20.     ang = ang * 3.141592 / 180#
  21.     objcyl.Rotate3D origin, xAxisPnt, ang
  22. End Sub

周一需要更多的清理
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-11-17 16:34:56 | 显示全部楼层
这里有几个例子。
前2个使用法线,第三个使用ucs
  1. Public Sub CylinderFromLine()
  2.     Dim oCyl As Acad3DSolid
  3.     Dim oCircle As AcadCircle
  4.     Dim oLine As AcadLine
  5.     Dim varpick As Variant
  6.     Dim Ent As AcadEntity
  7.     Dim N, oReg
  8.     Dim RegEnt(0) As AcadEntity
  9.     Dim V(2) As Double
  10.     Dim Unit As Double
  11.     Dim Vn(2) As Double
  12.     Dim P1, P2
  13.    
  14.     ThisDrawing.Utility.GetEntity Ent, varpick
  15.     If Not TypeOf Ent Is AcadLine Then Exit Sub
  16.     Set oLine = Ent
  17.    ' V = oLine.Delta 'Don't use the treacherous delta
  18.     P1 = oLine.StartPoint: P2 = oLine.EndPoint
  19.     V(0) = P2(0) - P1(0): V(1) = P2(1) - P1(1): V(2) = P2(2) - P1(2)
  20.    
  21.     'Normalise the vector(It's length=1)
  22.     Unit = Sqr(V(0) * V(0) + V(1) * V(1) + V(2) * V(2))
  23.     Vn(0) = V(0) / Unit: Vn(1) = V(1) / Unit: Vn(2) = V(2) / Unit
  24.    
  25.     Set oCircle = ThisDrawing.ModelSpace.AddCircle(oLine.StartPoint, 1)
  26.     oCircle.Normal = Vn
  27.     Set RegEnt(0) = oCircle
  28.     oReg = ThisDrawing.ModelSpace.AddRegion(RegEnt)
  29.     Set oCyl = ThisDrawing.ModelSpace.AddExtrudedSolid(oReg(0), oLine.Length, 0)
  30. End Sub
  31. Public Sub CylinderFromPoints()
  32.     'this mimics the Cylinder command
  33.     Dim oCyl As Acad3DSolid
  34.     Dim oCircle As AcadCircle
  35.     Dim Rad As Double
  36.     Dim P1, P2
  37.     Dim N, oReg
  38.     Dim dLength As Double
  39.     Dim RegEnt(0) As AcadEntity
  40.     Dim Util As AcadUtility
  41.    
  42.     Set Util = ThisDrawing.Utility
  43.     P1 = Util.GetPoint(, "Specify center point for base of cylinder:")
  44.     Rad = Util.GetDistance(ToUcs(P1), "Specify radius for base of cylinder:")
  45.     P2 = ThisDrawing.Utility.GetPoint(ToUcs(P1), "Specify center of other end of cylinder:")
  46.     Dim V(2) As Double
  47.     V(0) = P2(0) - P1(0): V(1) = P2(1) - P1(1): V(2) = P2(2) - P1(2)
  48.     Dim Unit As Double
  49.     Dim Vn(2) As Double
  50.     'Normalise the vector(It's length=1)
  51.     Unit = Sqr(V(0) * V(0) + V(1) * V(1) + V(2) * V(2))
  52.     Vn(0) = V(0) / Unit: Vn(1) = V(1) / Unit: Vn(2) = V(2) / Unit
  53.    
  54.     dLength = Sqr(V(0) ^ 2 + V(1) ^ 2 + V(2) ^ 2)
  55.     Set oCircle = ThisDrawing.ModelSpace.AddCircle(P1, Rad)
  56.     oCircle.Normal = Vn
  57.     Set RegEnt(0) = oCircle
  58.     oReg = ThisDrawing.ModelSpace.AddRegion(RegEnt)
  59.     Set oCyl = ThisDrawing.ModelSpace.AddExtrudedSolid(oReg(0), dLength, 0)
  60. End Sub
  61. Public Sub CylinderFromUcs()
  62.     Dim oUcs As AcadUCS
  63.     Dim Orig As Variant
  64.     Dim xAxisPnt(0 To 2) As Double
  65.     Dim yAxisPnt(0 To 2) As Double
  66.     Dim oCyl As Acad3DSolid
  67.    
  68.     Orig = ThisDrawing.Utility.GetPoint
  69.     Set oCyl = ThisDrawing.ModelSpace.AddCylinder(Zero, 1, 3)
  70.     ' Define the UCS
  71.     xAxisPnt(0) = 0: xAxisPnt(1) = 0: xAxisPnt(2) = -1
  72.     yAxisPnt(0) = 0: yAxisPnt(1) = 1: yAxisPnt(2) = 0
  73.     Set oUcs = ThisDrawing.UserCoordinateSystems.Add(Zero, xAxisPnt, yAxisPnt, "New_UCS")
  74.     oUcs.origin = Orig
  75.     oCyl.TransformBy oUcs.GetUCSMatrix
  76. End Sub
  77. Function ToUcs(pt As Variant) As Variant
  78.     ToUcs = ThisDrawing.Utility.TranslateCoordinates(pt, acWorld, acUCS, False)
  79. End Function
  80.    

回复

使用道具 举报

6

主题

103

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
127
发表于 2006-11-18 17:50:27 | 显示全部楼层
Bryco,这些工作完美。
现在,你能解释发生了什么,这样我就知道发生了什么,这样我就可以在将来使用它吗?干得好。
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-11-20 12:32:54 | 显示全部楼层
谢谢CmdrDuh。我本来打算尝试一篇关于这些东西的文章,但这需要一点时间。
请注意圆柱体以外的对象的Ucs方法,由于某种原因,圆柱体的工作方式与其他实体略有不同。
“帮助”表示“创建一个 3D 实心圆柱体,其基础位于 WCS 的 XY 平面上。通常你在世界中插入一些东西,确保正态是0,0,1,然后将其转换为你想要的ucs(或矩阵)。
回复

使用道具 举报

6

主题

103

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
127
发表于 2006-11-20 12:59:26 | 显示全部楼层
Bryco,我再次喜欢你的代码
感谢您的优雅
(Ya da ..)

>'J'<
回复

使用道具 举报

4

主题

206

帖子

6

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
271
发表于 2006-11-20 15:36:13 | 显示全部楼层
有几件事,在最后一个例子中,它使用“零”作为未定义。可能是来自其他地方的片段。
关于更好的事情:
我想我已经弄清楚了部分数学。P2-P1部分正在计算δX、delta Y和Z,对吗?我使用已知的XYZ坐标画了一些线,这就是看起来正在发生的事情。
现在我不完全确定发生了什么
[3]
在与这里的常驻数学大师在工作中交谈后,我的问题是oCircle.Normal不适用于V或Vn吗?我试过了,它确实有效。所以,我的最后一个问题是为什么你必须标准化向量?
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-7 00:43 , Processed in 0.992982 second(s), 73 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表