Attribute VB_Name = "Module1" '******************************************************* '* SURFACES OF PARAMETRIC EQUATIONS * '* --------------------------------------------------- * '* This program draws 3D surfaces defined by equations * '* x = f(u,v), y = g(u,v), z = h(u,v) by using unit * '* graph_3d.pas. * '* --------------------------------------------------- * '* SAMPLE RUNS: * '* * '* Surface Data: * '* ============= * '* * '* Surface Type: 1. Ellipsoid * '* 2. Sphere * '* 3. Torus * '* 4. Hyperboloid 1 * '* Projection kind (1:perspective 2:parallel): 2 * '* Value of distance to screen: 30 * '* Value of angle Theta (deg.): 60 * '* Value of angle Phi (deg.): 30 * '* * '* Input U begin, U end and step: -1.57 1.57 0.2 * '* Input V begin, V end and step: -3.14 3.14 0.2 * '* (An ellipsoid is displayed in parralel mode). * '* * '* Your choice(1 to 4): 2 * '* Projection kind (1:perspective 2:parallel): 2 * '* Value of distance to screen: 25 * '* Value of angle Theta (deg.): 45 * '* Value of angle Phi (deg.): 30 * '* * '* Input U begin, U end and step: -3.14 3.14 0.2 * '* Input V begin, V end and step: -3.14 3.14 0.2 * '* (A shere is displayed in parralel mode). * '* * '* Your choice(1 to 4): 3 * '* Projection kind (1:perspective 2:parallel): 2 * '* Value of distance to screen: 20 * '* Value of angle Theta (deg.): 30 * '* Value of angle Phi (deg.): 30 * '* * '* Input U begin, U end and step: -3.14 3.14 0.4 * '* Input V begin, V end and step: -3.14 3.14 0.2 * '* (A torus is displayed in parralel mode). * '* * '* Your choice(1 to 4): 4 * '* Projection type (1:perspective 2:parallel): 2 * '* Value of distance to screen: 100 * '* Value of angle Theta (deg.): 60 * '* Value of angle Phi (deg.): 30 * '* * '* Input U begin, U end and step: -1 1 0.1 * '* Input V begin, V end and step: -1 1 0.1 * '* (An hyperpoloid is displayed in parralel mode). * '* * '* Your choice(1 to 4): 3 * '* Projection type (1:perspective 2:parallel): 1 * '* Value of Rho : 150 * '* Value of distance to screen: 2500 * '* Value of angle Theta (deg.): 30 * '* Value of angle Phi (deg.): 30 * '* * '* Input U begin, U end and step: -3.14 3.14 0.4 * '* Input V begin, V end and step: -3.14 3.14 0.2 * '* (A torus is displayed in perspective mode). * '* * '* --------------------------------------------------- * '* Ref.: "Graphisme dans le plan et dans l'espace en * '* Turbo Pascal 4.0 By R. Dony, MASSON Paris, * '* 1990" [BIBLI 12]. * '* * '* Visual Basic Release By J-P Moreau, Paris. * '* (www.jpmoreau.fr) * '******************************************************* 'NOTE: In perspective mode, for a given rho value, you 'can increase the dimension of object by increasing the 'value of distance to screen (see last sample run). '------------------------------------------------------- DefInt I-N Public U As Single Public Udebut As Single Public Ufin As Single Public dU As Single Public V As Single Public Vdebut As Single Public Vfin As Single Public dV As Single Public A As Single Public B As Single Public C As Single Public proj As Integer Public typ As Integer Const PI = 3.1415926535 Function FX(U, V) If typ = 1 Then FX = A * Cos(U) * Cos(V) 'Ellipsoid ElseIf typ = 2 Then FX = A * Cos(U) * Cos(V) 'sphere ElseIf typ = 3 Then FX = (A + B * Cos(U)) * Cos(V) 'torus Else FX = U 'hyperboloid End If End Function Function FY(U, V) If typ = 1 Then FY = B * Cos(U) * Sin(V) 'Ellipsoid ElseIf typ = 2 Then FY = B * Cos(U) * Sin(V) 'sphere ElseIf typ = 3 Then FY = (A + B * Cos(U)) * Sin(V) 'torus Else FY = V 'hyperboloid End If End Function Function FZ(U, V) If typ = 1 Then FZ = C * Sin(U) 'Ellipsoid ElseIf typ = 2 Then FZ = C * Sin(U) 'sphere ElseIf typ = 3 Then FZ = C * Sin(U) 'torus Else FZ = U * U - V * V 'hyperboloid End If End Function Sub Data() 'Kind of surface: 1. Ellipsoïd ' 2. Sphere ' 3. Torus ' 4. Hyperboloid typ = Form2.Text1 'Projection kind (1:perspective 2:parallel) proj = Form2.Text2 'Value of screen distance: DE de = Form2.Text4 If proj = 1 Then projection = 1 rho = Form2.Text3 Else projection = 2 rho = 10000000000# End If theta = Form2.Text5 phi = Form2.Text6 Udebut = Form2.Text7: Ufin = Form2.Text8: dU = Form2.Text9 Vdebut = Form2.Text7: Vfin = Form2.Text8: dV = Form2.Text9 If typ = 1 Then A = 6#: B = 3#: C = 2# ElseIf typ = 2 Then A = 4#: B = 4#: C = 4.5 ElseIf typ = 3 Then A = 6#: B = 3#: C = 3# Else A = 1#: B = 1#: C = 1# End If End Sub Sub CourbesEnU() U = Udebut While U <= Ufin + dU V = Vdebut x = FX(U, V) y = FY(U, V) z = FZ(U, V) MoveXYZ x, y, z While V <= Vfin + dV x = FX(U, V) y = FY(U, V) z = FZ(U, V) DrawXYZ x, y, z V = V + dV Wend U = U + dU Wend End Sub Sub CourbesEnV() V = Vdebut While V <= Vfin + dV U = Udebut x = FX(U, V) y = FY(U, V) z = FZ(U, V) MoveXYZ x, y, z While U <= Ufin + dU x = FX(U, V) y = FY(U, V) z = FZ(U, V) DrawXYZ x, y, z U = U + dU Wend V = V + dV Wend End Sub Sub Affiche() If projection = 2 Then s1$ = "Infinity" Else s1$ = Str(rho) End If s2$ = Str(theta): s3$ = Str(phi): s4$ = Str(de) Form1.CurrentX = 150: Form1.CurrentY = 150 Form1.Print " Rho="; s1$; " Theta="; s2$; " Phi="; s3$; " Screen="; s4$ s5$ = Str(Udebut): s6$ = Str(Ufin): s7$ = Str(dU) Form1.CurrentX = 150: Form1.CurrentY = 400 Form1.Print " U= ["; s5$; ","; s6$; "] Step="; s7$ s8$ = Str(Vdebut): s9$ = Str(Vfin): s10$ = Str(dV) Form1.CurrentX = 150: Form1.CurrentY = 650 Form1.Print " V= ["; s8$; ","; s9$; "] Step="; s10$ Form1.CurrentX = 600: Form1.CurrentY = 7500 If typ = 1 Then Form1.Print "ELLIPSOID" ElseIf typ = 2 Then Form1.Print "SPHERE" ElseIf typ = 3 Then Form1.Print "TORUS" Else Form1.Print "HYPERBOLOID" End If End Sub Sub DrawSurface() MaxX = Form1.Width: MaxY = Form1.Height Data Form1.Cls Cloture 0, MaxX, 0, MaxY Border 25 InitProj Axes 1.5 * A, 2.5 * B, 1.5 * C CourbesEnU CourbesEnV Affiche End Sub