unit Unit7; { This software has been designed and is CopyLefted by Han de Bruijn: (===) @-O^O-@ #/_\# ### } interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, Grafisch; type TForm1 = class(TForm) Image1: TImage; procedure Scheppen(Sender: TObject); procedure Toetsdruk(Sender: TObject; var Key: Char); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} var x,y : array[1..4] of double; hoek : double; keer : integer; procedure Tekst(nr : integer); { Display Enumerations } var Ox,Oy : integer; begin with Form1.Image1.Canvas do begin Ox := PenPos.x; Oy := PenPos.y; TextOut(Ox,Oy,IntToStr(nr)); MoveTo(Ox,Oy); end; end; procedure mapping(xi,eta : double; var p,q : double); { Bilinear interpolation at quadrilateral i.e. transformation (xi,eta) -> (x,y) . } begin p := (1/2-xi)*(1/2-eta)*x[1] + (1/2+xi)*(1/2-eta)*x[2] + (1/2-xi)*(1/2+eta)*x[3] + (1/2+xi)*(1/2+eta)*x[4]; q := (1/2-xi)*(1/2-eta)*y[1] + (1/2+xi)*(1/2-eta)*y[2] + (1/2-xi)*(1/2+eta)*y[3] + (1/2+xi)*(1/2+eta)*y[4]; end; procedure Raster; { Yellow Grid } begin with Form1.Image1.Canvas do begin Pen.Color := clYellow; MoveTo(x2i(-1/2),y2j(0)); LineTo(x2i(+1/2),y2j(0)); MoveTo(x2i(0),y2j(-1/2)); LineTo(x2i(0),y2j(+1/2)); MoveTo(x2i(-1/2),y2j(-1/2)); LineTo(x2i(+1/2),y2j(-1/2)); LineTo(x2i(+1/2),y2j(+1/2)); LineTo(x2i(-1/2),y2j(+1/2)); LineTo(x2i(-1/2),y2j(-1/2)); end; end; procedure Ouderschap; { Parent Square } var i,j : integer; begin Raster; { Grid } with Form1.Image1.Canvas do begin Brush.Color := clWhite; Pen.Color := clBlack; MoveTo(x2i(-1/2),y2j(-1/2)); Tekst(1); LineTo(x2i(+1/2),y2j(-1/2)); Tekst(2); LineTo(x2i(+1/2),y2j(+1/2)); Tekst(4); LineTo(x2i(-1/2),y2j(+1/2)); Tekst(3); LineTo(x2i(-1/2),y2j(-1/2)); Pen.Color := clRed; MoveTo(x2i(-1/2),y2j(-1/2)); LineTo(x2i(+1/2),y2j(+1/2)); MoveTo(x2i(-1/2),y2j(+1/2)); LineTo(x2i(+1/2),y2j(-1/2)); Brush.Color := clRed; i := x2i(0); j := y2j(0); Ellipse(i-5,j-5,i+5,j+5); end; Form1.Image1.Picture.SaveToFile('film\7Pma.bmp'); end; procedure Tekenen; { Special Quadrilateral } var xi,eta,p,q : double; i,j,m,n : integer; nr : string[2]; begin Raster; { Yellow grid } x[1] := -1/2; y[1] := 0; x[2] := +1/2; y[2] := -1/2; x[3] := +1/2; y[3] := +1/2; x[4] := hoek; y[4] := 0; { -1/2 < xi,eta < +1/2 } for j := 0 to Hoog do begin eta := j/Hoog-1/2; for i := 0 to Wijd do begin xi := i/Wijd-1/2; mapping(xi,eta,p,q); m := x2i(p); n := y2j(q); Form1.Image1.Canvas.Pixels[m,n] := clGray; end; end; { Curved boundary gray area } with Form1.Image1.Canvas do Moveto(x2i(x[1]),y2j(y[1])); xi := (x[4]-x[1])/(x[2]+x[3]-x[1]-x[4])/2; if xi > 1/2 then xi := 1/2; eta := xi; mapping(xi,eta,p,q); i := x2i(p); j := y2j(q); with Form1.Image1.Canvas do begin Pen.Color := clBlue; { green dot } Brush.Color := clBlue; Ellipse(i-5,j-5,i+5,j+5); { Mapping diagonals of square } Pen.Color := clRed; { red } LineTo(x2i(p),y2j(q)); end; with Form1.Image1.Canvas do Moveto(x2i(x[3]),y2j(y[3])); for i := 0 to Wijd do begin xi := i/Wijd-1/2; eta := -xi; mapping(xi,eta,p,q); Form1.Image1.Canvas.LineTo(x2i(p),y2j(q)); end; { Diagonals intersection point } with Form1.Image1.Canvas do begin Pen.Color := clRed; Brush.Color := clRed; p := (x[1]+x[2]+x[3]+x[4])/4; i := x2i(p); j := y2j(0); Ellipse(i-5,j-5,i+5,j+5); end; { Alternative x-coordinate of vertex(4): mark Green } Writeln('xi[4] = ',1/2,',',(1-6*hoek)/(4*hoek-6)); xi := (1-6*hoek)/(4*hoek-6); eta := xi; mapping(xi,eta,p,q); i := x2i(p); j := y2j(q); with Form1.Image1.Canvas do begin Pen.Color := clGreen; Brush.Color := clGreen; Ellipse(i-5,j-5,i+5,j+5); { Quadrilateral last but not least } Pen.Color := clBlack; Brush.Color := clWhite; Moveto(x2i(x[1]),y2j(y[1])); Tekst(1); Lineto(x2i(x[2]),y2j(y[2])); Tekst(2); Lineto(x2i(x[4]),y2j(y[4])); Tekst(4); Lineto(x2i(x[3]),y2j(y[3])); Tekst(3); Lineto(x2i(x[1]),y2j(y[1])); end; nr[1] := char((keer div 10)+byte('0')); nr[2] := char((keer mod 10)+byte('0')); Form1.Image1.Picture.SaveToFile('film\7P'+nr+'.bmp'); end; procedure Grafiek; { Graph of the function x(xi) for y = 0 and/or xi = eta } var i,j : integer; xi,eta,p,q,max : double; nr : string[2]; begin Raster; { Grid } with Form1.Image1.Canvas do begin MoveTo(x2i(-1/2),y2j(1/2)); i := PenPos.x; j := PenPos.y; TextOut(i+10,j+10,'x'); MoveTo(x2i(+1/2),y2j(-1/2)); i := PenPos.x; j := PenPos.y; TextOut(i-30,j-30,'xi'); end; mapping(0,0,p,q); { At Midpoint } with Form1.Image1.Canvas do begin Pen.Color := clRed; MoveTo(x2i(0),y2j(-1/2)); LineTo(x2i(0),y2j(p)); end; Form1.Image1.Canvas.MoveTo(x2i(-1/2),y2j(-1/2)); { The function x(xi) } for i := 0 to Wijd do begin xi := i/Wijd-1/2; eta := xi; mapping(xi,eta,p,q); Form1.Image1.Canvas.Pen.Color := clBlack; Form1.Image1.Canvas.LineTo(x2i(xi),y2j(p)); end; { Mark x-coordinate of vertex(4) } Form1.Image1.Canvas.Pen.Color := clGreen; Form1.Image1.Canvas.LineTo(x2i(-1/2),y2j(p)); { Mark alternative x-coordinate of vertex(4) } xi := (1-6*hoek)/(4*hoek-6); eta := xi; mapping(xi,eta,p,q); Form1.Image1.Canvas.MoveTo(x2i(xi),y2j(-1/2)); Form1.Image1.Canvas.LineTo(x2i(xi),y2j(p)); { Mark curved boundary of gray area } xi := -(x[4]-x[1])/(x[1]+x[4]-x[2]-x[3])/2; Form1.Image1.Canvas.MoveTo(x2i(xi),y2j(-1/2)); max := -sqr(x[4]-x[1])/(x[1]+x[4]-x[2]-x[3])/4 + (x[1]+x[2]+x[3]+x[4])/4; Form1.Image1.Canvas.Pen.Color := clBlue; Form1.Image1.Canvas.LineTo(x2i(xi),y2j(max)); Writeln(xi,max); nr[1] := char((keer div 10)+byte('0')); nr[2] := char((keer mod 10)+byte('0')); Form1.Image1.Picture.SaveToFile('film\7P'+nr+'.bmp'); end; procedure TForm1.Scheppen(Sender: TObject); { On Create } begin keer := 0; hoek := 0; TV(Form1.Image1); xmin := -0.7; xmax := +0.7; ymin := -0.7; ymax := +0.7; Form1.Image1.Canvas.Pen.Width := 2; Form1.Image1.Canvas.Font.Size := 15; ClearDevice; Ouderschap; end; procedure TForm1.Toetsdruk(Sender: TObject; var Key: Char); { On KeyPress } begin hoek := (keer div 2)*1/8; ClearDevice; case keer mod 2 of 0: Tekenen; 1: Grafiek; end; keer := keer + 1; end; end.