VBA 中Rotate3D 的应用。
在三维旋转的时候 我们很难找到旋转轴 也很难确定 我们要旋转的空间 角度。我通过旋转对象的轴线和 旋转方向上的一条直线,找到旋转平面,然后计算这个平面的法线方程。再计算两条直线的夹角,在平面内旋转这个角度就到了。三维旋转轴就是平面的法线,旋转的角度就是两条直线的夹角。
程序代码: | [ 复制代码到剪贴板 ] |
Sub Rotate3D_1()
On Error Resume Next
Dim Obj As AcadEntity
Dim PickPnt
Dim A As Double, B As Double, C As Double, D As Double
Dim P1 As Variant, P2 As Variant, P3 As Variant
Dim T(0 To 2) As Double
Dim L1 As Double, L2 As Double, L3 As Double
Dim J As Double
ThisDrawing.Utility.GetEntity Obj, PickPnt, "选择旋转对象:"
ThisDrawing.Utility.InitializeUserInput 1, ""
P1 = ThisDrawing.Utility.GetPoint(, "旋转对象轴线上一点:")
ThisDrawing.Utility.InitializeUserInput 1, ""
P2 = ThisDrawing.Utility.GetPoint(, "旋转对象轴线与旋转方向直线的交点:")
ThisDrawing.Utility.InitializeUserInput 1, ""
P3 = ThisDrawing.Utility.GetPoint(, "旋转方向直线上的另一点:")
KJPMFC P1, P2, P3, A, B, C, D
MsgBox A
'过平面法线的一点
T(0) = A * 10 + P2(0)
T(1) = B * 10 + P2(1)
T(2) = C * 10 + P2(2)
'计算空间两条直线的夹角
L1 = P2PDistance(P1, P2)
L2 = P2PDistance(P2, P3)
L3 = P2PDistance(P3, P1)
'利用余弦定理 a^2=b^2+c^2-2*b*c*cos(A)
J = Arccos((L1 * L1 + L2 * L2 - L3 * L3) / 2 / L1 / L2)
Obj.Rotate3d P2, T, -J
End Sub
On Error Resume Next
Dim Obj As AcadEntity
Dim PickPnt
Dim A As Double, B As Double, C As Double, D As Double
Dim P1 As Variant, P2 As Variant, P3 As Variant
Dim T(0 To 2) As Double
Dim L1 As Double, L2 As Double, L3 As Double
Dim J As Double
ThisDrawing.Utility.GetEntity Obj, PickPnt, "选择旋转对象:"
ThisDrawing.Utility.InitializeUserInput 1, ""
P1 = ThisDrawing.Utility.GetPoint(, "旋转对象轴线上一点:")
ThisDrawing.Utility.InitializeUserInput 1, ""
P2 = ThisDrawing.Utility.GetPoint(, "旋转对象轴线与旋转方向直线的交点:")
ThisDrawing.Utility.InitializeUserInput 1, ""
P3 = ThisDrawing.Utility.GetPoint(, "旋转方向直线上的另一点:")
KJPMFC P1, P2, P3, A, B, C, D
MsgBox A
'过平面法线的一点
T(0) = A * 10 + P2(0)
T(1) = B * 10 + P2(1)
T(2) = C * 10 + P2(2)
'计算空间两条直线的夹角
L1 = P2PDistance(P1, P2)
L2 = P2PDistance(P2, P3)
L3 = P2PDistance(P3, P1)
'利用余弦定理 a^2=b^2+c^2-2*b*c*cos(A)
J = Arccos((L1 * L1 + L2 * L2 - L3 * L3) / 2 / L1 / L2)
Obj.Rotate3d P2, T, -J
End Sub
其实从这一点 我可以实现在空间三点上(不共线的三点)画圆.
[本日志由 田草 于 2007-04-05 02:53 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |