home *** CD-ROM | disk | FTP | other *** search
- (***********************************************************)
- (* *)
- (* TURBO GRAPHIX version 1.06A *)
- (* *)
- (* Cubic spline module *)
- (* Module version 1.06A *)
- (* *)
- (* Copyright (C) 1985 by *)
- (* BORLAND International *)
- (* *)
- (***********************************************************)
-
- procedure Spline(A : PlotArray; N : integer; X1, XM : real;
- var B : PlotArray; M : integer);
- const
- MaxSpline = 50;
- type
- Vector = array[1..MaxSpline] of real;
- var
- X, Y, Z : Vector;
- I : integer;
- DeltaX : real;
-
- procedure Stg(Vector1, Vector2, Vector3 : Vector;
- var Vector4 : Vector; NPts : integer);
- var
- I : integer;
- Factor : real;
-
- begin
- for I := 2 to NPts do
- begin
- Factor := Vector1[I - 1] / Vector2[I - 1];
- Vector2[I] := Vector2[I] - Factor * Vector3[I - 1];
- Vector4[I] := Vector4[I] - Factor * Vector4[I - 1];
- end;
- Vector4[NPts] := Vector4[NPts] / Vector2[NPts];
- for I := 1 to NPts - 1 do
- Vector4[NPts - I] := (Vector4[NPts - I] - Vector3[NPts - I] *
- Vector4[NPts - I + 1]) / Vector2[NPts - I];
- end; { Stg }
-
- procedure Sc(X, Y : Vector; var Z : Vector; NPts : integer);
- var
- I : integer;
- D, C : Vector;
-
- begin
- D[1] := 1.0;
- C[1] := 0.5;
- Z[1] := 0.5;
- for I := 2 to NPts - 1 do
- begin
- D[I] := 2.0 * (X[I + 1] - X[I - 1]);
- C[I] := X[I + 1] - X[I];
- Z[I] := 6.0 * ((Y[I + 1] - Y[I]) / (X[I + 1] - X[I]) -
- (Y[I] - Y[I - 1]) / (X[I] - X[I - 1]));
- end;
- D[NPts] := 1.0;
- C[NPts - 1] := 0.0;
- C[NPts] := 0.0;
- Z[NPts] := 0.0;
- Stg(C, D, C, Z, NPts);
- end; { Sc }
-
- function Si(V : real; X, Y, Z : Vector; NPts : integer) : real;
- var
- I, J : integer;
- Dummy, Ai, Hi : real;
-
- begin
- if (V > X[1]) and (V < X[NPts]) then
- begin
- J := 1;
- repeat
- J := J + 1;
- I := NPts - J;
- Dummy := V - X[I];
- until (Dummy >= 0.0) or (I = 2);
- Hi := X[I + 1] - X[I];
- Ai := Dummy * (Z[I + 1] - Z[I]) / (6.0 * Hi) + 0.5 * Z[I];
- Ai := Dummy * Ai + (Y[I + 1] - Y[I]) / Hi - Hi *
- (2.0 * Z[I] + Z[I + 1]) / 6.0;
- Si := Dummy * Ai + Y[I];
- end
- else
- if V = X[1] then
- Si := Y[1]
- else
- Si := Y[NPts];
- end; { Si }
-
- procedure Sia(X, Y : Vector; NPts : integer; XInt : Vector;
- var YInt : Vector; N : integer);
- var
- I : integer;
- V3 : Vector;
-
- begin
- Sc(X, Y, V3, NPts);
- for I := 1 to N do
- YInt[I] := Si(XInt[I], X, Y, V3, NPts);
- end; { Sia }
-
- begin { Spline }
- if (abs(N) >= 2) and (abs(M) >= 2) then
- begin
- if ((X1 >= A[1, 1]) and (XM <= A[N, 1])) and (M >= 2) then
- begin
- DeltaX := (XM - X1) / (M - 1);
- for I := 1 to N do
- begin
- X[I] := A[I, 1];
- Y[I] := A[I, 2];
- end;
- for I := 2 to M - 1 do
- Z[I] := X1 + (I - 1) * DeltaX;
- Z[1] := X1;
- Z[M] := XM;
- Sia(X, Y, N, Z, Y, M);
- for I := 1 to M do
- begin
- B[I, 1] := Z[I];
- B[I, 2] := Y[I];
- end;
- end
- else
- Error(20, 7);
- end
- else
- Error(20, 4);
- end; { Spline }