Attribute VB_Name = "Module2" '******************************************************************************** '* THE CYCLOIDAL CURVES * '* ---------------------------------------------------------------------------- * '* Explanations: * '* * '* Here are some definitions concerning the cycloidal family: * '* * '* Cycloids: this curved is described as the trajectory in 2D plane of a given * '* circle point, when the circle rolls on a straight line. An extended or * '* shortened cycloid is called trochoid. The parametric equations of a cycloid * '* are: * '* X = R.(T - sin(T)) * '* Y = R.(1 - cos(T)) * '* * '* Here we do not study these classical curves but their sisters: * '* * '* Epicycloid: this curved is described as the trajectory in 2D plane of a * '* given circle point, when the circle rolls on an outter fixed circle. * '* * '* Hypocycloid: this curved is described as the trajectory in 2D plane of a * '* given circle point, when the circle rolls on an inner fixed circle. * '* * '* An extended or shortened Epicycloid (Hypocycloid) is called Epitrochoid * '* (Hypotrochoid). * '* * '* Here the general equations of these curves: * '* * '* X = (R1+R2).cos(T) - L.R2.cos(((R1+R2)/R2).T) * '* Y = (R1+R2).sin(T) - L.R2.sin(((R1+R2)/R2).T) * '* * '* R1 = radius of the fixed circle * '* R2 = radius of the mobile circle * '* (R2>0 --> Epicycloid, R2<0 --> Hypocycloid) * '* L is a parameter, such as: * '* L > 1, we get an extended curve, * '* L = 1, we get a normal curve, * '* 0 < L < 1, we get a shortened curve. * '* * '* Some examples: R1=10, R2=4, L=1 * '* R1=10, R2=-4, L=1 * '* R1=10, R2=6, L=2 * '* R1=10, R2=-6, L=1 * '* R1=10, R2=4.5, L=0.6 * '* R1=10, R2=-4.5, L=0.6 * '* R1=5, R2=-3, L=0.5 * '* R1=17, R2=2, L=1 * '* R1=10, R2=17, L=1 * '* R1=17, R2=2, L=1 * '* ---------------------------------------------------------------------------- * '* Reference: * '* From "Graphisme dans le plan et dans l'espace avec Turbo Pascal 4.0 de * '* R. Dony - MASSON 1990 page 113" [BIBLI 12]. * '* * '* Visual Basic Release By J-P Moreau, Paris. * '* (www.jpmoreau.fr) * '******************************************************************************** DefInt I-N Public R1, R2 Public L As Single Public Generators As String Dim aux1 As Single Dim aux2 As Single Dim aux3 As Single Dim MaxRadius As Single Dim Period Public X(10), Y(10) 'Dummy arguments for Polygon (not used here) Const PI = 3.1416 Function FX(t) FX = aux1 * Cos(t) - aux3 * Cos(aux2 * t) End Function Function FY(t) FY = aux1 * Sin(t) - aux3 * Sin(aux2 * t) End Function Sub SeekPeriod() Period = 0 Xstart = FX(0) Ystart = FY(0) 10 Period = Period + 2 * PI CurrentX = FX(Period) CurrentY = FY(Period) deltax = Abs(CurrentX - Xstart) deltay = Abs(CurrentY - Ystart) If ((deltax < 0.000001) And (deltay < 0.000001)) Or (Period > 200 * PI) Then Exit Sub GoTo 10 End Sub Sub Data() 'writeln; 'writeln(' Cycloidal Curves'); 'writeln(' ----------------'); 'writeln; 'writeln(' R1=radius of fixed circle'); 'writeln(' R2=radius of mobile circle'); 'writeln; 'writeln(' If R2 > 0, we get an Epicycloid'); 'writeln(' If R2 < 0, we get an Hypocycloid'); 'writeln; 'writeln(' If L > 1, we get an extended curve'); 'writeln(' If L = 1, we get a normal curve'); 'writeln(' If 0 < L < 1, we get a shortened curve'); 'writeln; 'write(' R1 = '); readln(R1); 'write(' R2 = '); readln(R2); 'Repeat ' write(' L = '); readln(L) 'Until L>=0; If R1 = 0 Then R1 = 10 'Default values If R2 = 0 Then R2 = 17 If L = 0 Then L = 1 aux1 = R1 + R2: aux2 = aux1 / R2: aux3 = L * R2 'writeln; 'write(' Do you want to draw the generator circles (y/n): '); Generators:=ReadKey End Sub Sub SeekWindow() MaxRadius = 0 If L >= 1 Then MaxRadius = R1 + R2 + Abs(L * R2) ElseIf R2 > 0 Then MaxRadius = R1 + 2 * R2 Else MaxRadius = R1 End If End Sub Sub DrawCurve() a = 0 step = PI / 48 MoveXY FX(0), FY(0) While a < Period a = a + step LineXY FX(a), FY(a) Wend End Sub Sub GeneratorCircles() Circle1 0, 0, R1, False Circle1 R1 + R2, 0, R2, False End Sub Sub DisplayParam() Dim s1 As String Dim s2 As String Dim s3 As String Dim s4 As String Dim s5 As String s1 = Str$(R1) s2 = Str$(R2) s3 = Str$(L) s4 = Str$(Period) s5 = Str$(MaxRadius) ix = (MaxX / 2) - 2000 Display ix, 100, "R1=" + s1 + " R2=" + s2 + " L=" + s3 + " Period=" + s1 + " MaxRadius=" + s5 End Sub 'main subroutine Sub Exec_Cyclo() Data SeekPeriod SeekWindow Form1.Cls Fenetre -MaxRadius, MaxRadius, -MaxRadius, MaxRadius Cloture 600, MaxX - 600, 1150, MaxY - 400 Bordure Cloture 900, MaxX - 900, 1270, MaxY - 520 If Generators = "y" Then GeneratorCircles DrawCurve DisplayParam End Sub