home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Party 1994: Try This At Home
/
disk_image.bin
/
source
/
gallery
/
subdirs.exe
/
MAP
/
TPATH.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1993-07-19
|
4KB
|
181 lines
{$N+}
type real=single;
type TPoint = array[0..2] of real;
TSplineFac = array[0..3] of real;
var NumPts, SelPt : integer;
P : array[1..1000] of TPoint;
Le: array[1..1000] of real;
PTnum : integer;
PT: array[1..100] of TPoint;
procedure LoadPoints(s:string);
var f : file;
i : integer;
begin
assign(f,s); reset(f,1);
blockread(f,SelPt,2);
blockread(f,NumPts,2);
blockread(f,P,NumPts*SizeOf(TPoint));
close(f);
end;
procedure SplineFac( var F : TSplineFac; xm1,x0,x1,x2 : real );
begin
F[0] := (xm1+4*x0+x1)/6;
F[1] := (-xm1+x1)/2;
F[2] := (xm1+x1)/2-x0;
F[3] := (-xm1+3*(x0-x1)+x2)/6;
end;
procedure CalculateLengths;
var L : real;
i,j,k : integer;
F : array[0..1] of TSplineFac;
t,dx,dy : real;
begin
L := 0;
Le[2] := L;
for i := 2 to NumPts-2 do begin
for j := 0 to 1 do begin
SplineFac( F[j], P[i-1,j], P[i,j], P[i+1,j], P[i+2,j] );
end;
for k := 0 to 19 do begin
t := k/20;
dx := F[0,1]+t*(2*F[0,2]+t*3*F[0,3]);
dy := F[1,1]+t*(2*F[1,2]+t*3*F[1,3]);
L := L + sqrt(sqr(dx)+sqr(dy))/20;
end;
Le[i+1]:= L;
writeln('punto ',i:4,' T = ',P[i,2],' L = ',L);
end;
Le[NumPts-1] := L;
Le[NumPts] := L;
end;
procedure MakeSpeedCurve;
var i : integer;
begin
PTnum := 0;
PT[1,0] := 0; PT[1,1] := 0; { force time := 0; length := 0 }
PT[2] := PT[1];
PTnum := 3;
for i := 2 to NumPts-2 do
if P[i,2]<>-1 then begin
PT[PTnum,0] := P[i,2];
PT[PTnum,1] := Le[i];
inc(PTnum);
end;
PT[PTnum] := PT[PTnum-1];
inc(PTnum);
PT[PTnum] := PT[PTnum-2];
end;
var Iname, Oname : string;
procedure OutputTimed;
var O : Text;
LT : array[0..1] of TSplineFac;
Q,dQ : TPoint;
i,j,k : integer;
s,tt,ll : real;
C : longint;
procedure FindPos( l : real; var Q, dQ : Tpoint );
var i,j,k : integer;
t,m,xx,yy,dx,dy : real;
F : array[0..1] of TSplineFac;
begin
i := 1;
while (Le[i+1]<l) and (i<NumPts-2) do inc(i);
for j := 0 to 1 do begin
SplineFac( F[j], P[i-1,j], P[i,j], P[i+1,j], P[i+2,j] );
end;
m := Le[i];
t := 0;
k := 1;
while (m<l) do begin
t := k/200;
dx := F[0,1]+t*(2*F[0,2]+t*3*F[0,3]);
dy := F[1,1]+t*(2*F[1,2]+t*3*F[1,3]);
m := m + sqrt(sqr(dx)+sqr(dy))/200;
inc(k);
end;
xx := F[0,0]+t*(F[0,1]+t*(F[0,2]+t*F[0,3]));
yy := F[1,0]+t*(F[1,1]+t*(F[1,2]+t*F[1,3]));
Q[0] := xx; Q[1] := yy;
dQ[0] := dx; dQ[1] := dy;
end;
Function Angle(dQ:Tpoint) : real;
var a : real;
begin
if dQ[0]=0 then dQ[0] := dQ[1]/1E6;
a := ArcTan( -dQ[1]/dQ[0] );
if dQ[0]>0 then a := a+PI else if dQ[1]<0 then a := a + 2*PI;
Angle := a*180/PI;
end;
begin
assign(O, Oname); rewrite(O);
C := 0;
tt := 0;
write(O,tt:9:3,' ',(64-P[1,0]):10:6,' ',P[1,1]:10:6,' ');
for i := 2 to PTnum-2 do begin
for j := 0 to 1 do
SplineFac( LT[j], PT[i-1,j], PT[i,j], PT[i+1,j], PT[i+2,j] );
for k := 0 to 19 do begin
s := k/20;
tt := LT[0,0]+s*(LT[0,1]+s*(LT[0,2]+s*LT[0,3]));
ll := LT[1,0]+s*(LT[1,1]+s*(LT[1,2]+s*LT[1,3]));
FindPos(ll, Q, dQ);
if C=0 then writeln(O,Angle(dQ):7:3);
writeln(O,tt:9:3,' ',(64-Q[0]):10:6,' ',Q[1]:10:6,' ',Angle(dQ):7:3);
inc(C);
end;
end;
close(O);
end;
BEGIN
writeln('TPATH - synchro fit for PPATH data files // A.R-M. 7/93');
writeln;
if paramcount<2 then begin
writeln('Usage: TPATH InputFile OutputFile');
Halt(1);
end;
Iname := ParamStr(1);
Oname := ParamStr(2);
LoadPoints(Iname);
CalculateLengths;
MakeSpeedCurve;
OutputTimed;
END.