Функция произведения двух матриц:
Function CrossMatrices(tmx1, tmx2) As Variant
' Product of two matrices
Dim mtx(0 To 3, 0 To 3) As Double
Dim m As Integer
Dim n As Integer
Dim c As Integer
Dim tmp As Double
While m < 4
n = 0
While n < 4
c = 0
While c < 4
tmp = tmp + tmx1(c, n) * tmx2(m, c)
c = c + 1
Wend
mtx(m, n) = tmp
tmp = 0
n = n + 1
Wend
m = m + 1
Wend
CrossMatrices = mtx
End Function
'
' Проверка:
' Можно воспользоваться функциями выше для построения
' промежуточных матриц.
' (Здесь просто для наглядности)
Sub TestMultMatrices()
' матрица смещения из точки 5,5,0 в точку 0,0,0
Dim tmx1(0 To 3, 0 To 3) As Double
tmx1(0, 0) = 1#: tmx1(0, 1) = 0#: tmx1(0, 2) = 0#: tmx1(0, 3) = -5#
tmx1(1, 0) = 0#: tmx1(1, 1) = 1#: tmx1(1, 2) = 0#: tmx1(1, 3) = -5#
tmx1(2, 0) = 0#: tmx1(2, 1) = 0#: tmx1(2, 2) = 1#: tmx1(2, 3) = 0#
tmx1(3, 0) = 0#: tmx1(3, 1) = 0#: tmx1(3, 2) = 0#: tmx1(3, 3) = 1#
' матрица поворота на 45 град. вокруг точки 0,0,0
Dim tmx2(0 To 3, 0 To 3) As Double
tmx2(0, 0) = 0.707: tmx2(0, 1) = -0.707: tmx2(0, 2) = 0#: tmx2(0, 3) = 0#
tmx2(1, 0) = 0.707: tmx2(1, 1) = 0.707: tmx2(1, 2) = 0#: tmx2(1, 3) = 0#
tmx2(2, 0) = 0#: tmx2(2, 1) = 0#: tmx2(2, 2) = 1#: tmx2(2, 3) = 0#
tmx2(3, 0) = 0#: tmx2(3, 1) = 0#: tmx2(3, 2) = 0#: tmx2(3, 3) = 1#
' матрица обратного смещения из точки 0,0,0 в точку 5,5,0
Dim tmx3(0 To 3, 0 To 3) As Double
tmx3(0, 0) = 1: tmx3(0, 1) = 0: tmx3(0, 2) = 0#: tmx3(0, 3) = 5#
tmx3(1, 0) = 0: tmx3(1, 1) = 1: tmx3(1, 2) = 0#: tmx3(1, 3) = 5#
tmx3(2, 0) = 0#: tmx3(2, 1) = 0#: tmx3(2, 2) = 1#: tmx3(2, 3) = 0#
tmx3(3, 0) = 0#: tmx3(3, 1) = 0#: tmx3(3, 2) = 0#: tmx3(3, 3) = 1#
Dim matx As Variant
matx = CrossMatrices(CrossMatrices(tmx1, tmx2), tmx3)
Dim q, p
For q = 0 to 3
For p = 0 to 3
Debug.Print matx(q, p)
Next
Next
End Sub