Assalamualaikum...
berbagi sedikit ilmu lagi :)
full code :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
ScrollBox1: TScrollBox;
Bingkai: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
xp1: TEdit;
xp2: TEdit;
xp3: TEdit;
xp4: TEdit;
xp5: TEdit;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
yp1: TEdit;
yp2: TEdit;
yp3: TEdit;
yp4: TEdit;
yp5: TEdit;
zp1: TEdit;
zp2: TEdit;
zp3: TEdit;
zp4: TEdit;
zp5: TEdit;
xpp1: TEdit;
xpp2: TEdit;
xpp3: TEdit;
xpp4: TEdit;
xpp5: TEdit;
ypp1: TEdit;
ypp2: TEdit;
ypp3: TEdit;
ypp4: TEdit;
ypp5: TEdit;
Label12: TLabel;
Label13: TLabel;
txalp: TEdit;
txpsi: TEdit;
Label14: TLabel;
Label15: TLabel;
btncr: TButton;
btncl: TButton;
btnex: TButton;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
xp6: TEdit;
xp7: TEdit;
xp8: TEdit;
yp6: TEdit;
yp7: TEdit;
yp8: TEdit;
zp6: TEdit;
zp7: TEdit;
zp8: TEdit;
xpp6: TEdit;
xpp7: TEdit;
xpp8: TEdit;
ypp6: TEdit;
ypp7: TEdit;
ypp8: TEdit;
Label16: TLabel;
editM: TEdit;
btn1titik: TButton;
btnTrans: TButton;
btnScaling: TButton;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
editTx: TEdit;
editTy: TEdit;
editTz: TEdit;
Label20: TLabel;
editS: TEdit;
btnRotasi: TButton;
Label21: TLabel;
EditSudut: TEdit;
RadioGroupSumbu: TRadioGroup;
procedure FormShow(Sender: TObject);
procedure btnclClick(Sender: TObject);
procedure btnexClick(Sender: TObject);
procedure btncrClick(Sender: TObject);
procedure btn1titikClick(Sender: TObject);
procedure btnTransClick(Sender: TObject);
procedure btnScalingClick(Sender: TObject);
procedure btnRotasiClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses math;
{$R *.dfm}
var
x : array [1..8] of Integer;
y : array [1..8] of Integer;
z : array [1..8] of Integer;
xp : array [1..8] of Integer;
yp : array [1..8] of Integer;
zp : array [1..8] of Integer;
alpha,psi :integer;
l1, S : Double;
Tx,Ty,Tz, i, mode : Integer;
sudut : double;
procedure TForm1.FormShow(Sender: TObject);
begin
Bingkai.Canvas.Pen.Color := clRed;
Bingkai.Canvas.Pen.Style := psDash;
Bingkai.Canvas.MoveTo(Bingkai.Width div 2, 0);
Bingkai.Canvas.LineTo(Bingkai.Width div 2,Bingkai.Height);
Bingkai.Canvas.MoveTo(0, Bingkai.Height div 2);
Bingkai.Canvas.LineTo(Bingkai.Width,Bingkai.Height div 2);
end;
procedure TForm1.btnclClick(Sender: TObject);
begin
Bingkai.Canvas.Pen.Color := clWhite;
Bingkai.Canvas.Brush.Color := clWhite;
Bingkai.Canvas.Brush.Style := bsSolid;
Bingkai.Canvas.Pen.Style := psSolid;
Bingkai.Canvas.Rectangle(0,0,Bingkai.Width,Bingkai.Height);
FormShow(nil);
end;
procedure TForm1.btnexClick(Sender: TObject);
begin
Close;
end;
procedure TForm1.btncrClick(Sender: TObject);
var
srad1,srad2 : Double;
begin
mode:=0;
alpha := StrtoInt (txalp.Text);
psi := StrtoInt (txpsi.Text);
srad1 := alpha * PI / 180;
srad2 := psi * PI / 180;
l1 := 1/Tan(srad1);
x[1] := StrtoInt(xp1.Text) ;
y[1] := StrtoInt(yp1.Text) ;
Z[1] := StrtoInt(zp1.Text) ;
x[2] := StrtoInt(xp2.Text) ;
y[2] := StrtoInt(yp2.Text) ;
Z[2] := StrtoInt(zp2.Text) ;
x[3] := StrtoInt(xp3.Text) ;
y[3] := StrtoInt(yp3.Text) ;
Z[3] := StrtoInt(zp3.Text) ;
x[4] := StrtoInt(xp4.Text) ;
y[4] := StrtoInt(yp4.Text) ;
Z[4] := StrtoInt(zp4.Text) ;
x[5] := StrtoInt(xp5.Text) ;
y[5] := StrtoInt(yp5.Text) ;
Z[5] := StrtoInt(zp5.Text) ;
x[6] := StrtoInt(xp6.Text) ;
y[6] := StrtoInt(yp6.Text) ;
Z[6] := StrtoInt(zp6.Text) ;
x[7] := StrtoInt(xp7.Text) ;
y[7] := StrtoInt(yp7.Text) ;
Z[7] := StrtoInt(zp7.Text) ;
x[8] := StrtoInt(xp8.Text) ;
y[8] := StrtoInt(yp8.Text) ;
Z[8] := StrtoInt(zp8.Text) ;
For i := 1 To 8 Do
begin
xp[i] := round(x[i]+ z[i]*l1*Cos(srad2));
yp[i] := round(y[i]+ z[i]*l1*Sin(srad2));
end;
xpp1.Text := FloattoStr (xp[1]);
xpp2.Text := FloattoStr (xp[2]);
xpp3.Text := FloattoStr (xp[3]);
xpp4.Text := FloattoStr (xp[4]);
xpp5.Text := FloattoStr (xp[5]);
xpp6.Text := FloattoStr (xp[6]);
xpp7.Text := FloattoStr (xp[7]);
xpp8.Text := FloattoStr (xp[8]);
ypp1.Text := FloattoStr (yp[1]);
ypp2.Text := FloattoStr (yp[2]);
ypp3.Text := FloattoStr (yp[3]);
ypp4.Text := FloattoStr (yp[4]);
ypp5.Text := FloattoStr (yp[5]);
ypp6.Text := FloattoStr (yp[6]);
ypp7.Text := FloattoStr (yp[7]);
ypp8.Text := FloattoStr (yp[8]);
btnclClick(sender);
Bingkai.Canvas.Pen.Color := clBlue;
Bingkai.Canvas.Pen.Style := psSolid;
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[4]),Round(Bingkai.Height div 2 - yp[4]));
For i := 1 To 4 Do
begin
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
end;
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[8]),Round(Bingkai.Height div 2 - yp[8]));
For i := 5 To 8 Do
begin
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
end;
For i := 1 To 4 Do
begin
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i+4]),Round(Bingkai.Height div 2 - yp[i+4]));
end;
end;
procedure TForm1.btn1titikClick(Sender: TObject);
var
M : double;
begin
M := StrtoInt (editM.Text);
x[1] := StrtoInt(xp1.Text) ;
y[1] := StrtoInt(yp1.Text) ;
Z[1] := StrtoInt(zp1.Text) ;
x[2] := StrtoInt(xp2.Text) ;
y[2] := StrtoInt(yp2.Text) ;
Z[2] := StrtoInt(zp2.Text) ;
x[3] := StrtoInt(xp3.Text) ;
y[3] := StrtoInt(yp3.Text) ;
Z[3] := StrtoInt(zp3.Text) ;
x[4] := StrtoInt(xp4.Text) ;
y[4] := StrtoInt(yp4.Text) ;
Z[4] := StrtoInt(zp4.Text) ;
x[5] := StrtoInt(xp5.Text) ;
y[5] := StrtoInt(yp5.Text) ;
Z[5] := StrtoInt(zp5.Text) ;
x[6] := StrtoInt(xp6.Text) ;
y[6] := StrtoInt(yp6.Text) ;
Z[6] := StrtoInt(zp6.Text) ;
x[7] := StrtoInt(xp7.Text) ;
y[7] := StrtoInt(yp7.Text) ;
Z[7] := StrtoInt(zp7.Text) ;
x[8] := StrtoInt(xp8.Text) ;
y[8] := StrtoInt(yp8.Text) ;
Z[8] := StrtoInt(zp8.Text) ;
For i := 1 To 8 Do
begin
xp[i] := round(x[i] / (1 - (z[i]/M)));
yp[i] := round(y[i] / (1 - (z[i]/M)));
end;
xpp1.Text := FloattoStr (xp[1]);
xpp2.Text := FloattoStr (xp[2]);
xpp3.Text := FloattoStr (xp[3]);
xpp4.Text := FloattoStr (xp[4]);
xpp5.Text := FloattoStr (xp[5]);
xpp6.Text := FloattoStr (xp[6]);
xpp7.Text := FloattoStr (xp[7]);
xpp8.Text := FloattoStr (xp[8]);
ypp1.Text := FloattoStr (yp[1]);
ypp2.Text := FloattoStr (yp[2]);
ypp3.Text := FloattoStr (yp[3]);
ypp4.Text := FloattoStr (yp[4]);
ypp5.Text := FloattoStr (yp[5]);
ypp6.Text := FloattoStr (yp[6]);
ypp7.Text := FloattoStr (yp[7]);
ypp8.Text := FloattoStr (yp[8]);
btnclClick(Sender);
Bingkai.Canvas.Pen.Color := clBlue;
Bingkai.Canvas.Pen.Style := psSolid;
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[4]),Round(Bingkai.Height div 2 - yp[4]));
For i := 1 To 4 Do
begin
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
end;
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[8]),Round(Bingkai.Height div 2 - yp[8]));
For i := 5 To 8 Do
begin
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
end;
For i := 1 To 4 Do
begin
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i+4]),Round(Bingkai.Height div 2 - yp[i+4]));
end;
mode:=1;
end;
procedure TForm1.btnTransClick(Sender: TObject);
var
srad1,srad2 : Double;
M : double;
begin
Tx := StrToInt(editTx.Text);
Ty := StrToInt(editTy.Text);
Tz := StrToInt(editTz.Text);
M := strtoint(editM.Text);
//proses translasi
For i := 1 To 8 Do
begin
x[i] := x[i] + Tx;
y[i] := y[i] + Ty;
z[i] := z[i] + Tz;
end;
//proyeksikan hasil translasi; mode=0 paralel & mode=1 perspektif
if mode = 0 then
begin
alpha := StrtoInt (txalp.Text);
psi := StrtoInt (txpsi.Text);
srad1 := alpha * PI / 180;
srad2 := psi * PI / 180;
l1 := 1/Tan(srad1);
For i := 1 To 8 Do
begin
xp[i] := round(x[i]+ z[i]*l1*Cos(srad2));
yp[i] := round(y[i]+ z[i]*l1*Sin(srad2));
end;
end else
begin
For i := 1 To 8 Do
begin
xp[i] := round(x[i] / (1 - (z[i]/M)));
yp[i] := round(y[i] / (1 - (z[i]/M)));
end;
end;
//hapus area gambar
btnclClick(Sender);
//gambar ulang hasil proyeksi
Bingkai.Canvas.Pen.Color := clBlue;
Bingkai.Canvas.Pen.Style := psSolid;
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[4]),Round(Bingkai.Height div 2 - yp[4]));
For i := 1 To 4 Do
begin
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
end;
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[8]),Round(Bingkai.Height div 2 - yp[8]));
For i := 5 To 8 Do
begin
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
end;
For i := 1 To 4 Do
begin
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i+4]),Round(Bingkai.Height div 2 - yp[i+4]));
end;
end;
procedure TForm1.btnScalingClick(Sender: TObject);
var
srad1,srad2 : Double;
M : double;
begin
S := StrToFloat(editS.Text);
M := strtoint(editM.Text);
alpha := StrtoInt (txalp.Text);
psi := StrtoInt (txpsi.Text);
srad1 := alpha * PI / 180;
srad2 := psi * PI / 180;
l1 := 1/Tan(srad1);
//proses translasi
For i := 1 To 8 Do
begin
x[i] := round(x[i] * S);
y[i] := round(y[i] * S);
z[i] := round(z[i] * S);
end;
//proyeksikan hasil translasi; mode=0 paralel & mode=1 perspektif
if mode = 0 then
begin
For i := 1 To 8 Do
begin
xp[i] := round(x[i]+ z[i]*l1*Cos(srad2));
yp[i] := round(y[i]+ z[i]*l1*Sin(srad2));
end;
end else
begin
For i := 1 To 8 Do
begin
xp[i] := round(x[i] / (1 - (z[i]/M)));
yp[i] := round(y[i] / (1 - (z[i]/M)));
end;
end;
//hapus area gambar
btnclClick(Sender);
//gambar ulang hasil proyeksi
Bingkai.Canvas.Pen.Color := clBlue;
Bingkai.Canvas.Pen.Style := psSolid;
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[4]),Round(Bingkai.Height div 2 - yp[4]));
For i := 1 To 4 Do
begin
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
end;
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[8]),Round(Bingkai.Height div 2 - yp[8]));
For i := 5 To 8 Do
begin
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
end;
For i := 1 To 4 Do
begin
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i+4]),Round(Bingkai.Height div 2 - yp[i+4]));
end;
end;
procedure TForm1.btnRotasiClick(Sender: TObject);
var
x0, y0, z0 : Double;
M : double;
srad1,srad2 : Double;
begin
sudut := StrToFloat(EditSudut.Text) * pi / 180;
M := strtoint(editM.Text);
alpha := StrtoInt (txalp.Text);
psi := StrtoInt (txpsi.Text);
srad1 := alpha * PI / 180;
srad2 := psi * PI / 180;
l1 := 1/Tan(srad1);
for i:=1 to 8 do
begin
//simpan nilai asli koordinat titik yang akan diproses
x0 := x[i];
y0 := y[i];
z0 := z[i];
Case RadioGroupSumbu.ItemIndex of
//Menghitung Nilai Rotasi pada Sumbu X
0 : begin
y[i] := round(y0 * cos(sudut) - z0 * sin(sudut));
z[i] := round(y0 * sin(sudut) + z0 * cos(sudut));
end;
//Menghitung Nilai Rotasi pada Sumbu Y
1 : begin
x[i] := round(x0 * cos(sudut) - z0 * sin(sudut));
z[i] := round(x0 * sin(sudut) + z0 * cos(sudut));
end;
//Menghitung Nilai Rotasi pada Sumbu Z
2 : begin
x[i] := round(x0 * cos(sudut) - y0 * sin(sudut));
y[i] := round(x0 * sin(sudut) + y0 * cos(sudut));
end;
end;
end;
//proyeksikan hasil rotasi; mode=0 paralel & mode=1 perspektif
if mode = 0 then
begin
For i := 1 To 8 Do
begin
xp[i] := round(x[i]+ z[i]*l1*Cos(srad2));
yp[i] := round(y[i]+ z[i]*l1*Sin(srad2));
end;
end else
begin
For i := 1 To 8 Do
begin
xp[i] := round(x[i] / (1 - (z[i]/M)));
yp[i] := round(y[i] / (1 - (z[i]/M)));
end;
end;
//hapus area gambar
btnclClick(Sender);
//gambar ulang hasil proyeksi
Bingkai.Canvas.Pen.Color := clBlue;
Bingkai.Canvas.Pen.Style := psSolid;
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[4]),Round(Bingkai.Height div 2 - yp[4]));
For i := 1 To 4 Do
begin
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
end;
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[8]),Round(Bingkai.Height div 2 - yp[8]));
For i := 5 To 8 Do
begin
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
end;
For i := 1 To 4 Do
begin
Bingkai.Canvas.MoveTo(Round(Bingkai.Width div 2 + xp[i]),Round(Bingkai.Height div 2 - yp[i]));
Bingkai.Canvas.LineTo(Round(Bingkai.Width div 2 + xp[i+4]),Round(Bingkai.Height div 2 - yp[i+4]));
end;
end;
end.
Sabtu, 14 Mei 2016
Langganan:
Posting Komentar (Atom)
File projectnya apa bisa dishare ya? di denmas94@gmail.com
BalasHapus