本帖最后由 作者 于 2008-9-16 20:45:50 编辑
带功能函数 Type ReturnPoint X As Double Y As Double Z As Double End Type Sub lss() Dim p2(0 To 2) As Double, p1(0 To 2) As Double Dim objLine As AcadLine Dim pXY As Variant, P0 As Variant Dim pp As ReturnPoint pXY = Array(2, 2, 0) P0 = Array(0, 0, 0) pp = RotatingAroundTheZAxis(P0, pXY, 30) For ii = 0 To 2 p1(ii) = P0(ii) Next ii p2(0) = pp.X: p2(1) = pp.Y: p2(2) = pp.Z Set objLine = ThisDrawing.ModelSpace.AddLine(p1, p2) '' pYZ = Array(0, 2, 2) P0 = Array(0, 0, 0) pp = RotatingAroundTheXAxis(P0, pYZ, 30) For ii = 0 To 2 p1(ii) = P0(ii) Next ii p2(0) = pp.X: p2(1) = pp.Y: p2(2) = pp.Z Set objLine = ThisDrawing.ModelSpace.AddLine(p1, p2) '' pYZ = Array(2, 0, 2) P0 = Array(0, 0, 0) pp = RotatingAroundTheYAxis(P0, pYZ, 30) For ii = 0 To 2 p1(ii) = P0(ii) Next ii p2(0) = pp.X: p2(1) = pp.Y: p2(2) = pp.Z Set objLine = ThisDrawing.ModelSpace.AddLine(p1, p2) End Sub Function RotatingAroundTheXAxis(P0 As Variant, pXY As Variant, Gama As Double) As ReturnPoint zz = pXY(2): yy = pXY(1) z0 = P0(2): y0 = P0(1) Gama = Gama * Pi / 180 With RotatingAroundTheXAxis .X = pXY(0) .Y = (yy - y0) * Cos(Gama) - (zz - z0) * Sin(Gama) + y0 .Z = (yy - y0) * Sin(Gama) + (zz - z0) * Cos(Gama) + z0 End With End Function Function RotatingAroundTheYAxis(P0 As Variant, pXY As Variant, Belta As Double) As ReturnPoint xx = pXY(0): zz = pXY(2) x0 = P0(0): z0 = P0(2) Belta = Belta * Pi / 180 With RotatingAroundTheYAxis .X = (xx - x0) * Cos(Belta) - (zz - z0) * Sin(Belta) + x0 .Y = pXY(1) .Z = (xx - x0) * Sin(Belta) + (zz - z0) * Cos(Belta) + z0 End With End Function Function RotatingAroundTheZAxis(P0 As Variant, pXY As Variant, Alfa As Double) As ReturnPoint xx = pXY(0): yy = pXY(1) x0 = P0(0): y0 = P0(1) Alfa = Alfa * Pi / 180 With RotatingAroundTheZAxis .X = (xx - x0) * Cos(Alfa) - (yy - y0) * Sin(Alfa) + x0 .Y = (xx - x0) * Sin(Alfa) + (yy - y0) * Cos(Alfa) + y0 .Z = pXY(2) End With End Function Function Pi() Pi = 4 * Atn(1) End Function
|