[讨论]矩阵
才开始研究矩阵,发个矩阵实现移动、旋转、缩放的例子三维的矩阵旋转还没想通,应该怎么实现?
Public Sub Test()<BR>Dim dot(2) As Double<BR>Dim pnt(2) As Double<BR>pnt(0) = 2<BR>pnt(1) = 3<BR>pnt(2) = 3
ScaleByTransMat ThisDrawing.ModelSpace(0), pnt, 10<BR>End Sub
Public Sub RotateByTransMat(ByVal Obj As AcadEntity, ByVal BasePoint As Variant, ByVal Angle As Double)<BR> Dim pTransMat(3, 3) As Double<BR> Dim pAngle As Double, pDistance As Double<BR> pAngle = ThisDrawing.Utility.AngleFromXAxis(pnt, BasePoint)<BR> pDistance = Sqr(BasePoint(0) ^ 2 + BasePoint(1) ^ 2)<BR> pTransMat(0, 0) = Cos(Angle): pTransMat(0, 1) = -Sin(Angle): pTransMat(0, 3) = BasePoint(0) - Cos(pAngle + Angle) * pDistance<BR> pTransMat(1, 0) = Sin(Angle): pTransMat(1, 1) = Cos(Angle): pTransMat(1, 3) = BasePoint(1) - Sin(pAngle + Angle) * pDistance<BR> pTransMat(2, 2) = 1<BR> pTransMat(3, 3) = 1<BR> TestTrans pTransMat<BR> Obj.TransformBy pTransMat<BR> Obj.Update<BR>End Sub<BR>Public Sub ScaleByTransMat(ByVal Obj As AcadEntity, ByVal BasePoint As Variant, ByVal ScaleFactor As Double)<BR> Dim pTransMat(3, 3) As Double<BR> pTransMat(0, 0) = ScaleFactor: pTransMat(0, 3) = BasePoint(0) * (1 - ScaleFactor)<BR> pTransMat(1, 1) = ScaleFactor: pTransMat(1, 3) = BasePoint(1) * (1 - ScaleFactor)<BR> pTransMat(2, 2) = ScaleFactor: pTransMat(2, 3) = BasePoint(2) * (1 - ScaleFactor)<BR> pTransMat(3, 3) = 1<BR> TestTrans pTransMat<BR> Obj.TransformBy pTransMat<BR> Obj.Update<BR>End Sub
Public Sub MoveByTransMat(ByVal Obj As AcadEntity, ByVal StartPoint As Variant, ByVal EndPoint As Variant)<BR> Dim pTransMat(3, 3) As Double<BR> pTransMat(0, 0) = 1: pTransMat(0, 3) = EndPoint(0) - StartPoint(0)<BR> pTransMat(1, 1) = 1: pTransMat(1, 3) = EndPoint(1) - StartPoint(1)<BR> pTransMat(2, 2) = 1: pTransMat(2, 3) = EndPoint(2) - StartPoint(2)<BR> pTransMat(3, 3) = 1<BR> TestTrans pTransMat<BR> Obj.TransformBy pTransMat<BR> Obj.Update<BR>End Sub<BR>Public Sub TestTrans(ByVal TransMat As Variant)<BR>For i = 0 To 3<BR>Debug.Print TransMat(i, 0) & "," & TransMat(i, 1) & "," & TransMat(i, 2) & "," & TransMat(i, 3)<BR>Next i<BR>End Sub<BR> 可不可以生成个临时的块对象然后旋转后打碎呢?~~~~
是不是有些跑题~~~~
。。。。。。。。。。。。
页:
[1]