全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1831
推到 Plurk!
推到 Facebook!

3D-圓的轉動

 
daniel__lee
高階會員


發表:18
回覆:124
積分:113
註冊:2002-11-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-02 11:20:13 IP:61.218.xxx.xxx 未訂閱
這是我以前參考計算機圖學做的 (完整版) 附執行檔    //--------------------------------------------------------------------------- #include  #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #include <math.h> #define PI 3.141593 #define D 1 #define VD 300 float Theta=0,Phi=0,SN1,SN2,CN1,CN2, X,Y,Z,XE,YE,ZE,XS,YS,ZS,phi,theta; int mouse_x,mouse_y; bool flag=0; void DefineViewingParameters(); void Define3DFunction(); void ViewingCoordinates(); void ScreenCoordinates(); void Plot(); TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormActivate(TObject *Sender) { Timer1->Enabled=false; Timer1->Interval=200; Form1->Caption="ELLIPSOD + ROTATE BY DANIEL LEE"; Form1->Canvas->FillRect(Rect(0,0,ClientWidth,ClientHeight)); Form1->Canvas->TextOutA(5,5,"用滑鼠選擇繪圖位置"); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { Form1->Canvas->TextOutA(5,5,"用滑鼠選擇繪圖位置 X="+IntToStr(X)+" Y="+IntToStr(Y)); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { AnsiString InputString; mouse_x=X; mouse_y=Y; Form1->Canvas->FillRect(Rect(0,0,ClientWidth,ClientHeight)); Form1->Canvas->TextOutA(5,5,"用滑鼠選擇繪圖位置 X="+IntToStr(X)+" Y="+IntToStr(Y)); if(Timer1->Enabled==false) { theta=0; phi=0; } Timer1->Enabled^=1; } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { Phi=phi; Theta=theta; DefineViewingParameters(); Form1->Canvas->FillRect(Rect(0,0,ClientWidth,ClientHeight)); Form1->Canvas->TextOutA(5,5,"用滑鼠選擇繪圖位置 X="+IntToStr(mouse_x)+" Y="+IntToStr(mouse_y)); Define3DFunction(); phi+=5; if(phi>180) phi=0; } //--------------------------------------------------------------------------- void DefineViewingParameters() { Theta=Theta*PI/180; Phi=Phi*PI/180; SN1=sin(Theta);SN2=sin(Phi);CN1=cos(Theta);CN2=cos(Phi); } //--------------------------------------------------------------------------- void Define3DFunction() { float theta2,thetat,phi2,phit,r =0.5; for(phi2=0;phi2<=180;phi2+=10) { flag=0; phit = (float) phi2 *PI /180; for(theta2=0;theta2<=360; theta2+=2) { thetat = (float) theta2 * PI/180; X = r * sin(phit)*cos(thetat); Y = r * sin(phit)*sin(thetat); Z = r * cos(phit); ViewingCoordinates(); ScreenCoordinates(); Plot(); } } for(theta2=0;theta2<=360;theta2+=10) { flag=0; thetat = (float) theta2 *PI /180; for(phi2=0;phi2<=180; phi2+=2) { phit = (float) phi2 * PI/180; X = r * sin(phit)*cos(thetat); Y = r * sin(phit)*sin(thetat); Z = r * cos(phit); ViewingCoordinates(); ScreenCoordinates(); Plot(); } } } //--------------------------------------------------------------------------- void ViewingCoordinates() { XE=-X * SN1 + Y * CN1; YE=-X*CN1*CN2-Y*SN1*CN2+Z*SN2; ZE=-X*SN2*CN1-Y*SN2*SN1-Z*CN2+D; } //--------------------------------------------------------------------------- void ScreenCoordinates() { XS=(VD)*XE/ZE; YS=(VD)*YE/ZE; XS=XS+mouse_x; YS=-YS+mouse_y; } //--------------------------------------------------------------------------- void Plot() { if((XS < 0)||(XS >Form1->Width)||(YS<0)||(YS>Form1->Height)) { flag=0; return; } if(flag==0) { Form1->Canvas->MoveTo(XS,YS); Form1->Canvas->Pixels[XS][YS]=clRed; flag=1; Form1->Canvas->Pen->Color=clBlue; return; } Form1->Canvas->LineTo(XS,YS); } //------------------------------------------------------------------------END ~ 勿在浮沙上面築高塔 ~
------
~ 勿在浮沙上面築高塔 ~
系統時間:2024-06-02 20:41:47
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!