Èçîáðàæåíèå è óïðàâëåíèå
Ëèñòèíã 34.1. Êîä âûøå è â òåëå ïðîöåäóðû Form1_Load.
'Íà÷àëî êîîðäèíàò:
Private Const x_focus As Double = 0
Private Const y_focus As Double = 0
Private Const z_focus As Double = 0
'Ñôåðè÷åñêèå êîîðäèíàòû òî÷êè E (ãëàçà íàáëþäàòåëÿ Eye):
Private r_Eye As Single
Private phi_Eye As Single
Private theta_Eye As Single
'Îáúÿâëÿåì ìàòðèöó (êàê ìàññèâ) è ïåðåìåííûå
'(âî âñåõ ìàññèâàõ íóëåâûå èíäåêñû íå èñïîëüçóåì):
Private Const pi As Double = Math.PI
Private MatrixProjection(4, 4) As Single
Private Tetrahedron As Integer
Private Cube As Integer
Private Octahedron As Integer
Private Dodecahedron As Integer
Private Icosahedron_first As Integer
Private Icosahedron_last As Integer
'Äëÿ ïàðàëëåëüíîãî ïðîåöèðîâàíèÿ îáúåêòà íà ýêðàí
'(parallel projection) çàäàåì êîíñòàíòó:
Private Const ParallelProjection As Integer = 0
'Äëÿ ïåðñïåêòèâíîãî ïðîåöèðîâàíèÿ îáúåêòà íà ýêðàí
'(perspective projection)çàäàåì êîíñòàíòó:
Private Const PerspectiveProjection As Integer = 1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As EventArgs) Handles MyBase.Load
'Çàäàåì êîîðäèíàòû ãëàçà íàáëþäàòåëÿ, íàïðèìåð:
r_Eye = 4 : phi_Eye = 0.05 * pi : theta_Eye = 0.3 * pi
'Âûçûâàåì ïðîöåäóðó äëÿ ïåðñïåêòèâíîãî ïðîåöèðîâàíèÿ,
'êîãäà type_of_projection = PerspectiveProjection
'(äëÿ ïàðàëëåëüíîãî ïðîåöèðîâàíèÿ âìåñòî
'PerspectiveProjection ïèøåì ParallelProjection):
Projection(MatrixProjection, PerspectiveProjection, _
r_Eye, phi_Eye, theta_Eye, _
x_focus, y_focus, z_focus, 0, 1, 0)
'Ðàññ÷èòûâàåì ïàðàìåòðû ãåîìåòðè÷åñêîãî òåëà:
ÑalculateParameters()
'Ñâÿçûâàåì ýëåìåíò PictureBox1 ñ êëàññîì Bitmap:
PictureBox1.Image = New Bitmap(PictureBox1.Width, _
PictureBox1.Height)
'Ïðîåêòèðóåì è â PictureBox1 ðèñóåì âûáðàííîå íàìè òåëî:
Designing(DirectCast(PictureBox1.Image, Bitmap))
End Sub
×òîáû ìû ìîãëè óïðàâëÿòü (íàïðèìåð, âðàùàòü) îáúåêòàìè ïðè ïîìîùè íàæàòèÿ êëàâèø, â îêíå Class Name âûáèðàåì (Overrides), à â îêíå Method Name âûáèðàåì ProcessCmdKey. Ïîÿâëÿåòñÿ ôàéë Form1.vb ñ øàáëîíîì (ìåòîäà ProcessCmdKey), êîòîðûé ïîñëå çàïèñè íàøåãî êîäà ïðèíèìàåò ñëåäóþùèé âèä. Îòìåòèì, ÷òî åñëè â âåðñèè VS, êîòîðàÿ èìååòñÿ ó ÷èòàòåëÿ, îòñóòñòâóåò ìåòîä ProcessCmdKey, òî íåîáõîäèìî ïîëíîñòüþ çàïèñàòü íèæåñëåäóþùèé ìåòîä âìåñòå ñ øàáëîíîì (èëè ñêîïèðîâàòü âåñü ìåòîä èç ïðèëàãàåìîãî ê êíèãå äèñêà).
Ëèñòèíã 34.2. Ìåòîä ProcessCmdKey.
Protected Overrides Function ProcessCmdKey( _
ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) As Boolean
'Çàäàåì óãîë ïîâîðîòà ôèãóðû ïîñëå íàæàòèÿ êëàâèøè:
Const delta_theta As Single = pi / 20
Select Case keyData
Case System.Windows.Forms.Keys.Left
theta_Eye = theta_Eye - delta_theta
Case System.Windows.Forms.Keys.Right
theta_Eye = theta_Eye + delta_theta
Case System.Windows.Forms.Keys.Up
phi_Eye = phi_Eye - delta_theta
Case System.Windows.Forms.Keys.Down
phi_Eye = phi_Eye + delta_theta
Case Else
Return MyBase.ProcessCmdKey(msg, keyData)
End Select
Projection(MatrixProjection, PerspectiveProjection, _
r_Eye, phi_Eye, theta_Eye, _
x_focus, y_focus, z_focus, 0, 1, 0)
'Â ýëåìåíòå PictureBox1 ïåðåðèñîâûâàåì îáúåêò:
Designing(DirectCast(PictureBox1.Image, Bitmap))
PictureBox1.Refresh()
Return True
End Function
Íèæå ýòîãî êîäà çàïèñûâàåì ñëåäóþùèå âñå ïðîöåäóðû è ôóíêöèè.
Ëèñòèíã 34.3. Ïðîöåäóðû è ôóíêöèè.
'Ïðîåêòèðóåì è ïðè ïîìîùè ïðîöåäóðû DrawSolid
'ðèñóåì âûáðàííîå ôëàæêîì CheckBox ãåîìåòðè÷åñêîå òåëî:
Private Sub Designing(ByVal bmp As Bitmap)
'Ñîçäàåì îáúåêò g êëàññà Graphics:
Dim g As Graphics
'Ñâÿçûâàåì îáúåêò g ñ èçîáðàæåíèåì bmp:
g = Graphics.FromImage(bmp)
' Çàäàåì áåëûé öâåò òèïà Window
'äëÿ ýëåìåíòà óïðàâëåíèÿ PictureBox1:
g.Clear(SystemColors.Window)
'Âûñâîáîæäàåì ðåñóðñû îò ãðàôè÷åñêîãî îáúåêòà g:
g.Dispose()
'Ïðåîáðàçóåì òî÷êè:
TransformAllDataFull(MatrixProjection)
'Ïðîåêòèðóåì è ðèñóåì âûáðàííîå íà CheckBox òåëî:
If CheckBox1.CheckState = _
System.Windows.Forms.CheckState.Checked Then
DrawSolid(bmp, Tetrahedron, Cube - 1, _
System.Drawing.Color.Red, False)
End If
If CheckBox2.CheckState = _
System.Windows.Forms.CheckState.Checked Then _
DrawSolid(bmp, Cube, Octahedron - 1, _
System.Drawing.Color.Black, False)
If CheckBox3.CheckState = _
System.Windows.Forms.CheckState.Checked Then _
DrawSolid(bmp, Octahedron, Dodecahedron - 1, _
System.Drawing.Color.Green, False)
If CheckBox4.CheckState = _
System.Windows.Forms.CheckState.Checked Then _
DrawSolid(bmp, Dodecahedron, Icosahedron_first - 1, _
System.Drawing.Color.Blue, False)
If CheckBox5.CheckState = _
System.Windows.Forms.CheckState.Checked Then _
DrawSolid(bmp, Icosahedron_first, Icosahedron_last, _
System.Drawing.Color.Orange, False)
If CheckBox6.CheckState = _
System.Windows.Forms.CheckState.Checked Then _
DrawSolid(bmp, 1, Tetrahedron - 1, _
System.Drawing.Color.Salmon, False)
End Sub
'Ðàññ÷èòûâàåì ïàðàìåòðû ãåîìåòðè÷åñêèõ òåë è îñåé:
Private Sub ÑalculateParameters()
Dim theta1 As Single : Dim theta2 As Single
Dim s1 As Single : Dim s2 As Single
Dim c1 As Single : Dim c2 As Single
Dim S As Single : Dim R As Single
Dim H As Single : Dim A As Single
Dim B As Single : Dim C As Single
Dim D As Single : Dim X As Single
Dim Y As Single : Dim y2 As Single
Dim M As Single : Dim N As Single
'Îñè êîîðäèíàò:
DesigningLine(0, 0, 0, 0.5, 0, 0) 'Îñü x.
DesigningLine(0, 0, 0, 0, 0.5, 0) 'Îñü y.
DesigningLine(0, 0, 0, 0, 0, 0.5) 'Îñü z.
'Òåòðàýäð (Tetrahedron):
Tetrahedron = NumLines + 1
S = CSng(Sqrt(6))
A = S / CSng(Sqrt(3))
B = -A / 2
C = A * CSng(Sqrt(2)) - 1
D = S / 2
DesigningLine(0, C, 0, A, -1, 0)
DesigningLine(0, C, 0, B, -1, D)
DesigningLine(0, C, 0, B, -1, -D)
DesigningLine(B, -1, -D, B, -1, D)
DesigningLine(B, -1, D, A, -1, 0)
DesigningLine(A, -1, 0, B, -1, -D)
'Êóá (Cube):
Cube = NumLines + 1
DesigningLine(-1, -1, -1, -1, 1, -1)
DesigningLine(-1, 1, -1, 1, 1, -1)
DesigningLine(1, 1, -1, 1, -1, -1)
DesigningLine(1, -1, -1, -1, -1, -1)
DesigningLine(-1, -1, 1, -1, 1, 1)
DesigningLine(-1, 1, 1, 1, 1, 1)
DesigningLine(1, 1, 1, 1, -1, 1)
DesigningLine(1, -1, 1, -1, -1, 1)
DesigningLine(-1, -1, -1, -1, -1, 1)
DesigningLine(-1, 1, -1, -1, 1, 1)
DesigningLine(1, 1, -1, 1, 1, 1)
DesigningLine(1, -1, -1, 1, -1, 1)
'Îêòàýäð (Octahedron):
Octahedron = NumLines + 1
DesigningLine(0, 1, 0, 1, 0, 0)
DesigningLine(0, 1, 0, -1, 0, 0)
DesigningLine(0, 1, 0, 0, 0, 1)
DesigningLine(0, 1, 0, 0, 0, -1)
DesigningLine(0, -1, 0, 1, 0, 0)
DesigningLine(0, -1, 0, -1, 0, 0)
DesigningLine(0, -1, 0, 0, 0, 1)
DesigningLine(0, -1, 0, 0, 0, -1)
DesigningLine(0, 0, 1, 1, 0, 0)
DesigningLine(0, 0, 1, -1, 0, 0)
DesigningLine(0, 0, -1, 1, 0, 0)
DesigningLine(0, 0, -1, -1, 0, 0)
'ÄÎäåêàýäð (Dodecahedron):
Dodecahedron = NumLines + 1
theta1 = pi * 0.4 : theta2 = pi * 0.8
s1 = CSng(Sin(theta1))
c1 = CSng(Cos(theta1))
s2 = CSng(Sin(theta2))
c2 = CSng(Cos(theta2))
M = 1 - (2 - 2 * c1 - 4 * s1 * s1) / (2 * c1 - 2)
N = CSng(Sqrt((2 - 2 * c1) - M * M)) * _
(1 + (1 - c2) / (c1 - c2)) : R = 2 / N
S = R * CSng(Sqrt(2 - 2 * c1))
A = R * s1 : B = R * s2
C = R * c1 : D = R * c2
H = R * (c1 - s1)
X = (R * R * (2 - 2 * c1) - 4 * A * A) / _
(2 * C - 2 * R)
Y = CSng(Sqrt(S * S - (R - X) * (R - X)))
y2 = Y * (1 - c2) / (c1 - c2)
DesigningLine(R, 1, 0, C, 1, A)
DesigningLine(C, 1, A, D, 1, B)
DesigningLine(D, 1, B, D, 1, -B)
DesigningLine(D, 1, -B, C, 1, -A)
DesigningLine(C, 1, -A, R, 1, 0)
DesigningLine(R, 1, 0, X, 1 - Y, 0)
DesigningLine(C, 1, A, X * c1, 1 - Y, X * s1)
DesigningLine(C, 1, -A, X * c1, 1 - Y, -X * s1)
DesigningLine(D, 1, B, X * c2, 1 - Y, X * s2)
DesigningLine(D, 1, -B, X * c2, 1 - Y, -X * s2)
DesigningLine(X, 1 - Y, 0, -X * c2, 1 - y2, -X * s2)
DesigningLine(X, 1 - Y, 0, -X * c2, 1 - y2, X * s2)
DesigningLine(X * c1, 1 - Y, X * s1, _
-X * c2, 1 - y2, X * s2)
DesigningLine(X * c1, 1 - Y, X * s1, _
-X * c1, 1 - y2, X * s1)
DesigningLine(X * c2, 1 - Y, X * s2, _
-X * c1, 1 - y2, X * s1)
DesigningLine(X * c2, 1 - Y, X * s2, -X, 1 - y2, 0)
DesigningLine(X * c2, 1 - Y, -X * s2, -X, 1 - y2, 0)
DesigningLine(X * c2, 1 - Y, -X * s2, _
-X * c1, 1 - y2, -X * s1)
DesigningLine(X * c1, 1 - Y, -X * s1, _
-X * c1, 1 - y2, -X * s1)
DesigningLine(X * c1, 1 - Y, -X * s1, _
-X * c2, 1 - y2, -X * s2)
DesigningLine(-R, -1, 0, -X, 1 - y2, 0)
DesigningLine(-C, -1, A, -X * c1, 1 - y2, X * s1)
DesigningLine(-D, -1, B, -X * c2, 1 - y2, X * s2)
DesigningLine(-D, -1, -B, -X * c2, 1 - y2, -X * s2)
DesigningLine(-C, -1, -A, -X * c1, 1 - y2, -X * s1)
DesigningLine(-R, -1, 0, -C, -1, A)
DesigningLine(-C, -1, A, -D, -1, B)
DesigningLine(-D, -1, B, -D, -1, -B)
DesigningLine(-D, -1, -B, -C, -1, -A)
DesigningLine(-C, -1, -A, -R, -1, 0)
'Èêîñàýäð (Icosahedron):
Icosahedron_first = NumLines + 1
R = 2 / (2 * CSng(Sqrt(1 - 2 * c1)) + _
CSng(Sqrt(3 / 4 * (2 - 2 * c1) - _
2 * c2 - c2 * c2 - 1)))
S = R * CSng(Sqrt(2 - 2 * c1))
H = 1 - CSng(Sqrt(S * S - R * R))
A = R * s1 : B = R * s2
C = R * c1 : D = R * c2
DesigningLine(R, H, 0, C, H, A)
DesigningLine(C, H, A, D, H, B)
DesigningLine(D, H, B, D, H, -B)
DesigningLine(D, H, -B, C, H, -A)
DesigningLine(C, H, -A, R, H, 0)
DesigningLine(R, H, 0, 0, 1, 0)
DesigningLine(C, H, A, 0, 1, 0)
DesigningLine(D, H, B, 0, 1, 0)
DesigningLine(D, H, -B, 0, 1, 0)
DesigningLine(C, H, -A, 0, 1, 0)
DesigningLine(-R, -H, 0, -C, -H, A)
DesigningLine(-C, -H, A, -D, -H, B)
DesigningLine(-D, -H, B, -D, -H, -B)
DesigningLine(-D, -H, -B, -C, -H, -A)
DesigningLine(-C, -H, -A, -R, -H, 0)
DesigningLine(-R, -H, 0, 0, -1, 0)
DesigningLine(-C, -H, A, 0, -1, 0)
DesigningLine(-D, -H, B, 0, -1, 0)
DesigningLine(-D, -H, -B, 0, -1, 0)
DesigningLine(-C, -H, -A, 0, -1, 0)
DesigningLine(R, H, 0, -D, -H, B)
DesigningLine(R, H, 0, -D, -H, -B)
DesigningLine(C, H, A, -D, -H, B)
DesigningLine(C, H, A, -C, -H, A)
DesigningLine(D, H, B, -C, -H, A)
DesigningLine(D, H, B, -R, -H, 0)
DesigningLine(D, H, -B, -R, -H, 0)
DesigningLine(D, H, -B, -C, -H, -A)
DesigningLine(C, H, -A, -C, -H, -A)
DesigningLine(C, H, -A, -D, -H, -B)
Icosahedron_last = NumLines
End Sub
Public Structure Line
'Ìàññèâû äëÿ ñîåäèíåíèÿ òî÷åê (points):
<VBFixedArray(4)> Dim fr_points() As Single
<VBFixedArray(4)> Dim to_points() As Single
' Ìàññèâû äëÿ ñîåäèíåíèÿ ïðåîáðàçîâàííûõ òî÷åê
'(transformed points):
<VBFixedArray(4)> Dim fr_tr_points() As Single
<VBFixedArray(4)> Dim to_tr_points() As Single
Public Sub Initialize()
ReDim fr_points(4) : ReDim to_points(4)
ReDim fr_tr_points(4) : ReDim to_tr_points(4)
End Sub
End Structure
'Îáúÿâëÿåì ìàññèâ Lines ñòðóêòóðû Line (ñîçäàâàòü ìàññèâ
'èç èçìåíÿåìîãî êîëè÷åñòâà ýëåìåíòîâ è èíèöèàëèçèðîâàòü åãî 'ïðè ïîìîùè îïåðàòîðà ReDim ìû áóäåì íèæå):
Public Lines() As Line
'Îáúÿâëÿåì è èíèöèàëèçèðóåì ïåðåìåííóþ äëÿ èíäåêñà ìàññèâà:
Public NumLines As Integer
'Ïðîåêòèðóåì ëèíèþ ìåæäó òî÷êàìè (x1,y1,z1),(x2,y2,z2):
Public Sub DesigningLine(ByVal x1 As Single, _
ByVal y1 As Single, ByVal z1 As Single, ByVal x2 As Single, _
ByVal y2 As Single, ByVal z2 As Single)
NumLines = NumLines + 1
'Ñîçäàåì ìàññèâ Lines ñòðóêòóðû Line èç èçìåíÿåìîãî
'êîëè÷åñòâà ýëåìåíòîâ NumLines, èíèöèàëèçèðóåì åãî
'îïåðàòîðîì ReDim è ïðè ïîìîùè êëþ÷åâîãî ñëîâà Preserve
'ñîõðàíÿåì ïðåäûäóùèå äàííûå ìàññèâà:
ReDim Preserve Lines(NumLines)
'Èíèöèàëèçèðóåì è ðàññ÷èòûâàåì ìàññèâû:
Lines(NumLines).Initialize()
Lines(NumLines).fr_points(1) = x1
Lines(NumLines).fr_points(2) = y1
Lines(NumLines).fr_points(3) = z1
Lines(NumLines).fr_points(4) = 1
Lines(NumLines).to_points(1) = x2
Lines(NumLines).to_points(2) = y2
Lines(NumLines).to_points(3) = z2
Lines(NumLines).to_points(4) = 1
End Sub
'Ïðèìåíÿåì ìàòðèöó ïåðåíîñà (translation matrix)
'êî âñåì ëèíèÿì, èñïîëüçóÿ MatrixApplyFull.
' Ïðåîáðàçîâàíèå íå èìååò 0, 0, 0, 1 â ïîñëåäíåì ñòîëáöå:
Public Sub TransformAllDataFull(ByRef M(,) As Single)
TransformDataFull(M, 1, NumLines)
End Sub
'Ïðèìåíÿåì ìàòðèöó ïåðåíîñà (translation matrix)
'êî âñåì âûäåëåííûì ëèíèÿì, èñïîëüçóÿ MatrixApplyFull.
'Ïðåîáðàçîâàíèå íå èìååò 0, 0, 0, 1 â ïîñëåäíåì ñòîëáöå:
Public Sub TransformDataFull(ByRef M(,) As Single, _
ByVal line1 As Integer, ByVal line2 As Integer)
Dim i As Integer
For i = line1 To line2
MatrixApplyFull(Lines(i).fr_points, M, _
Lines(i).fr_tr_points)
MatrixApplyFull(Lines(i).to_points, M, _
Lines(i).to_tr_points)
Next i
End Sub
'Ââîäèì ïåðåì-þ N_Graphics äëÿ íîìåðà ìíîãèõ ãåîì-õ èçîáð-é.
'Íîìåð ïåðâîãî èçîáðàæåíèÿ ðàâåí 1:
Dim N_Graphics As Integer = 1
'Ðèñóåì âûäåëåííûå ïðåîáðàçîâàííûå ëèíèè è ýêïîðò-ì â ôàéëû:
Public Sub DrawSolid(ByVal bmp As Bitmap, _
ByVal first_line As Integer, ByVal last_line As Integer, _
ByVal color As Color, ByVal clear As Boolean)
Dim k As Integer
Dim x1 As Single : Dim y1 As Single
Dim x2 As Single : Dim y2 As Single
Dim g As Graphics : Dim pen As Pen
'Çàäàåì òîëùèíó ëèíèè ðèñîâàíèÿ, íàïðèìåð, 2
'(öâåò ëèíèè ìû çàäàëè â ïðîöåäóðå Designing):
pen = New Pen(color, 2)
'Ñâÿçûâàåì îáúåêò g ñ èçîáðàæåíèåì bmp:
g = Graphics.FromImage(bmp)
If clear Then g.Clear(System.Drawing.Color.Black)
'Îáúÿâëÿåì èíäåêñû ýëåìåíòîâ âñåõ ìàññèâîâ:
Dim i, j As Integer
'Åñëè ýòîò ìåòîä DrawSolid âûçâàí âòîðîé ðàç
'äëÿ ðèñîâàíèÿ âòîðîãî èçîáðàæåíèÿ è N_Graphics = 2,
'òî îáõîäèì 1-é ìàññèâ äëÿ ïåðâîãî èçîáð-ÿ äî ìåòêè M2:
If N_Graphics = 2 Then GoTo M2
'Ïðîãðàììèðóåì ïåðâûé ìàññèâ äëÿ ïåðâîãî èçîáðàæåíèÿ:
'Çàäàåì ãðàíèöû èíäåêñîâ ïåðâîãî ìàññèâà myArrayVB(i, j)
Dim N_x As Integer = 200
Dim N_y As Integer = 1
'Îáúÿâëÿåì ìàññèâ myArrayVB(i, j) ïåðåìåííûõ òèïà Single,
'êîãäà i = 0,1,2,3,...,N_x; j = 0,1,2,3,...,N_y:
Dim myArrayVB(N_x, N_y) As Single 'Àâòîìàò-êè îáíóëÿåòñÿ.
'Çíà÷åíèå ïåðâîé ãðàíèöû ìàññèâà myArrayVB:
Dim N_1_myArrayVB As Integer
'Ðàññ÷èòûâàåì ýëåìåíòû ìàññèâà myArrayVB(i, j)
'äëÿ ðèñîâàíèÿ ëèíèé ïåðâîãî ãåîì-ãî èçîáðàæåíèÿ:
i = -1 'Çàäàåì äî öèêëà.
For k = first_line To last_line
x1 = Lines(k).fr_tr_points(1)
y1 = Lines(k).fr_tr_points(2)
x2 = Lines(k).to_tr_points(1)
y2 = Lines(k).to_tr_points(2)
'Ìîæíî ðèñîâàòü ëèíèè èçîáðàæåíèÿ è çäåñü:
'g.DrawLine(pen, _
' (x1 * bmp.Width / 4) + bmp.Width / 2.0F, _
' bmp.Height / 2.0F - (y1 * bmp.Height / 4), _
' (x2 * bmp.Width / 4) + bmp.Width / 2.0F, _
' bmp.Height / 2.0F - (y2 * bmp.Height / 4) _
')
'Ìàñøòàáèðóåì çíà÷åíèÿ êîîðäèíàò:
x1 = (x1 * bmp.Width / 4) + bmp.Width / 2.0F
y1 = bmp.Height / 2.0F - (y1 * bmp.Height / 4)
x2 = (x2 * bmp.Width / 4) + bmp.Width / 2.0F
y2 = bmp.Height / 2.0F - (y2 * bmp.Height / 4)
'Çàïèñûâàåì êîîðäèíàòû òî÷åê â ìàññèâ:
i = i + 2
myArrayVB(i, 0) = x1
myArrayVB(i, 1) = y1
myArrayVB(i + 1, 0) = x2
myArrayVB(i + 1, 1) = y2
N_1_myArrayVB = i + 1 'Çíà÷åíèå ãðàíèöû ìàññèâà.
Next
'Íà÷àëî N_first_line è êîíåö N_last_line öèêëà
'ïðè ðèñîâàíèè èç ìàññèâà myArrayVB:
Dim N_first_line, N_last_line As Integer
N_first_line = first_line
N_last_line = last_line
'Ïåðåäàåì çíà÷åíèÿ íà÷àëà N_first_line
'è êîíöà öèêëà N_last_line â ýëåìåíòû ìàññèâà
'myArrayVB(0, 0) è myArrayVB(0, 1):
myArrayVB(0, 0) = N_first_line
myArrayVB(0, 1) = N_last_line
' Ðèñóåì ïðè ïîìîùè ìàññèâà êîîðäèíàò myArrayVB(200, 1).
i = -1
For k = N_first_line To N_last_line
i = i + 2
x1 = myArrayVB(i, 0)
y1 = myArrayVB(i, 1)
x2 = myArrayVB(i + 1, 0)
y2 = myArrayVB(i + 1, 1)
g.DrawLine(pen, x1, y1, x2, y2)
Next
'Çàïèñûâàåì ìàññèâ êîîðäèíàò myArrayVB(200, 1) â ôàéë.
'Ñîçäàåì îáúåêò sw êëàññà StreamWriter äëÿ çàïèñè
'â ôàéë ïî àäðåñó D:\MyDocs\MyTest3D_Graphics.txt.
If N_Graphics = 1 Then
Dim sw As StreamWriter = _
New StreamWriter("D:\MyDocs\MyTest3D_Graphics.txt")
'Êàæäûé ýëåìåíò ìàññèâà myArrayVB(i, j) çàïèñûâàåì â ôàéë
'â âèäå îòäåëüíîé ñòðîêè ïðè ïîìîùè ïðîöåäóðû WriteLine:
For i = 0 To N_x
For j = 0 To N_y
sw.WriteLine(myArrayVB(i, j))
Next
Next
sw.Close()
End If
M2:
'Åñëè ýòîò ìåòîä DrawSolid âûçâàí ïåðâûé ðàç
'äëÿ ðèñîâàíèÿ ïåðâîãî èçîáðàæåíèÿ è N_Graphics = 1,
'òî îáõîäèì 2-é ìàññèâ äëÿ 2-ãî èçîáð-ÿ äî ìåòêè M_End:
If N_Graphics = 1 Then GoTo M_End
'Ïðîãðàììèðóåì âòîðîé ìàññèâ äëÿ âòîðîãî èçîáðàæåíèÿ.
'Çàäàåì ãðàíèöû èíäåêñîâ 2-ãî ìàññèâà myArrayVB_2(i, j):
Dim N_x_2 As Integer = 200
Dim N_y_2 As Integer = 1
'Çàäàåì ìàññèâ myArrayVB_2(i, j) ïåðåìåííûõ òèïà Single,
'êîãäà i = 0,1,2,3,...,N_x; j = 0,1,2,3,...,N_y:
Dim myArrayVB_2(N_x_2, N_y_2) As Single
'Çíà÷åíèå ïåðâîé ãðàíèöû ìàññèâà myArrayVB_2:
Dim N_1_myArrayVB_2 As Integer
'Ðàññ÷èòûâàåì ýëåìåíòû ìàññèâà myArrayVB_2(i, j)
'äëÿ ðèñîâàíèÿ ëèíèé âòîðîãî ãåîì-ãî èçîáðàæåíèÿ:
i = -1 'Çàäàåì äî öèêëà.
For k = first_line To last_line
x1 = Lines(k).fr_tr_points(1)
y1 = Lines(k).fr_tr_points(2)
x2 = Lines(k).to_tr_points(1)
y2 = Lines(k).to_tr_points(2)
'Ìîæíî ðèñîâàòü ëèíèè èçîáðàæåíèÿ è çäåñü:
'g.DrawLine(pen, _
' (x1 * bmp.Width / 4) + bmp.Width / 2.0F, _
' bmp.Height / 2.0F - (y1 * bmp.Height / 4), _
' (x2 * bmp.Width / 4) + bmp.Width / 2.0F, _
' bmp.Height / 2.0F - (y2 * bmp.Height / 4) _
')
'Ìàñøòàáèðóåì çíà÷åíèÿ êîîðäèíàò:
x1 = (x1 * bmp.Width / 4) + bmp.Width / 2.0F
y1 = bmp.Height / 2.0F - (y1 * bmp.Height / 4)
x2 = (x2 * bmp.Width / 4) + bmp.Width / 2.0F
y2 = bmp.Height / 2.0F - (y2 * bmp.Height / 4)
'Çàïèñûâàåì êîîðäèíàòû òî÷åê â ìàññèâ:
i = i + 2
myArrayVB_2(i, 0) = x1
myArrayVB_2(i, 1) = y1
myArrayVB_2(i + 1, 0) = x2
myArrayVB_2(i + 1, 1) = y2
N_1_myArrayVB_2 = i + 1 'Çíà÷åíèå ãðàíèöû ìàññèâà.
Next
'Íà÷àëî N_first_line_2 è êîíåö N_last_line_2 öèêëà
'ïðè ðèñîâàíèè èç ìàññèâà myArrayVB_2:
Dim N_first_line_2, N_last_line_2 As Integer
N_first_line_2 = first_line
N_last_line_2 = last_line
'Ïåðåäàåì çíà÷åíèÿ íà÷àëà N_first_line_2
'è êîíöà öèêëà N_last_line_2 â ýëåìåíòû ìàññèâà
'myArrayVB_2(0, 0) è myArrayVB_2(0, 1):
myArrayVB_2(0, 0) = N_first_line_2
myArrayVB_2(0, 1) = N_last_line_2
' Ðèñóåì ïðè ïîìîùè ìàññèâà êîîðäèíàò myArrayVB_2(200, 1):
i = -1
For k = N_first_line_2 To N_last_line_2
i = i + 2
x1 = myArrayVB_2(i, 0)
y1 = myArrayVB_2(i, 1)
x2 = myArrayVB_2(i + 1, 0)
y2 = myArrayVB_2(i + 1, 1)
g.DrawLine(pen, x1, y1, x2, y2)
Next
'Çàïèñûâàåì ìàññèâ êîîðäèíàò myArrayVB_2(200, 1) â ôàéë.
'Ñîçäàåì îáúåêò sw_2 êëàññà StreamWriter äëÿ çàïèñè
'â ôàéë ïî àäðåñó D:\MyDocs\MyTest3D_Graphics_2.txt.
'Ôàéë àâòîìàòè÷åñêè "îïóñòîøàåòñÿ":
Dim sw_2 As StreamWriter = _
New StreamWriter("D:\MyDocs\MyTest3D_Graphics_2.txt")
'Êàæäûé ýëåìåíò ìàññèâà myArrayVB_2(i, j) çàïèñ-ì â ôàéë
' â âèäå îòäåëüíîé ñòðîêè ïðè ïîìîùè ïðîöåäóðû WriteLine:
For i = 0 To N_x_2
For j = 0 To N_y_2
sw_2.WriteLine(myArrayVB_2(i, j))
Next
Next
sw_2.Close()
'Âûñâîáîæäàåì ðåñóðñû îò îáúåêòîâ g è pen:
g.Dispose() : pen.Dispose()
M_End:
'Åñëè ýòà ìåòîä DrawSolid âûçâàíà åùå ðàç
'äëÿ ðèñîâàíèÿ ñëåäóþùåãî èçîáðàæåíèÿ,
'òî óâåëè÷èâàåì íîìåð èçîáðàæåíèÿ N_Graphics íà 1:
N_Graphics = N_Graphics + 1
End Sub
'Ñòðîèì åäèíè÷íóþ ìàòðèöó:
Public Sub MatrixIdentity(ByRef M(,) As Single)
Dim i As Integer : Dim j As Integer
For i = 1 To 4
For j = 1 To 4
If i = j Then
M(i, j) = 1
Else
M(i, j) = 0
End If
Next
Next
End Sub
'Ñòðîèì ìàòðèöó ïðåîáðàçîâàíèÿ (3-D transformation matrix)
'äëÿ ïåðñïåêòèâíîé ïðîåêöèè âäîëü îñè z íà ïëîñêîñòü x,y
'ñ öåíòðîì îáúåêòà (ôîêóñîì) â íà÷àëå êîîðäèíàò
'è c öåíòðîì ïðîåöèðîâàíèÿ íà ðàññòîÿíèè (0, 0, Distance):
Public Sub MatrixPerspectiveXZ(ByRef M(,) As Single, _
ByVal Distance As Single)
MatrixIdentity(M)
If Distance <> 0 Then M(3, 4) = -1 / Distance
End Sub
'Ñòðîèì ìàòðèöó ïðåîáðàçîâàíèÿ (3-D transformation matrix)
'äëÿ ïðîåöèðîâàíèÿ ñ êîîðäèíàòàìè:
'öåíòð ïðîåöèðîâàíèÿ (cx, cy, cz),
'ôîêóñ (fx, fy, fx),
'âåêòîð îò îáúåêòà äî ýêðàíà UP <ux, yx, uz>,
'òèï ïðîåöèðîâàíèÿ (type_of_projection):
'PerspectiveProjection èëè ParallelProjection:
Public Sub MatrixTransformation(ByRef M(,) As Single, _
ByVal type_of_projection As Integer, _
ByVal Cx As Single, _
ByVal Cy As Single, ByVal Cz As Single, _
ByVal Fx As Single, ByVal Fy As Single, _
ByVal Fz As Single, ByVal ux As Single, _
ByVal uy As Single, ByVal uz As Single)
Static M1(4, 4) As Single : Static M2(4, 4) As Single
Static M3(4, 4) As Single : Static M4(4, 4) As Single
Static M5(4, 4) As Single : Static M12(4, 4) As Single
Static M34(4, 4) As Single
Static M1234(4, 4) As Single
Dim sin1 As Single : Dim cos1 As Single
Dim sin2 As Single : Dim cos2 As Single
Dim sin3 As Single : Dim cos3 As Single
Dim A As Single : Dim B As Single
Dim C As Single : Dim d1 As Single
Dim d2 As Single : Dim d3 As Single
Dim up1(4) As Single : Dim up2(4) As Single
'Ïåðåíîñèì ôîêóñ (öåíòð îáúåêòà) â íà÷àëî êîîðäèíàò:
MatrixTranslate(M1, -Fx, -Fy, -Fz)
A = Cx - Fx : B = Cy - Fy : C = Cz - Fz
d1 = CSng(Sqrt(A * A + C * C))
If d1 <> 0 Then
sin1 = -A / d1 : cos1 = C / d1
End If
d2 = CSng(Sqrt(A * A + B * B + C * C))
If d2 <> 0 Then
sin2 = B / d2 : cos2 = d1 / d2
End If
'Âðàùàåì îáúåêò âîêðóã îñè y, ÷òîáû ðàçìåñòèòü
'öåíòð ïðîåêöèè â y-z ïëîñêîñòè:
MatrixIdentity(M2)
'Åñëè d1 = 0, òîãäà öåíòð ïðîåêöèè
'óæå íàõîäèòñÿ íà îñè y è â y-z ïëîñêîñòè:
If d1 <> 0 Then
M2(1, 1) = cos1 : M2(1, 3) = -sin1
M2(3, 1) = sin1 : M2(3, 3) = cos1
End If
'Âðàùàåì âîêðóã îñè x,
'÷òîáû ðàçìåñòèòü öåíòð ïðîåêöèè íà îñè Z.
MatrixIdentity(M3)
'Åñëè d2 = 0, òî öåíòð ïðîåêöèè
'íàõîäèòñÿ â íà÷àëå êîîðäèíàò.
'Ýòî äåëàåò ïðîåêöèþ íåâîçìîæíîé.
If d2 <> 0 Then
M3(2, 2) = cos2 : M3(2, 3) = sin2
M3(3, 2) = -sin2 : M3(3, 3) = cos2
End If
'Âðàùàåì âåêòîð UP:
up1(1) = ux : up1(2) = uy : up1(3) = uz
up1(4) = 1 : MatrixApply(up1, M2, up2)
MatrixApply(up2, M3, up1)
' Rotate around the Z axis to put the UP
' vector in the Y-Z plane.
'Âðàùàåì âîêðóã îñè z, ÷òîáû ðàçìåñòèòü
'âåêòîð UP â y-z ïëîñêîñòè:
d3 = CSng(Sqrt(up1(1) * up1(1) + _
up1(2) * up1(2)))
MatrixIdentity(M4)
'Åñëè d3 = 0, òî âåêòîð UP ðàâåí íóëþ:
If d3 <> 0 Then
sin3 = up1(1) / d3 : cos3 = up1(2) / d3
M4(1, 1) = cos3 : M4(1, 2) = sin3
M4(2, 1) = -sin3 : M4(2, 2) = cos3
End If
'Ïðîåöèðóåì:
If type_of_projection = _
PerspectiveProjection And d2 <> 0 Then
MatrixPerspectiveXZ(M5, d2)
Else
MatrixIdentity(M5)
End If
'Êîìáèíèðóåì ïðåîáðàçîâàíèÿ:
m3MatMultiply(M12, M1, M2)
m3MatMultiply(M34, M3, M4)
m3MatMultiply(M1234, M12, M34)
If type_of_projection = PerspectiveProjection Then
m3MatMultiplyFull(M, M1234, M5)
Else
m3MatMultiply(M, M1234, M5)
End If
End Sub
'Ñòðîèì ìàòðèöó ïðåîáðàçîâàíèÿ (3-D transformation matrix)
'äëÿ ïåðñïåêòèâíîãî ïðîåöèðîâàíèÿ (perspective projection):
'öåíòð ïðîåöèðîâàíèÿ (r, phi, theta),
'ôîêóñ (fx, fy, fx),
'âåêòîð îò îáúåêòà äî ýêðàíà UP <ux, yx, uz>,
'òèï ïðîåöèðîâàíèÿ (type_of_projection):
'PerspectiveProjection:
Public Sub Projection(ByRef M(,) As Single, _
ByVal type_of_projection As Integer, ByVal R As Single, _
ByVal phi As Single, ByVal theta As Single, _
ByVal Fx As Single, ByVal Fy As Single, ByVal Fz As Single, _
ByVal ux As Single, ByVal uy As Single, ByVal uz As Single)
Dim Cx As Single : Dim Cy As Single
Dim Cz As Single : Dim r2 As Single
'Ïåðåõîäèì ê ïðÿìîóãîëüíûì êîîðäèíàòàì:
Cy = R * CSng(Sin(phi))
r2 = R * CSng(Cos(phi))
Cx = r2 * CSng(Cos(theta))
Cz = r2 * CSng(Sin(theta))
MatrixTransformation(M, type_of_projection, _
Cx, Cy, Cz, Fx, Fy, Fz, ux, uy, uz)
End Sub
' Ñòðîèì ìàòðèöó ïðåîáðàçîâàíèÿ, ÷òîáû ïîëó÷èòü
'îòðàæåíèå íàïðîòèâ ïëîñêîñòè, ïðîõîäÿùåé
'÷åðåç (p1, p2, p3) ñ âåêòîðîì íîðìàëè <n1, n2, n3>:
Public Sub m3Reflect(ByRef M(,) As Single, _
ByVal p1 As Single, ByVal p2 As Single, _
ByVal p3 As Single, ByVal n1 As Single, _
ByVal n2 As Single, ByVal n3 As Single)
Dim T(4, 4) As Single 'Ïåðåíîñ.
Dim R1(4, 4) As Single 'Âðàùåíèå 1.
Dim r2(4, 4) As Single 'Âðàùåíèå 2.
Dim S(4, 4) As Single 'Îòðàæåíèå.
Dim R2i(4, 4) As Single 'Íå âðàùàòü 2.
Dim R1i(4, 4) As Single 'Íå âðàùàòü 1.
Dim Ti(4, 4) As Single 'Íå ïåðåíîñèòü.
Dim D As Single : Dim L As Single
Dim M12(4, 4) As Single : Dim M34(4, 4) As Single
Dim M1234(4, 4) As Single
Dim M56(4, 4) As Single : Dim M567(4, 4) As Single
'Ïåðåíîñèì ïëîñêîñòü ê íà÷àëó êîîðäèíàò:
MatrixTranslate(T, -p1, -p2, -p3)
MatrixTranslate(Ti, p1, p2, p3)
'Âðàùàåì âîêðóã îñè z,
'ïîêà íîðìàëü íå áóäåò â y-z ïëîñêîñòè:
MatrixIdentity(R1)
D = CSng(Sqrt(n1 * n1 + n2 * n2))
R1(1, 1) = n2 / D : R1(1, 2) = n1 / D
R1(2, 1) = -R1(1, 2) : R1(2, 2) = R1(1, 1)
MatrixIdentity(R1i)
R1i(1, 1) = R1(1, 1) : R1i(1, 2) = -R1(1, 2)
R1i(2, 1) = -R1(2, 1) : R1i(2, 2) = R1(2, 2)
'Âðàùàåì âîêðóã îñè x, êîãäà íîðìàëü áóäåò ïî îñè y:
MatrixIdentity(r2)
L = CSng(Sqrt(n1 * n1 + n2 * n2 + n3 * n3))
r2(2, 2) = D / L : r2(2, 3) = -n3 / L
r2(3, 2) = -r2(2, 3) : r2(3, 3) = r2(2, 2)
MatrixIdentity(R2i)
R2i(2, 2) = r2(2, 2) : R2i(2, 3) = -r2(2, 3)
R2i(3, 2) = -r2(3, 2) : R2i(3, 3) = r2(3, 3)
'Ðèñóåì îòðàæåíèå îáúåêòà ïåðïåíäèêóëÿðíî x-z ïëîñêîñòè:
MatrixIdentity(S)
S(2, 2) = -1
'Êîìáèíèðóåì ìàòðèöû:
m3MatMultiply(M12, T, R1) : m3MatMultiply(M34, r2, S)
m3MatMultiply(M1234, M12, M34)
m3MatMultiply(M56, R2i, R1i)
m3MatMultiply(M567, M56, Ti)
m3MatMultiply(M, M1234, M567)
End Sub
' Ñòðîèì ìàòðèöó ïðåîáðàçîâàíèÿ äëÿ ïîâîðîòà íà óãîë theta
'âîêðóã ëèíèè, ïðîõîäÿùåé ÷åðåç (p1, p2, p3)
'â íàïðàâëåíèè <d1, d2, d3>.
'Óãîë theta îòêëàäûâàåòñÿ ïðîòèâ ÷àñîâîé ñòðåëêè,
'åñëè ìû ñìîòðèì âíèç â íàïðàâëåíèè,
'ïðîòèâîïîëîæíîì íàïðàâëåíèþ ëèíèè:
Public Sub m3LineRotate(ByRef M(,) As Single, _
ByVal p1 As Single, ByVal p2 As Single, ByVal p3 As Single, _
ByVal d1 As Single, ByVal d2 As Single, ByVal d3 As Single, _
ByVal theta As Single)
Dim T(4, 4) As Single 'Ïåðåíîñ.
Dim R1(4, 4) As Single 'Âðàùåíèå 1.
Dim r2(4, 4) As Single 'Âðàùåíèå 2.
Dim Rot3(4, 4) As Single 'Âðàùåíèå.
Dim R2i(4, 4) As Single 'Ñòîï âðàùåíèþ 2.
Dim R1i(4, 4) As Single 'Ñòîï âðàùåíèþ 1.
Dim Ti(4, 4) As Single 'Ñòîï ïåðåíîñó.
Dim D As Single : Dim L As Single
Dim M12(4, 4) As Single : Dim M34(4, 4) As Single
Dim M1234(4, 4) As Single
Dim M56(4, 4) As Single : Dim M567(4, 4) As Single
'Ïåðåíîñèì ïëîñêîñòü ê íà÷àëó êîîðäèíàò:
MatrixTranslate(T, -p1, -p2, -p3)
MatrixTranslate(Ti, p1, p2, p3)
'Âðàùàåì âîêðóã îñè z,
'ïîêà ëèíèÿ íå îêàæåòñÿ â y-z ïëîñêîñòè:
MatrixIdentity(R1)
D = CSng(Sqrt(d1 * d1 + d2 * d2))
R1(1, 1) = d2 / D : R1(1, 2) = d1 / D
R1(2, 1) = -R1(1, 2) : R1(2, 2) = R1(1, 1)
MatrixIdentity(R1i)
R1i(1, 1) = R1(1, 1) : R1i(1, 2) = -R1(1, 2)
R1i(2, 1) = -R1(2, 1) : R1i(2, 2) = R1(2, 2)
'Âðàùàåì âîêðóã îñè x, êîãäà ëèíèÿ áóäåò ïî îñè y:
MatrixIdentity(r2)
L = CSng(Sqrt(d1 * d1 + d2 * d2 + d3 * d3))
r2(2, 2) = D / L : r2(2, 3) = -d3 / L
r2(3, 2) = -r2(2, 3) : r2(3, 3) = r2(2, 2)
MatrixIdentity(R2i)
R2i(2, 2) = r2(2, 2) : R2i(2, 3) = -r2(2, 3)
R2i(3, 2) = -r2(3, 2) : R2i(3, 3) = r2(3, 3)
'Âðàùàåì âîêðóã ëèíèè (îñè y):
MatrixYRotate(Rot3, theta)
'Êîìáèíèðóåì ìàòðèöû:
m3MatMultiply(M12, T, R1)
m3MatMultiply(M34, r2, Rot3)
m3MatMultiply(M1234, M12, M34)
m3MatMultiply(M56, R2i, R1i)
m3MatMultiply(M567, M56, Ti)
m3MatMultiply(M, M1234, M567)
End Sub
'Ñòðîèì ìàòðèöó ïðåîáðàçîâàíèÿ (3-D transformation matrix)
' äëÿ ïåðåíîñà íà Tx, Ty, Tz:
Public Sub MatrixTranslate(ByRef M(,) As Single, _
ByVal Tx As Single, ByVal Ty As Single, ByVal Tz As Single)
MatrixIdentity(M)
M(4, 1) = Tx : M(4, 2) = Ty : M(4, 3) = Tz
End Sub
'Ñòðîèì ìàòðèöó ïðåîáðàçîâàíèÿ (3-D transformation matrix)
'äëÿ ïîâîðîòà âîêðóã îñè y (óãîë - â ðàäèàíàõ):
Public Sub MatrixYRotate(ByRef M(,) As Single, _
ByVal theta As Single)
MatrixIdentity(M)
M(1, 1) = CSng(Cos(theta))
M(3, 3) = M(1, 1)
M(3, 1) = CSng(Sin(theta))
M(1, 3) = -M(3, 1)
End Sub
'Ïðèìåíÿåì ìàòðèöó ïðåîáðàçîâàíèÿ ê òî÷êå,
'ãäå ìàòðèöà íå ìîæåò èìåòü 0, 0, 0, 1
'â ïîñëåäíåì ñòîëáöå. Íîðìàëèçóåì òîëüêî
'x è y êîìïîíåíòû ðåçóëüòàòà, ÷òîáû ñîõðàíèòü z èíôîðìàöèþ:
Public Sub MatrixApplyFull(ByRef V() As Single, _
ByRef M(,) As Single, ByRef Result() As Single)
Dim i As Integer : Dim j As Integer
Dim value As Single
For i = 1 To 4
value = 0
For j = 1 To 4
value = value + V(j) * M(j, i)
Next j
Result(i) = value
Next i
'Ïîâòîðíî íîðìàëèçóåì òî÷êó (value = Result(4)):
If value <> 0 Then
Result(1) = Result(1) / value
Result(2) = Result(2) / value
'Íå ïðåîáðàçîâûâàåì z-ñîñòàâëÿþùóþ:
Else
'Åñëè çíà÷åíèå z áîëüøå, ÷åì îò öåíòðà ïðîåêöèè,
'ýòà òî÷êà áóäåò óäàëåíà:
Result(3) = Single.MaxValue
End If
Result(4) = 1
End Sub
'Ïðèìåíÿåì ìàòðèöó ïðåîáðàçîâàíèÿ ê òî÷êå:
Public Sub MatrixApply(ByRef V() As Single, _
ByRef M(,) As Single, ByRef Result() As Single)
Result(1) = V(1) * M(1, 1) + V(2) * M(2, 1) + _
V(3) * M(3, 1) + M(4, 1)
Result(2) = V(1) * M(1, 2) + V(2) * M(2, 2) + _
V(3) * M(3, 2) + M(4, 2)
Result(3) = V(1) * M(1, 3) + V(2) * M(2, 3) + _
V(3) * M(3, 3) + M(4, 3)
Result(4) = 1
End Sub
'Óìíîæàåì äâå ìàòðèöû. Ìàòðèöû
'íå ìîãóò ñîäåðæàòü 0, 0, 0, 1 â ïîñëåäíèõ ñòîëáöàõ:
Public Sub m3MatMultiplyFull(ByRef Result(,) As Single, _
ByRef A(,) As Single, ByRef B(,) As Single)
Dim i As Integer : Dim j As Integer
Dim k As Integer : Dim value As Single
For i = 1 To 4
For j = 1 To 4
value = 0
For k = 1 To 4
value = value + A(i, k) * B(k, j)
Next k
Result(i, j) = value
Next
Next
End Sub
'Óìíîæàåì äâå ìàòðèöû:
Public Sub m3MatMultiply(ByRef Result(,) As Single, _
ByRef A(,) As Single, ByRef B(,) As Single)
Result(1, 1) = A(1, 1) * B(1, 1) + A(1, 2) * B(2, 1) _
+ A(1, 3) * B(3, 1)
Result(1, 2) = A(1, 1) * B(1, 2) + A(1, 2) * B(2, 2) _
+ A(1, 3) * B(3, 2)
Result(1, 3) = A(1, 1) * B(1, 3) + A(1, 2) * B(2, 3) _
+ A(1, 3) * B(3, 3)
Result(1, 4) = 0
Result(2, 1) = A(2, 1) * B(1, 1) + A(2, 2) * B(2, 1) _
+ A(2, 3) * B(3, 1)
Result(2, 2) = A(2, 1) * B(1, 2) + A(2, 2) * B(2, 2) _
+ A(2, 3) * B(3, 2)
Result(2, 3) = A(2, 1) * B(1, 3) + A(2, 2) * B(2, 3) _
+ A(2, 3) * B(3, 3)
Result(2, 4) = 0
Result(3, 1) = A(3, 1) * B(1, 1) + A(3, 2) * B(2, 1) _
+ A(3, 3) * B(3, 1)
Result(3, 2) = A(3, 1) * B(1, 2) + A(3, 2) * B(2, 2) _
+ A(3, 3) * B(3, 2)
Result(3, 3) = A(3, 1) * B(1, 3) + A(3, 2) * B(2, 3) _
+ A(3, 3) * B(3, 3)
Result(3, 4) = 0
Result(4, 1) = A(4, 1) * B(1, 1) + A(4, 2) * B(2, 1) _
+ A(4, 3) * B(3, 1) + B(4, 1)
Result(4, 2) = A(4, 1) * B(1, 2) + A(4, 2) * B(2, 2) _
+ A(4, 3) * B(3, 2) + B(4, 2)
Result(4, 3) = A(4, 1) * B(1, 3) + A(4, 2) * B(2, 3) _
+ A(4, 3) * B(3, 3) + B(4, 3)
Result(4, 4) = 1
End Sub
Ëèñòèíã 34.4. Ìåòîä äëÿ ïå÷àòè èçîáðàæåíèÿ ñ ýëåìåíòà PictureBox.
Private Sub PrintDocument1_PrintPage( _
ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles PrintDocument1.PrintPage
e.Graphics.DrawImage(PictureBox1.Image, 0, 0)
End Sub