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 do print(`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 then OK := TRUE: fi: od: if FLAG = 1 then OK := FALSE: while OK = FALSE do print(`Input n `): N := scanf(`%d`)[1]:print(`n = `):print(N): if N > 0 then OK := 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 do print(`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]): else print(`Number must be a positive integer `): fi: od: fi: if FLAG = 2 then print(`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" then print(`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 do print(`Input n `): N := scanf(` %d`)[1]:print(`n = `):print(N): if N > 0 then OK := 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 do X[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): else print(`Number must be a positive integer `): fi: od: else print(`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 then print(`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 then print(`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): else OUP := 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 1 for I1 from 0 to N-1 do # Step 2 A0[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 3 fprintf(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 then fclose(OUP): print(`Output file `,NAME,` created successfully`): fi: fi: # Step 4 SUVUaGlzfmlzfnRoZX5CZXppZXJ+Q3VydmV+QWxnb3JpdGhtLnwrRzYi STlDaG9pY2V+b2Z+aW5wdXR+bWV0aG9kOn5HNiI= SUcxLn5JbnB1dH5lbnRyeX5ieX5lbnRyeX5mcm9tfmtleWJvYXJkfkc2Ig== SUAyLn5JbnB1dH5kYXRhfmZyb21+YX50ZXh0fmZpbGV+RzYi STZDaG9vc2V+MX5vcn4yfnBsZWFzZX5HNiI= SSlFbnRyeX49fkc2Ig== IiIi SSlJbnB1dH5ufkc2Ig== SSVufj1+RzYi IiIj ST1JbnB1dH5YWzBdLFlbMF0sWCtbMF0sWStbMF1+RzYi STZzZXBhcmF0ZWR+Ynl+YX5zcGFjZX5HNiI= SS1FbnRyaWVzfmFyZX5HNiI= NiYkIiIhRiRGIyQiIiYhIiIkIiNEISIj SThJbnB1dH5YKGkpLFkoaSl+Zm9yfml+PUc2Ig== IiIi STRzZXBhcmF0ZWR+Ynl+c3BhY2V+RzYi SS1FbnRyaWVzfmFyZX5HNiI= NiQkIiIlIiIhJCIiJ0Yl STtJbnB1dH5YLShpKSxZLShpKX5mb3J+aX49fkc2Ig== IiIi STRzZXBhcmF0ZWR+Ynl+c3BhY2V+RzYi SS1FbnRyaWVzfmFyZX5HNiI= NiQkIiNOISIiJCIiKCIiIQ== STtJbnB1dH5YKyhpKSxZKyhpKX5mb3J+aX49fkc2Ig== IiIi STRzZXBhcmF0ZWR+Ynl+c3BhY2V+RzYi SS1FbnRyaWVzfmFyZX5HNiI= NiQkIiNYISIiJCIiJiIiIQ== ST1JbnB1dH5YW25dLFlbbl0sWC1bbl0sWS1bbl1+RzYi STZzZXBhcmF0ZWR+Ynl+YX5zcGFjZX5HNiI= SS1FbnRyaWVzfmFyZX5HNiI= NiYkIiInIiIhJCIiIkYlJCIiKEYlJCIiI0Yl STtTZWxlY3R+b3V0cHV0fmRlc3RpbmF0aW9ufkc2Ig== SSsxLn5TY3JlZW5+RzYi SS4yLn5UZXh0fmZpbGV+RzYi SS5FbnRlcn4xfm9yfjJ+RzYi SSlFbnRyeX49fkc2Ig== IiIi BEZIER CURVE ALGORITHM A0 A1 A2 A3 on the first line B0 B1 B2 B3 on the second line 0.000000 1.500000 7.500000 -5.000000 0.000000 0.750000 19.500000 -14.250000 4.000000 1.500000 6.000000 -5.500000 6.000000 -3.000000 -6.000000 4.000000 JSFH