本帖最后由 作者 于 2007-2-21 12:51:46 编辑
采用offset平移,作平行线方法,搞定效果见图。 offset 线段a-b与线段a'-b'平行,b-b'与a-b是垂直的。 现在关键问题是要找参数方程公式求解.省去建立临时线段和删除线段的无用功。 Function Rotate3dEntity(ByVal EnterEintity As Object, ByVal ll As Object) As Object Dim theta As Double Dim x As Double, x1 As Double, y As Double, y1 As Double, z As Double, z1 As Double Dim Point1 As Variant, Point2 As Variant Dim l1 As Object, l2 As Object 'Dim Point1(0 To 2) As Double, Point2(0 To 2) As Double Point1 = ll.StartPoint Point2 = ll.EndPoint x = Point1(0): x1 = Point2(0) y = Point1(1): y1 = Point2(1) z = Point1(2): z1 = Point2(2) ' theta = (z - z1) / Sqr((x - x1) ^ 2 + (y - y1) ^ 2 + (z - z1) ^ 2) theta = Format(ArcCos(theta) - Pi / 2, "0.00") If Format(x - x1, "0.00") = 0 And Format(y - y1, "0.00") = 0 Then If z1 - z < 0 And Format(x - x1, "0.00") = 0# And Format(y - y1, "0.00") = 0# Then Point2(0) = Point2(0) + 2 Point2(1) = Point2(1) Point2(2) = Point2(2) EnterEintity.Rotate3D ll.EndPoint, Point2, Pi End If ElseIf x - x1 <> 0 Or y - y1 <> 0 Then ll.Offset 10 With obj_ModelSpace Set l1 = .Item(.Count - 1) Set l2 = .AddLine(ll.EndPoint, l1.EndPoint) l1.Delete End With If Format(z - z1, "0.00") = 0 Then EnterEintity.Rotate3D ll.EndPoint, l2.EndPoint, Pi / 2 ElseIf z - z1 <> 0 Then EnterEintity.Rotate3D ll.EndPoint, l2.EndPoint, theta If z1 - z < 0 Then EnterEintity.Rotate3D ll.EndPoint, l2.EndPoint, Pi End If End If l2.Delete End If End Function
Function lll() ' Dim Point1 As Variant, Point2 As Variant If boo = False Then AutoCADConnect End If Dim ll As Object, ss As Object, ReturnEntity As Object For Each ll In obj_ModelSpace If ll.objectname = "AcDbLine" Then Set ss = obj_ModelSpace.AddCone(ll.EndPoint, 3, 10) Set ReturnEntity = Rotate3dEntity(ss, ll) End If Next ll obj_Doc.Regen (0) End Function
|