- UID
- 76071
- 积分
- 1505
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-8-30
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
才开始研究矩阵,发个矩阵实现移动、旋转、缩放的例子
三维的矩阵旋转还没想通,应该怎么实现?
或者提供一个矩阵相乘的算法?
[Code]Public Sub Test()
Dim dot(2) As Double
Dim pnt(2) As Double
pnt(0) = 2
pnt(1) = 3
pnt(2) = 3
ScaleByTransMat ThisDrawing.ModelSpace(0), pnt, 10
End Sub
Public Sub RotateByTransMat(ByVal Obj As AcadEntity, ByVal BasePoint As Variant, ByVal Angle As Double)
Dim pTransMat(3, 3) As Double
Dim pAngle As Double, pDistance As Double
pAngle = ThisDrawing.Utility.AngleFromXAxis(pnt, BasePoint)
pDistance = Sqr(BasePoint(0) ^ 2 + BasePoint(1) ^ 2)
pTransMat(0, 0) = Cos(Angle): pTransMat(0, 1) = -Sin(Angle): pTransMat(0, 3) = BasePoint(0) - Cos(pAngle + Angle) * pDistance
pTransMat(1, 0) = Sin(Angle): pTransMat(1, 1) = Cos(Angle): pTransMat(1, 3) = BasePoint(1) - Sin(pAngle + Angle) * pDistance
pTransMat(2, 2) = 1
pTransMat(3, 3) = 1
TestTrans pTransMat
Obj.TransformBy pTransMat
Obj.Update
End Sub
Public Sub ScaleByTransMat(ByVal Obj As AcadEntity, ByVal BasePoint As Variant, ByVal ScaleFactor As Double)
Dim pTransMat(3, 3) As Double
pTransMat(0, 0) = ScaleFactor: pTransMat(0, 3) = BasePoint(0) * (1 - ScaleFactor)
pTransMat(1, 1) = ScaleFactor: pTransMat(1, 3) = BasePoint(1) * (1 - ScaleFactor)
pTransMat(2, 2) = ScaleFactor: pTransMat(2, 3) = BasePoint(2) * (1 - ScaleFactor)
pTransMat(3, 3) = 1
TestTrans pTransMat
Obj.TransformBy pTransMat
Obj.Update
End Sub
Public Sub MoveByTransMat(ByVal Obj As AcadEntity, ByVal StartPoint As Variant, ByVal EndPoint As Variant)
Dim pTransMat(3, 3) As Double
pTransMat(0, 0) = 1: pTransMat(0, 3) = EndPoint(0) - StartPoint(0)
pTransMat(1, 1) = 1: pTransMat(1, 3) = EndPoint(1) - StartPoint(1)
pTransMat(2, 2) = 1: pTransMat(2, 3) = EndPoint(2) - StartPoint(2)
pTransMat(3, 3) = 1
TestTrans pTransMat
Obj.TransformBy pTransMat
Obj.Update
End Sub
Public Sub TestTrans(ByVal TransMat As Variant)
For i = 0 To 3
Debug.Print TransMat(i, 0) & "," & TransMat(i, 1) & "," & TransMat(i, 2) & "," & TransMat(i, 3)
Next i
End Sub[/Code] |
|