3d to 2d

Màu nền
Font chữ
Font size
Chiều cao dòng

Procedure 3D_To_2D(P3D : Point_3D; Var P2D : Point_2D);

Begin

P2D.x := P3D.x - P3D.z * Cos(G);

P2D.y := P3D.y - P3D.z * Sin(G);

End;

VD: ve duong cong x=Sin(t), y=Cos(t), z=Sin(t)*Cos(t)

Program Duong_ba_chieu;

Uses Crt, Graph;

Type

Point_2D = Record

x, y : Real;

End;

Point_3D = Record

x, y, z : Real;

End;

Const

Xmin: Real=0;

Ymin: Real=0;

Zmin: Real=0;

Xmax: Real=639;

Ymax: Real=479;

Zmax: Real=479;

MaxX: Integer=600;

MaxY: Integer=440;

G : Real=PI/4;

Var

m,n : Integer;

ch: char;

CGx,CGy,x,y,z,t,b,Xgoc,Ygoc : Real;

p1,p2 : Point_2D;

p3 : Point_3D;

(*********************)

Procedure C3_2(p : Point_3D; Var q : Point_2D);

Begin

q.x:=p.x-p.z*Cos(G);

q.y:=p.y-p.z*Sin(G);

End;

(*********************)

Procedure WTV(p : Point_2D; Var q : Point_2D);

Begin

q.x:=p.x*CGx;

q.y:=p.y*CGy;

End;

(*********************)

Procedure VTS(p : Point_2D; Var q : Point_2D);

Begin q.x:=Xgoc+p.x;

q.y:=Ygoc-p.y;

End;

(********************)

Procedure He_Truc;

Begin

SetLineStyle(1,0,1);

Line(Round(Xgoc),0,Round(Xgoc),GetMaxY);

Line(0,Round(Ygoc),GetMaxX,Round(Ygoc));

Line(0,Round(Ygoc+Xgoc),639,Round(Ygoc+Xgoc)-639);

SetLineStyle(0,0,1);

End;

(*********************)

Procedure bp(t: Real; Var p : Point_3D);

Begin

p.x:=Sin(t);

p.y:=Cos(t);

p.z:=Sin(t)*Cos(t);

end;

(*********************)

Begin

clrscr;

m:=0;

InitGraph(m,n,'c:\tp\bgi');

DirectVideo:=False;

MaxX:=GetMaxX;

MaxY:=GetMaxY;

b:=2*pi/360;

Xmin:=-1;

Xmax:=1;

Ymin:=-1;

Ymax:=1;

Zmin:=-1/2;

Zmax:=1/2;

Xmin:=Xmin+Zmin*Sin(G);

Xmax:=Xmax+Zmax*Cos(G);

Ymin:=Ymin+Zmin*Sin(G);

Ymax:=Ymax+Zmax*Sin(G);

If Xmin>0 Then Xmin:=0;

If Ymin>0 Then Ymin:=0;

If Xmax<0 Then Xmax:=0;

If Ymax<0 Then Ymax:=0;

CGx:=MaxX/(Xmax-Xmin);

CGy:=MaxY/(Ymax-Ymin);

Xmin:=CGx*Xmin;

Xmax:=CGx*Xmax;

Ymin:=CGy*Ymin;

Ymax:=CGy*Ymax; Xgoc:=0;

If Xgoc>Xmin Then Xgoc:=Round(ABS(Xmin));

Ygoc:=0;

If Ygoc<Ymax Then Ygoc:=Round(ABS(Ymax));

He_Truc;

t:=0;

bp(t,p3);

C3_2(p3,p1);

WTV(p1, p2);

p1:=p2;

VTS(p2, p2);

MoveTo(Round(p2.x),Round(p2.y));

Repeat bp(t,p3);

C3_2(p3,p1);

WTV(p1, p2);

p1:=p2; VTS(p2, p2);

LineTo(Round(p2.x),Round(p2.y));

t:=t+b;

Until t>2*pi+b;

Readln;

CloseGraph;

End.

Bạn đang đọc truyện trên: Truyen2U.Pro

#hoa