Post Reply 
Constant speed
04-18-2016, 07:27 AM (This post was last modified: 04-18-2016 08:07 AM by Martin Hepperle.)
Post: #13
RE: Constant speed
... and for illustration ... a Series-80 BASIC implementation for drawing a curve at "constant speed". You supply the two functions for x(p) and y(p) at the end of the code.

Besides the pure plotting data some additional values are calculated (e.g. the arc length of the curve). For speed you could strip some code and I also have left in some duplicated subexpressions for clarity.

The ticks option can be used to draw monorail tracks if you want to describe the track layout mathematically...

Code:

10 ! HP-85
20 ! Constant speed plotter
30 ! and path length integrator
40 ! for parametric function
50 ! Martin Hepperle, 2016 
60 !
70 ! initial values  
80 T=0 ! time
90 S=0 ! distance
100 P=0 ! parameter at time T
110 V=.5 ! velocity (const.)
120 ! integration parameters
130 T0=.1 ! time step
140 C0=.01 ! fin. diff. step
150 P9=4*PI ! end of parameter
160 ! distance for dt (const.)
170 S0=V*T0
180 C2=2*C0 ! speed up calc.
190 ! -- isotropic plotting --
200 GCLEAR
210 SCALE -(1.1*RATIO),1.1*RATIO,-1.1,1.1
220 MOVE FNX(P),FNY(P)
230 ! integration loop       
240 ! derivative dx/dp
250 D0=(FNX(P+C0)-FNX(P-C0))/C2
260 ! derivative dy/dp
270 D1=(FNY(P+C0)-FNY(P-C0))/C2
280 ! calculate dp
290 ! required for given dt
300 P0=S0/SQR(D0^2+D1^2)
310 ! -- plotting --
320 DRAW FNX(P),FNY(P)
330 ! --- ticks (optional)
340 ! derivative dy/dx
350 D2=D1/D0
360 F=ATN(D2)
370 F0=SIN(F)*.03
380 F1=COS(F)*.03
390 MOVE FNX(P)-F0,FNY(P)+F1
400 DRAW FNX(P)+F0,FNY(P)-F1
410 MOVE FNX(P),FNY(P)
420 ! --- end of ticks
430 ! advance to next
440 P=P+P0 ! parameter
450 T=T+T0 ! time
460 S=S+S0 ! distance so far
470 ! check for termination
480 IF P<=P9 THEN 250
490 PRINT "End Time  t=";T
500 PRINT "Distance  s=";S
510 PRINT "Parameter p=";P
520 ! accuracy check:
530 ! circle: sin(p),cos(p)
540 ! S/PI should be 2.0
550 PRINT "s/PI=";S/PI
560 END
570 ! ----------------
580 ! function x(p)
590 DEF FNX(P)
600 FNX=SIN(P)
610 FN END
620 ! ----------------
630 ! function y(p)
640 DEF FNY(P)
650 FNY=COS(P*.5)
660 FN END
670 ! ----------------
680 END

Of course, one could replace \(arctan()\), \(sin()\) and \(cos()\) by \(sqrt()\) expressions and simplify further.
Then you could replace
Code:

350 ! deleted
360 ! deleted
370 F0=D1*P0/S0*.03
380 F1=D0*P0/S0*.03
which leaves further room for simplification (common subexpressions ) but you must be aware of cases where \(dx/dp=0\) or \(dy/dp=0\).
The implementation will also hang if both derivatives are zero at the same time (singular point).

Martin
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Constant speed - Tugdual - 04-04-2016, 10:33 PM
RE: Constant speed - PANAMATIK - 04-05-2016, 07:01 AM
RE: Constant speed - Tugdual - 04-05-2016, 07:19 AM
RE: Constant speed - Dave Britten - 04-05-2016, 11:14 AM
RE: Constant speed - Tugdual - 04-05-2016, 06:04 PM
RE: Constant speed - Dave Britten - 04-06-2016, 11:16 AM
RE: Constant speed - Tugdual - 04-07-2016, 06:13 AM
RE: Constant speed - Dave Britten - 04-07-2016, 11:16 AM
RE: Constant speed - Martin Hepperle - 04-11-2016, 02:01 PM
RE: Constant speed - Tugdual - 04-11-2016, 03:53 PM
RE: Constant speed - Martin Hepperle - 04-13-2016, 03:29 PM
RE: Constant speed - Tugdual - 04-13-2016, 06:30 PM
RE: Constant speed - Martin Hepperle - 04-18-2016 07:27 AM



User(s) browsing this thread: 1 Guest(s)