Attribute VB_Name = "Module2" '*********************************************************** '* Geometrical Transformations in 2D plane * '* ------------------------------------------------------- * '* Reference: * '* After Robert DONY - MASSON 1990 "Graphisme dans le * '* plan et dans l'espace en Turbo Pascal 4.0". * '* * '* Visual Basic Release By J-P Moreau, Paris, April 2005. * '* ------------------------------------------------------- * '* Available transformations are: * '* Kind=1: Rotation (choose angle in degrees) * '* Kind=2: Homothecy (choose ratio) * '* Kind=3: Symmetry (choose with respect to OX, OY or O) * '* Kind=4: Shearing (choose parameters B, C). * '*********************************************************** Const lim = 10 Const coef = 0.01745329252 'pi/180 Public choice As Integer Public x(1 To lim) As Double Public y(1 To lim) As Double Public Xtr(1 To lim) As Double Public Ytr(1 To lim) As Double Dim a As Double Dim b As Double Dim c As Double Dim d As Double Dim m As Double Dim n As Double Dim max As Double Dim rotdeg As Double Dim rotrad As Double Dim rh As Double Dim bord1 As Double Dim bord2 As Double Dim ch As String Public first As Boolean Public id_print As Boolean Sub InitObject() 'create a letter F for drawing x(1) = 5: y(1) = 7 x(2) = 2: y(2) = 7 x(3) = 2: y(3) = 2 x(4) = 3: y(4) = 2 x(5) = 3: y(5) = 4 x(6) = 4: y(6) = 4 x(7) = 4: y(7) = 5 x(8) = 3: y(8) = 5 x(9) = 3: y(9) = 6 x(10) = 5: y(10) = 6 End Sub Sub Limits(f1 As Double, f2 As Double, f3 As Double, f4 As Double, ByVal x As Double, ByVal y As Double) If x < f1 Then f1 = x If x > f2 Then f2 = x If y < f3 Then f3 = y If y > f4 Then f4 = y End Sub Sub Polygon(lim As Integer, mode As String) MoveXY x(1), y(1) For i = 2 To lim LineXY x(i), y(i) Next i If mode = "ferme" Then LineXY x(1), y(1) End Sub Sub Polygon1(lim As Integer, mode As String) MoveXY Xtr(1), Ytr(1) For i = 2 To lim LineXY Xtr(i), Ytr(i) Next i If mode = "ferme" Then LineXY Xtr(1), Ytr(1) End Sub Sub SeekWindow() Dim aux1 As Double Dim aux2 As Double Dim f1 As Double Dim f2 As Double Dim f3 As Double Dim f4 As Double Dim i As Integer f1 = 1E+20: f2 = -f1: f3 = f1: f4 = f2 For i = 1 To lim Limits f1, f2, f3, f4, x(i), y(i) Next i aux1 = -m * a + n * c + m aux2 = -m * b - n * d + n For i = 1 To lim Xtr(i) = a * x(i) - c * y(i) + aux1 Ytr(i) = b * x(i) + d * y(i) + aux2 Limits f1, f2, f3, f4, Xtr(i), Ytr(i) Next i max = Abs(f1) If max < Abs(f2) Then max = Abs(f2) If max < Abs(f3) Then max = Abs(f3) If max < Abs(f4) Then max = Abs(f4) max = 10 + 10 * (Int(max / 10)) End Sub Sub Init() If Not first Then Call InitObject first = True End If Form1.DrawWidth = 1 'normal width 'seek origin m = Val(Form1.Text2.Text) n = Val(Form1.Text3.Text) 'seek kind of transgormation choice = Val(Form1.Text1.Text) If choice = 1 Then 'case rotation rotdeg = Val(Form1.Text4.Text) rotrad = coef * rotdeg a = Cos(rotrad): b = Sin(rotrad) c = b: d = a ElseIf choice = 2 Then 'case homothecy rh = Val(Form1.Text4.Text) a = rh: b = 0 c = 0: d = rh ElseIf choice = 3 Then 'case symmetry b = 0: c = 0 If (m = 0) And (n = 0) Then ch = Form1.Text5.Text If ch = "X" Then a = 1: d = -1 ElseIf ch = "Y" Then a = -1: d = 1 ElseIf ch = "O" Then a = -1: d = -1 End If Else a = -1: d = -1 End If ElseIf choice = 4 Then 'case shearing a = 1: d = 1 b = Val(Form1.Text6.Text) c = Val(Form1.Text7.Text) End If Form1.ForeColor = RGB(0, 0, 255) 'select blue pen Call SeekWindow Fenetre -max, max, -max, max End Sub Sub FigureInit() 'draw figure to transform Dim xmax As Double Cloture 750, MaxX, 250, MaxY - 200 xmax = max / 10 Grid xmax, xmax Call Bordure Call Axes Graduate xmax, xmax Form1.DrawWidth = 2 'select thicker line Polygon lim, "ferme" End Sub Sub FigureTrans() 'draw figure after transformation Polygon1 lim, "ferme" If (m <> 0) And (n <> 0) Then MoveXY m + 0.5, n LineXY m - 0.5, n MoveXY m, n - 0.5 LineXY m, n + 0.5 End If Form1.FontSize = 16 'select bigger font} If choice = 1 Then Display MaxX - 1400, MaxY - 1000, "Rotation" ElseIf choice = 2 Then Display MaxX - 1500, MaxY - 1000, "Homothecy" ElseIf choice = 3 Then Display MaxX - 1400, MaxY - 1000, "Symmetry" ElseIf choice = 4 Then Display MaxX - 1400, MaxY - 1000, "Shearing" End If Form1.FontSize = 10 'return to normal size End Sub Sub Exec_Trans2d() Form1.Cls Call Init Call FigureInit Call FigureTrans End Sub