明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2972|回复: 1

在UCS中怎么画图?

[复制链接]
发表于 2004-5-29 20:51:00 | 显示全部楼层 |阅读模式
论坛的CAD高级应用版有个画“偏心圆台”的问题。我写了程序,可只能在WCS中画,在UCS中画的问题一直没解决,请高手相助!
  1. Imports Autodesk.AutoCAD.ApplicationServices
  2. Imports Autodesk.AutoCAD.DatabaseServices
  3. Imports Autodesk.AutoCAD.Runtime
  4. Imports Autodesk.AutoCAD.Interop
  5. Imports Autodesk.AutoCAD.Interop.Common
  6. Imports System.MathPublic Class Class1_程序
  7.        '公用设置
  8.        Const pi = 3.1415926535
  9.        Dim app As AcadApplication = Application.AcadApplication
  10.        Dim doc As AcadDocument = app.ActiveDocument
  11.        Dim ms As Object = doc.ModelSpace
  12.        Dim ut As Object = doc.Utility       '------------------------函数库------------------------------
  13.        Function dis(ByVal pa As Object, ByVal pb As Object) As Double
  14.                Return Sqrt((pa(0) - pb(0)) ^ 2 + (pa(1) - pb(1)) ^ 2 + (pa(2) - pb(2)) ^ 2)
  15.        End Function
  16. <CommandMethod("px")> Sub Cmd5_偏心圆台()               MsgBox("程序将在世界坐标系中画偏心圆台!", , "AutoCAD 2005")
  17.                doc.SendCommand("UCS" & vbCr & "w" & vbCr)
  18.                Dim point As Object = ut.GetPoint(, "请输入偏心圆台的底面中心点:")
  19.                Dim R1 As Double = ut.GetDistance(point, "请输入偏心圆台的底面半径:")
  20.                Dim h As Double = ut.GetDistance(point, "请输入偏心圆台的高度:")
  21.                Dim R2 As Double = ut.GetDistance(point, "请输入偏心圆台的顶面半径:")
  22.                Dim d As Double = ut.GetDistance(point, "请输入偏心圆台的偏心距离:")               If R2 >= R1 Then
  23.                        MsgBox("因工作较忙,程序尚未全部完成,只能画顶面半径小于底面半径的偏心圆台!", , "AutoCAD 2005")
  24.                        Exit Sub
  25.                End If
  26.                Dim h1 As Double = h * R1 / (R1 - R2)
  27.                Dim dd As Double = h1 * d / h               Dim p0(2) As Double : Dim p1(2) As Double
  28.                Dim p2(2) As Double : Dim p3(2) As Double
  29.                p0(0) = dd + point(0) : p0(1) = point(1) : p0(2) = h1 + point(2)
  30.                p1(0) = R1 + point(0) : p1(1) = point(1) : p1(2) = point(2)
  31.                p2(0) = -R1 + point(0) : p2(1) = point(1) : p2(2) = point(2)               Dim L1 As Double = dis(p1, p0)
  32.                Dim L2 As Double = dis(p2, p0)               p3(0) = R1 * (L2 - L1) / (L1 + L2) + point(0)
  33.                p3(1) = point(1) : p3(2) = point(2)               Dim L3 As Double = dis(p3, p0)
  34.                Dim L12 As Double = dis(p1, p2)
  35.                Dim L13 As Double = dis(p1, p3)
  36.                Dim L23 As Double = dis(p2, p3)               Dim e As Double = (L2 ^ 2 + L3 ^ 2 - L23 ^ 2) / (2 * L2 * L3)
  37.                Dim ang As Double = Atan(-e / Sqrt(-e * e + 1)) + 2 * Atan(1)               Dim b As Double = L3 * Tan(ang)
  38.                Dim a As Double = Sqrt(L23 * L13)               Dim EL As Acad3DSolid _
  39.                = ms.AddEllipticalCone(p3, 2 * b, 2 * a, 2 * L3)               Dim e2 As Double _
  40.                = (L23 ^ 2 + L3 ^ 2 - L2 ^ 2) / (2 * L23 * L3)
  41.                Dim ang2 As Double _
  42.                = Atan(-e2 / Sqrt(-e2 * e2 + 1)) + 2 * Atan(1) - 0.5 * pi               Dim p333(2) As Double
  43.                p333(0) = p3(0) : p333(1) = p3(1) + 1 : p333(2) = p3(2)
  44.                EL.Rotate3D(p3, p333, ang2)               Dim spt1(2) As Double, spt2(2) As Double
  45.                Dim spt3(2) As Double
  46.                Dim sliceObj As Acad3DSolid
  47.                spt1(0) = point(0) : spt1(1) = point(1) : spt1(2) = point(2)
  48.                spt2(0) = point(0) : spt2(1) = point(1) + 1 : spt2(2) = point(2)
  49.                spt3(0) = point(0) + 1 : spt3(1) = point(1) : spt3(2) = point(2)
  50.                sliceObj = EL.SliceSolid(spt1, spt2, spt3, False)               spt1(0) = point(0) : spt1(1) = point(1) : spt1(2) = point(2) + h
  51.                spt2(0) = point(0) + 1 : spt2(1) = point(1) : spt2(2) = point(2) + h
  52.                spt3(0) = point(0) : spt3(1) = point(1) + 1 : spt3(2) = point(2) + h
  53.                sliceObj = EL.SliceSolid(spt1, spt2, spt3, False)
  54.                doc.Regen(AcRegenType.acAllViewports)
  55.                app.ZoomExtents()       End SubEnd Class
TranslateCoordinates 方法我也用了,可还是……

 楼主| 发表于 2004-5-29 21:03:00 | 显示全部楼层
TranslateCoordinates 方法我也用了,可还是……
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-28 04:19 , Processed in 0.134483 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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