Лабораторна робота №3
ПАРАЛЕЛЬНІ І КОСОКУТНІ ПРОЕКЦІЇ
Мета роботи: Ознайомлення з елементарним математичним апаратом плоских геометричних проекцій.
Хід роботи
Результати роботи програми приведені на наступних малюнках:
/
/
Текст програми
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, Math;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Panel1: TPanel;
LabeledEdit1: TLabeledEdit;
Button1: TButton;
LabeledEdit2: TLabeledEdit;
LabeledEdit3: TLabeledEdit;
LabeledEdit4: TLabeledEdit;
Panel2: TPanel;
LabeledEdit5: TLabeledEdit;
Button2: TButton;
LabeledEdit6: TLabeledEdit;
LabeledEdit7: TLabeledEdit;
PaintBox1: TPaintBox;
procedure draw_axises();
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure drawPoint();
procedure draw_Proection();
procedure draw_Plane();
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
xc,yc:integer;
alpha:double;
llength,wwidth:integer;
d:double;
point, proection: Array [1..4] of double;
implementation
uses DateUtils;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
xc:=PaintBox1.Width div 2;
yc:=PaintBox1.Height div 2;
alpha:=pi/6;
llength:=PaintBox1.Height div 10;
wwidth:=6;
end;
procedure TForm1.draw_axises();
var
x,y,z,i:integer;
dz:double;
begin
with PaintBox1.Canvas do
begin
Pen.Color:=clBlack;
Pen.Width:=1;
MoveTo(xc,yc);
LineTo(PaintBox1.Width,yc);
MoveTo(xc,0);
LineTo(xc,round((PaintBox1.Height)/2));
z:=xc;//round(sqrt(sqr(xc)+sqr(yc)));
x:=-round(z*cos(alpha)+0.5);
y:=-round(z*sin(alpha)+0.5);
MoveTo(xc,yc);
LineTo(xc+x,yc-y);
x:=xc+llength;
while (x<PaintBox1.Width) do
begin
MoveTo(x,yc-wwidth);
LineTo(x,yc+wwidth);
x:=x+llength;
end;
y:=yc-llength;
while (y>0) do
begin
MoveTo(xc-wwidth,y);
LineTo(xc+wwidth,y);
y:=y-llength;
end;
dz:=llength*sin(alpha);
z:=round(dz+0.5);
i:=2;
while (z<xc) do
begin
x:=-round(z*cos(alpha)+0.5);
y:=-round(z*sin(alpha)+0.5);
x:=xc+x;
y:=yc-y;
MoveTo(x,y);
LineTo(x,y-2*wwidth);
MoveTo(x,y);
LineTo(x+2*wwidth,y);
z:=round(i*dz+0.5);//round(llength*sin(alpha)+0.5);
i:=i+1;
end;
TextOut(round(PaintBox1.Width*0.98),round(yc*1.1),'X');
TextOut(round(xc*1.05),round(PaintBox1.Height*0.02),'Y');
TextOut(x,y,'Z');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
j:integer;
begin
point[1]:=strtofloat(LabeledEdit1.Text);
point[2]:=strtofloat(LabeledEdit2.Text);
point[3]:=strtofloat(LabeledEdit3.Text);
point[4]:=1;
d:=strtofloat(LabeledEdit4.Text);
proection[3]:=d;
proection[1]:=d*point[1]/point[3];
proection[2]:=d*point[2]/point[3];
draw_Plane();
draw_axises();
drawPoint();
draw_Proection();
end;
procedure TForm1.drawPoint();
var
x,y:integer;
xx,yy:integer;
begin
x:=round(0.5+(point[1]-point[3]*cos(alpha)*sin(alpha))*llength+xc);
y:=round(yc-(point[2]-point[3]*sin(alpha)*sin(alpha))*llength+0.5);
with PaintBox1.Canvas do
begin
Pen.Width:=5;
Pen.Color:=clYellow;
MoveTo(x-1,y-1);
Ellipse(x-1,y-1,x+1,y+1);
Pen.Width:=1;
MoveTo(x,y);
Pen.Color:=clYellow;
Pen.Style:=psDash;
LineTo(round(0.5+(point[1])*llength+xc),round(yc-(point[2])*llength+0.5));
MoveTo(round(0.5+(point[1])*llength+xc),round(yc-(point[2])*llength+0.5));
LineTo(round(0.5+xc),round(yc-(point[2])*llength+0.5));
MoveTo(x,y);
xx:=round(0.5+(point[1]-point[3]*cos(alpha)*sin(alpha))*llength+xc);
yy:=round(yc-(0-point[3]*sin(alpha)*sin(alpha))*llength+0.5);
LineTo(xx,yy);
MoveTo(xx,yy);
x:=round((0-point[3]*cos(alpha)*sin(alpha))*llength+xc+0.5);
y:=round(yc-(0-point[3]*sin(alpha)*sin(alpha))*llength+0.5);
LineTo(x,y);
MoveTo(xx,yy);
x:=round((point[1])*llength+xc+0.5);
y:=round(yc);
LineTo(x,y);
Pen.Style:=psSolid;
end;
end;
procedure TForm1.draw_Proection();
var
x,y,xx,yy:integer;
begin
x:=round((proection[1]-proection[3]*cos(alpha)*sin(alpha))*llength+xc+0.5);
y:=round(yc-(proection[2]-proection[3]*sin(alpha)*sin(alpha))*llength+0.5);
with PaintBox1.Canvas do
begin
Pen.Width:=3;
Pen.Color:=clRed;
MoveTo(x-1,y-1);
Ellipse(x-1,y-1,x+1,y+1);
Pen.Color:=clBlack;
Pen.Width:=1;
MoveTo(x,y);
LineTo(xc,yc);
MoveTo(x,y);
x:=round((point[1]-point[3]*cos(alpha)*sin(alpha))*llength+xc+0.5);
y:=round(yc-(point[2]-point[3]*sin(alpha)*sin(alpha))*llength+0.5);
LineTo(x,y);
x:=round((proection[1]-proection[3]*cos(alpha)*sin(alpha))*llength+xc+0.5);
y:=round(yc-(proection[2]-proection[3]*sin(alpha)*sin(alpha))*llength+0.5);
Pen.Color:=clRed;
Pen.Width:=1;
Pen.Style:=psDash;
MoveTo(x,y);
LineTo(round(0.5+(proection[1])*llength+xc),round(yc-(proection[2])*llength+0.5));
MoveTo(round(0.5+(proection[1])*llength+xc),round(yc-(proection[2])*llength+0.5));
LineTo(round(0.5+xc),round(yc-(proection[2])*llength+0.5));
MoveTo(x,y);
xx:=round((proection[1]-proection[3]*cos(alpha)*sin(alpha))*llength+xc+0.5);
yy:=round(yc-(0-proection[3]*sin(alpha)*sin(alpha))*llength+0.5);
LineTo(xx,yy);
MoveTo(xx,yy);
x:=round((0-proection[3]*cos(alpha)*sin(alpha))*llength+xc+0.5);
y:=round(yc-(0-proection[3]*sin(alpha)*sin(alpha))*llength+0.5);
LineTo(x,y);
MoveTo(xx,yy);
x:=round((proection[1])*llength+xc+0.5);
y:=round(yc);
LineTo(x,y);
Pen.Style:=psSolid;
end;
end;
procedure TForm1.draw_Plane();
var
x,y:integer;
begin
x:=round((0-d*cos(alpha)*sin(alpha))*llength+xc+0.5);
y:=round(yc-(0-d*sin(alpha)*sin(alpha))*llength+0.5);
PaintBox1.Refresh;
with PaintBox1.Canvas do
begin
Pen.Color:=clBlue;
Pen.Width:=1;
Rectangle(x,y,PaintBox1.Width-20,20);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
j:integer;
alpha,beta,xp:double;
begin
PaintBox1.Refresh;
xp:=strtofloat(LabeledEdit5.Text);
point[1]:=xp;
point[2]:=0;
point[3]:=0;
point[4]:=1;
alpha:=strtofloat(LabeledEdit6.Text);
beta:=strtofloat(LabeledEdit7.Text);
proection[1]:=0;
proection[2]:=xp*sin(alpha*pi/180)/tan(beta*pi/180);
proection[3]:=xp*cos(alpha*pi/180)/tan(beta*pi/180);
draw_axises();
drawPoint();
draw_Proection();
end;
end.
Висновок: на цій лабораторній роботі, я ознайомився з елементарним математичним апаратом плоских геометричних проекцій, та написав програму яка його реалізує.