明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2935|回复: 4

我想计算将面域的形心移动到0,0点然后计算惯性矩,可奇次和偶次计算结果不一样

[复制链接]
发表于 2002-7-13 14:24 | 显示全部楼层 |阅读模式
我想计算将面域的形心移动到0,0点然后计算惯性矩,可奇次和偶次计算结果不一样,具体的说就是形心坐标第偶次计算又回到初始的位置:(,程序如下
Private Sub CommandButton1_Click()
    UserForm1.Hide
   
    Dim currUCS As AcadUCS
    Dim origin(0 To 2) As Double
        
    Dim Centroid As Variant
    Dim momentOfInertia As Variant
    Dim sset As AcadSelectionSet         'Define sset as a SelectionSet object
    'Set sset to a new selection set named SS1 (the name doesn't matter here)
    Set sset = ThisDrawing.SelectionSets.Add("SS1")
   
    sset.SelectOnScreen                  'Prompt user to select objects
   
    Dim ent As Object                    'Define ent as an object
    For Each ent In sset                 'Loop through the SelectionSet collection
        If ent.EntityName = "AcDbRegion" Then
            
            Centroid = ent.Centroid

            ' Create a UCS and makes it current
            Set currUCS = ThisDrawing.ActiveUCS
            
            origin(0) = Centroid(0): origin(1) = Centroid(1): origin(2) = 0
            currUCS.origin = origin
            
            ThisDrawing.ActiveUCS = currUCS

            momentOfInertia = ent.momentOfInertia

            MsgBox "Ix=" & Format(momentOfInertia(0) / 10000, "######.00") & "mm^4;Iy=" & Format(momentOfInertia(1) / 10000, "######.00") & "mm^4", , "被选择物体的惯性矩"
            
            End If
    Next ent

    sset.Delete
    UserForm1.Show

End Sub
发表于 2002-7-15 12:53 | 显示全部楼层

origin的原因

通过单步调试,我发现奇次和偶次计算时,currUCS.origin和ThisDrawing.ActiveUCS.origin不一样,暂未找到解决办法,有空我再试试。
 楼主| 发表于 2002-7-16 14:06 | 显示全部楼层

快来帮忙呀:(

帮我调试调试,我做不出来。
发表于 2002-7-16 16:03 | 显示全部楼层

找到原因了,先这样解决

本帖最后由 作者 于 2002-7-16 16:03:03 编辑

找到原因了,Thisdrawing.ActiveUCS是活动UCS而不是系统UCS,计算转动惯量时以Thisdrawing.ActiveUCS的原点为中心,第一次运行时,以面域形心(注意:形心坐标非零,即不是系统UCS原点)为惯性中心;第二次运行时,形心坐标计算以Thisdrawing.ActiveUCS为参照,为零,惯性中心为(0,0)即系统UCS原点与面域形心不同。
解决办法:在修改Thisdrawing.ActiveUCS前保存原点,MsgBox后恢复。请参考以下代码。
Private Sub CommandButton1_Click()
    UserForm1.Hide
    Dim temp(0 To 2) As Double
    Dim origin(0 To 2) As Double
    Dim Centroid As Variant
    Dim currUCS As AcadUCS
    Dim momentOfInertia As Variant
    Dim sset As AcadSelectionSet         'Define sset as a SelectionSet object
    'Set sset to a new selection set named SS1 (the name doesn't matter here)
    Set sset = ThisDrawing.SelectionSets.Add("SS1")
   
    sset.SelectOnScreen                  'Prompt user to select objects
    'save current UCS origin
   temp(0) = ThisDrawing.ActiveUCS.origin(0)
   temp(1) = ThisDrawing.ActiveUCS.origin(1)
   temp(2) = ThisDrawing.ActiveUCS.origin(2)
    Dim ent As Object                    'Define ent as an object
    For Each ent In sset                 'Loop through the SelectionSet collection
        If ent.EntityName = "AcDbRegion" Then
            
            Centroid = ent.Centroid

            ' Create a UCS and makes it current
            Set currUCS = ThisDrawing.ActiveUCS
           
            origin(0) = Centroid(0): origin(1) = Centroid(1): origin(2) = 0
            currUCS.origin = origin
            
            ThisDrawing.ActiveUCS = currUCS

            momentOfInertia = ent.momentOfInertia

            MsgBox "Ix=" & Format(momentOfInertia(0) / 10000, "######.00") & "mm^4;Iy=" & Format(momentOfInertia(1) / 10000, "######.00") & "mm^4", , "被选择物体的惯性矩"
        End If
    Next ent
    currUCS.origin = temp
    ThisDrawing.ActiveUCS = currUCS  'restore ActiveUCS origin
    sset.Delete
    UserForm1.Show
End Sub
 楼主| 发表于 2002-7-17 17:49 | 显示全部楼层

thx

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

本版积分规则

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

GMT+8, 2024-5-4 13:35 , Processed in 0.950525 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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