明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1379|回复: 1

[讨论]矩阵

[复制链接]
发表于 2004-6-15 12:51:00 | 显示全部楼层 |阅读模式
才开始研究矩阵,发个矩阵实现移动、旋转、缩放的例子 三维的矩阵旋转还没想通,应该怎么实现? 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
发表于 2004-6-15 14:11:00 | 显示全部楼层
可不可以生成个临时的块对象然后旋转后打碎呢?~~~~


是不是有些跑题~~~~


。。。。。。。。。。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-28 05:48 , Processed in 0.160529 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表