Hi folks,

I'm very fond of that machine. One half of the Cornu spiral! The other half you can get by mirroring the displayed one at lower left corner of the display. What does this little pic on the display for our calculator means?

It has to do a lot work. The parameter t is in [0 ; 5] by 0.02 steps. the x value = C(t) an the y value = S(t). For every point we have two integrations. And then the calc has to draw a little line on the display. For we have 500 integrations (ACC was set to 1E-3) and 250 little pieces of lines between the two points P1( C(t1) ; S(t1)) and P2(C(t1 + Δt) ; S(t1 + Δt)). How long it takes? And with the resolution of ca. 170 dpi. Two Minutes! Enjoy the pic!

## Cornu Spiral (Fresnel integrals)

### Re: Cornu Spiral (Fresnel integrals)

Source code! My kingdom for the source code!

Werner

Werner

42S #3249S01123

DM42 #00345

DM42 #00345

### Re: Cornu Spiral (Fresnel integrals)

@peacecalc, nice picture and a good challenge !

Here is my code as I was trying to reproduce your picture above. I have not optimized this code in any way to keep it easier to read.

It will prompt for Tmax value (min value is set to 0), the Step value and ACC value, and then will draw the spiral. Y

Update: you need to be in RAD mode.

To work this code needs the LINE program from Tim Butler available here.

And here is what I get with your parameters: T within [0 ; 5], step 0.02, 1E-3 for ACC:

Two notes:

Here is my code as I was trying to reproduce your picture above. I have not optimized this code in any way to keep it easier to read.

It will prompt for Tmax value (min value is set to 0), the Step value and ACC value, and then will draw the spiral. Y

Update: you need to be in RAD mode.

Code: Select all

```
00 { 176-Byte Prgm }
01▸LBL "CORNU"
02 3
03 STO "GrMod"
04 CLLCD
05 CLST
06 STO "LLIM"
07 LSTO "T"
08 RCL "ResY"
09 COMPLEX
10 LSTO "XY0"
11 INPUT "Tmax"
12 INPUT "Step"
13 INPUT "ACC"
14▸LBL 01
15 RCL "T"
16 STO "ULIM"
17 PGMINT "Ct"
18 INTEG "U"
19 LSTO "XX"
20 PGMINT "St"
21 INTEG "U"
22 RCL "ResY"
23 ×
24 LASTX
25 X<>Y
26 -
27 RCL "XX"
28 RCL "ResX"
29 ×
30 X<>Y
31 COMPLEX
32 ENTER
33 X<> "XY0"
34 X<>Y
35 XEQ "LINE"
36 RCL "Step"
37 STO+ "T"
38 RCL "Tmax"
39 RCL "T"
40 X≤Y?
41 GTO 01
42 RTN
43▸LBL "Ct"
44 MVAR "U"
45 RCL "U"
46 X↑2
47 COS
48 RTN
49▸LBL "St"
50 MVAR "U"
51 RCL "U"
52 X↑2
53 SIN
54 END
```

And here is what I get with your parameters: T within [0 ; 5], step 0.02, 1E-3 for ACC:

Two notes:

- the original picture is different from mine and seems to have been obtained with Tmax ~= 6.25 instead of 5
- replacing Tim's LINE program with Werner’s LINE version from here gives an interesting spiral !

Last edited by dlachieze on Wed Aug 19, 2020 5:41 pm, edited 1 time in total.

DM42: 00425 - DM41X: β00066

### Re: Cornu Spiral (Fresnel integrals)

Hello friends!

So what! (@miles davis), what are you doing? I formatted and explained my code and come too late for publishing. @dlachieze is faster as the magic bus (@the who). But neverthe less here is my version with comments:

@whuyse: And who gets your kindom? By the way, what kind of kingdom is your kingdom?

Here is the rwa code:

So what! (@miles davis), what are you doing? I formatted and explained my code and come too late for publishing. @dlachieze is faster as the magic bus (@the who). But neverthe less here is my version with comments:

Code: Select all

```
00 { 484-Byte Prgm }
01▸LBL "INTFC"
02 PGMINT IND "FC"
03 INTEG "T"
04 RTN
"INTFC" is the main integrationprogram. You have to make the variables ULIM, LLIM (preset with zero) and
ACC (preset by 1E-3 or 1E-5) It attended a function stored in "FC" and that the functions has the variable
T for integration.
05▸LBL "SFRES"
06 MVAR "T"
07 RCL "PI2"
08 RCL "T"
09 X↑2
10 ×
11 SIN
12 RTN
"SFRES" is the Fresnel integral funktion sin(pi*x²/2), the variable "PI2" contains pi/2;
13▸LBL "CFRES"
14 MVAR "T"
15 RCL "PI2"
16 RCL "T"
17 X↑2
18 ×
19 COS
20 RTN
"CFRES" is the Fresnel integral funktion cos(pi*x²/2), the variable "PI2" contains pi/2;
21▸LBL "BFRE"
22 "SFRES"
23 ASTO "FC"
24 XEQ "INTFC"
25 STO "SFRE"
26 "CFRES"
27 ASTO "FC"
28 XEQ "INTFC"
29 STO "CFRE"
30 CLST
31 RCL "SFRE"
32 RCL "CFRE"
33 RTN
"BFRE" calculates first C(s) returns in x-stack, than it calculates S(x) and gave it back to y-stack;
34▸LBL "CORNU"
35 2
36 1
37 DIM "TVA"
38 DIM "TVE"
39 3
40 STO IND 10
41 CLLCD
42 0.02
43 STO 14
44 240
45 1
46 INDEX "TVA"
47 STOEL
48 I+
49 X<>Y
50 STOEL
51▸LBL "LOOFR"
52 RCL 14
53 5
54 X<Y?
55 RTN
56 X<>Y
57 STO "ULIM"
58 XEQ "BFRE"
59 512
60 ×
61 0.5
62 +
63 IP
64 X<>Y
65 328
66 ×
67 0.5
68 +
69 IP
70 240
71 X<>Y
72 -
73 X<>Y
74 INDEX "TVE"
75 STOEL
76 X<>Y
77 I+
78 STOEL
79 X<>Y
80 "TVA"
81 XEQ "RCLP"
82 XEQ "DLINE"
83 "TVE"
84 XEQ "RCLP"
85 INDEX "TVA"
86 STOEL
87 I+
88 X<>Y
89 STOEL
90 0.02
91 STO+ 14
92 GTO "LOOFR"
"CORNU" is the main program at all, with the main loop "LOOFR". CORNU does several things:
1) Initialisation creates two vectors {2x1} "TVA" a. "TVE"; TVA is loaded with (1; 240) left lower corner;
2) turns the display mode 3 on; load the variable 14 with 0.02 (store 14 is the bow length variable for
the spiral)
3) go into the main loop "LOOFR", at the beginning it tests wether store 14 is greater then 5., if true
the program stops here you can enter another value instead of 5. maybe 2 if you in hurry or 20 if you
are relaxing in your beachchair;
4) if store 14 isn't greater, the actual value of store 14 is given to "ULIM" and "BFRE" is called;
5) a lot of instruction for scaling the values for the right place in display;
6) before displaying the values are stored in "TVE"; why I use vectors, for me it was the possibility to load the
whole stack without getting errors with the order of stack (but you can use four single stores instead).
7) now, in x is x2 and y2 in y-stack; in sequenze the elements of "TVA" are loaded to the stack and we have this:
t -> y2
z -> x2
y -> y1
x -> x1
that is the input for "DLINE" q1 are the coordinates of the beginning of the line an q2 are the
coordinates where the line ends.
8) After Drawing the line, the elements of TVE are copied to TVA as the new starting point. The store
14 is increased by 0.02, here you can enter another value instead of 0.02 maybe 0.1 if you in hurry
or 0.005 if you are relaxing in your beachchair; after that it goes to the beginning of LOOFR.
93▸LBL "RCLP"
94 ASTO "VX"
95 INDEX IND "VX"
96 RCLEL
97 I+
98 RCLEL
99 X<>Y
100 RTN
"RCLP" is a helping routine, which can be directly coded in the main program, kind of a historic genesis.
101▸LBL "INVIR"
102 "GrMod"
103 ASTO 10
104 "ResX"
105 ASTO 11
106 "ResY"
107 ASTO 12
108 RTN
Maybe "INVIR" is nessecary for getting a stable display mode.
109▸LBL "DLINE"
110 X<>Y
111 R↓
112 X<>Y
113 STO 08
114 -
115 STO 00
116 R↓
117 STO 09
118 -
119 STO 01
120 RCL 00
121 SIGN
122 STO 02
123 RCL 01
124 SIGN
125 STO 03
126 RCL 02
127 X<0?
128 STO× 00
129 RCL 03
130 X<0?
131 STO× 01
132 RCL 01
133 RCL 00
134 X≥Y?
135 GTO 00
136 RCL 00
137 STO 04
138 0
139 STO 05
140 RCL 03
141 STO 06
142 GTO 01
143▸LBL 00
144 RCL 01
145 STO 04
146 RCL 00
147 STO 01
148 0
149 STO 06
150 RCL 02
151 STO 05
152▸LBL 01
153 RCL 01
154 2
155 ÷
156 STO 00
157 RCL 09
158 RCL 08
159 PIXEL
160 RCL 01
161 1ᴇ-5
162 +
163 STO 07
164▸LBL 02
165 DSE 07
166 GTO 03
167 GTO 06
168▸LBL 03
169 RCL 04
170 STO- 00
171 RCL 00
172 X≥0?
173 GTO 04
174 RCL 01
175 STO+ 00
176 RCL 02
177 STO+ 08
178 RCL 03
179 STO+ 09
180 GTO 05
181▸LBL 04
182 RCL 05
183 STO+ 08
184 RCL 06
185 STO+ 09
186▸LBL 05
187 RCL 09
188 RCL 08
189 PIXEL
190 GTO 02
191▸LBL 06
192 RTN
"DLINE" is the program for connecting two points of the display with a line (Bresenham algorithm)
The order of all programs isn't optimized and it is raw brutal force code.
```

Here is the rwa code:

### Re: Cornu Spiral (Fresnel integrals)

Oops quite a bug there.. I'll see what I can do to correct that.

Thanks, Werner

[Update: correction done, link now contains corrected program]

42S #3249S01123

DM42 #00345

DM42 #00345