restart:# BEZIER CURVE ALGORITHM 3.6## To construct the cubic Bezier curves C0, ..., Cn-1 in# parameter form, where Ci is represented by## (xi(t),yi(t)) = ( a0(i) + a1(i)*t + a2(i)*t^2 + a3(i)*t^3,# b0(i) + b1(i)*t + b2(i)*t^2 + b3(i)*t^3)## for 0 <= t <= 1 as determined by the left endpoint (x(i),y(i)),# left guidepoint (x+(i),y+(i)), right endpoint (x(i+1),y(i+1)) and# right guidepoint (x-(i+1),y-(i+1)) for each i = 0, 1, ... , n-1:## INPUT n, ( (x(i),y(i)), i = 0,...,n ),# ( (x+(i),y+(i)), i = 0,...,n-1 ),# ( (x-(i),y-(i)), i = 1,...,n ).## OUTPUT coefficients ( a0(i), a1(i), a2(i), a3(i),# b0(i), b1(i), b2(i), b3(i), i = 0, ... , n-1 ).print(`This is the Bezier Curve Algorithm.\134n`):OK := FALSE:while OK = FALSE doprint(`Choice of input method: `):print(`1. Input entry by entry from keyboard `):print(`2. Input data from a text file `):print(`Choose 1 or 2 please `):FLAG := scanf(`%d`)[1]:print(`Entry = `):print(FLAG):if FLAG = 1 or FLAG = 2 thenOK := TRUE:fi:od:if FLAG = 1 thenOK := FALSE:while OK = FALSE doprint(`Input n `):N := scanf(`%d`)[1]:print(`n = `):print(N):if N > 0 thenOK := TRUE:print(`Input X[0],Y[0],X+[0],Y+[0] `):print(`separated by a space `):X[0] := scanf(`%f`)[1]:Y[0] := scanf(`%f`)[1]:XPL[0] := scanf(`%f`)[1]:YPL[0] := scanf(`%f`)[1]:print(`Entries are `):print(X[0],Y[0],XPL[0],YPL[0]):for I1 from 1 to N-1 doprint(`Input X(i),Y(i) for i =`):print(I1):print(`separated by space `):X[I1] := scanf(`%f`)[1]:Y[I1] := scanf(`%f`)[1]:print(`Entries are `):print(X[I1],Y[I1]):print(`Input X-(i),Y-(i) for i = `):print(I1):print(`separated by space `):XMI[I1-1] := scanf(`%f`)[1]:YMI[I1-1] := scanf(`%f`)[1]:print(`Entries are `):print(XMI[I1-1],YMI[I1-1]):print(`Input X+(i),Y+(i) for i = `):print(I1):print(`separated by space `):XPL[I1] := scanf(`%f`)[1]:YPL[I1] := scanf(`%f`)[1]:print(`Entries are `):print(XPL[I1],YPL[I1]):od:print(`Input X[n],Y[n],X-[n],Y-[n] `):print(`separated by a space `):X[N] := scanf(`%f`)[1]:Y[N] := scanf(`%f`)[1]:XMI[N-1] := scanf(`%f`)[1]:YMI[N-1] := scanf(`%f`)[1]:print(`Entries are `):print(X[N],Y[N],XMI[N-1],YMI[N-1]):elseprint(`Number must be a positive integer `):fi:od:fi:if FLAG = 2 thenprint(`Has a text file been created with the data as follows ? `):print(`X[0] Y[0] X+[0] Y+[0] `):print(`X[1] Y[1] X-[1] Y-[1] X+[1] Y+[1] `):print(`... `):print(`X[n-1] Y[n-1] X-[n-1] Y-[n-1] X+[n-1] Y+[n-1] `):print(`X[n] Y[n] X-[n] Y-[n] `):print(`Enter Y or N `):A := scanf(` %c`)[1]:print(`Entry = `):print(A):if A = "Y" or A = "y" thenprint(`Input the file name in the form - `):print(`drive:\134\134name.ext `):print(`For example: A:\134\134DATA.DTA `):NAME := scanf(`%s`)[1]:print(`Entry = `):print(NAME):INP := fopen(NAME,READ,TEXT):OK := FALSE:while OK = FALSE doprint(`Input n `):N := scanf(` %d`)[1]:print(`n = `):print(N):if N > 0 thenOK := TRUE:X[0] := fscanf(INP, `%f`)[1]:Y[0] := fscanf(INP, `%f`)[1]:XPL[0] := fscanf(INP, `%f`)[1]:YPL[0] := fscanf(INP, `%f`)[1]:for I1 from 1 to N-1 doX[I1] := fscanf(INP, `%f`)[1]:Y[I1] := fscanf(INP, `%f`)[1]:XMI[I1-1] := fscanf(INP, `%f`)[1]:YMI[I1-1] := fscanf(INP, `%f`)[1]:XPL[I1] := fscanf(INP, `%f`)[1]:YPL[I1] := fscanf(INP, `%f`)[1]:od:X[N] := fscanf(INP, `%f`)[1]:Y[N] := fscanf(INP, `%f`)[1]:XMI[N-1] := fscanf(INP, `%f`)[1]:YMI[N-1] := fscanf(INP, `%f`)[1]:fclose(INP):elseprint(`Number must be a positive integer `):fi:od:elseprint(`Please create the input file as indicated. `):print(`The program will end so the input file can `):print(`be created. `):OK := FALSE:fi:fi:if OK = TRUE thenprint(`Select output destination `):print(`1. Screen `):print(`2. Text file `):print(`Enter 1 or 2 `):FLAG := scanf(`%d`)[1]:print(`Entry = `):print(FLAG):if FLAG = 2 thenprint(`Input the file name in the form - drive:\134\134name.ext `):print(`For example: A:\134\134OUTPUT.DTA `):NAME := scanf(`%s`)[1]:print(`Entry = `):print(NAME):OUP := fopen(NAME,WRITE,TEXT):elseOUP := default:fi:fprintf(OUP, `BEZIER CURVE ALGORITHM\134n\134n`):fprintf(OUP, ` A0 A1 A2 A3`):fprintf(OUP,` on the first line\134n`):fprintf(OUP, ` B0 B1 B2 B3`):fprintf(OUP,` on the second line\134n`):# Step 1for I1 from 0 to N-1 do# Step 2A0[I1] := X[I1]:B0[I1] := Y[I1]:A1[I1] := 3*(XPL[I1] - X[I1]):B1[I1] := 3*(YPL[I1] - Y[I1]):A2[I1] := 3*(X[I1]+XMI[I1]-2*XPL[I1]):B2[I1] := 3*(Y[I1]+YMI[I1]-2*YPL[I1]):A3[I1] := X[I1+1]-X[I1]+3*XPL[I1]-3*XMI[I1]:B3[I1] := Y[I1+1]-Y[I1]+3*YPL[I1]-3*YMI[I1]:# Step 3fprintf(OUP,` %11.6f %11.6f %11.6f %11.6f\134n`, A0[I1], A1[I1], A2[I1], A3[I1]):fprintf(OUP,` %11.6f %11.6f %11.6f %11.6f\134n`, B0[I1], B1[I1], B2[I1], B3[I1]):fprintf(OUP, `\134n`):od:if OUP <> default thenfclose(OUP):print(`Output file `,NAME,` created successfully`):fi:fi:# Step 4JSFH