Attribute VB_Name = "Module2" '********************************************************************** '* INVERSION OF A 2D CURVE * '* ------------------------------------------------------------------ * '* Explanations: * '* The inversion is defined by a point o, as origin, and a real number* '* p <> 0. Any point a is transformed into a point a', such as: * '* * '* _____.____________.___________.__________ * '* o a a' * '* * '* oa x oa' = p * '* * '* This small program calculates and draws the inverse of a polar * '* curve, defined as Rho = F(t). * '* ------------------------------------------------------------------ * '* Sample Run: * '* The example is defined as: Rho = 2 + cos(7*t) * '* ------------------------------------------------------------------ * '* From "Graphisme dans le plan et dans l'espace avec Turbo Pascal 4.0* '* de R. Dony - MASSON 1990", page 223". * '* * '* Visual Basic Release By J-P Moreau, Paris. * '********************************************************************** Const bord = 10, pas = 0.025, lim = 6.2832 Dim f1 As Double, f2 As Double, f3 As Double, f4 As Double Dim m As Double, n As Double Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double Dim puiss As Double Sub Data() 'put content of Edition box in Form1 into variable puiss puiss = Val(Form1.Text1.Text) 'define graphic window in physical coordinates Fenetre -5, 5, -5, 5 End Sub 'Define curve rho=f(t) in polar coordinates Function Rho(t As Double) As Double Rho = 2# + Cos(7# * t) End Function 'draw initial curve Sub DrawInitialCurve() Dim x As Double, y As Double, t As Double Form1.ForeColor = RGB(0, 0, 255) 'select blue pen 'define graphic zone in screen pixels Cloture 50 * bord, MaxX - 2 * bord, 8 * bord, MaxY - 10 * bord 'draw a grid with steps 1 in axes ox, oy Grid 1, 1 'draw a border around graphic zone Call Bordure 'draw axes ox, oy Call Axes 'graduate axes with steps 2 in ox, oy Graduate 2, 2 If puiss > 0 Then Cercle 0, 0, Sqr(puiss), False t = 1E-20 x = Rho(t) y = 0 MoveXY x, y While t <= lim t = t + pas x = Rho(t) * Cos(t) y = Rho(t) * Sin(t) LineXY x, y Wend End If End Sub 'draw curve after geometrical inversion Sub DrawInvertedCurve() Dim t As Double, r1 As Double, r2 As Double Dim x As Double, y As Double t = 1E-20 r1 = Rho(t) If r1 = 0 Then r2 = puiss / 1E-37 Else r2 = puiss / r1 End If x = r2 * Cos(t) y = r2 * Sin(t) MoveXY x, y While t <= lim t = t + pas r1 = Rho(t) r2 = puiss / r1 x = r2 * Cos(t) y = r2 * Sin(t) LineXY x, y Wend End Sub 'main subroutine Sub Exec_Inversion() Call Data Form1.Cls Call DrawInitialCurve Call DrawInvertedCurve Display MaxX - 2500, MaxY - 500, "GEOMETRICAL INVERSION" End Sub