# include <iostream.h> # include <graphics.h> # include <conio.h> # include <math.h> # define f 0.3 # define projection_angle 45 void show_screen( ); void Ellipsoid(const int,const int,const int,const int,const int,const int); void get_projected_point(double&,double&,double&); void multiply_matrices(const double[4],const double[4][4],double[4]); int main( ) { int driver=VGA; int mode=VGAHI; int x=0; int y=0; int z=0; int rx=0; int ry=0; int rz=0; do { show_screen( ); gotoxy(8,10); cout<<\"Coordinates of Central Point - (x,y,z) :\"; gotoxy(8,11); cout<<\"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\"; gotoxy(12,13); cout<<\"Enter the value of x = \"; cin>>x; gotoxy(12,15); cout<<\"Enter the value of y = \"; cin>>y; gotoxy(12,17); cout<<\"Enter the value of z = \"; cin>>z; gotoxy(8,21); cout<<\"Radius of the Ellipsoid :\"; gotoxy(8,22); cout<<\"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\"; gotoxy(12,24); cout<<\"Enter the value of rx = \"; cin>>rx; gotoxy(12,26); cout<<\"Enter the value of ry = \"; cin>>ry; gotoxy(12,28); cout<<\"Enter the value of rz = \"; cin>>rz; initgraph(&driver,&mode,\"..\\\\Bgi\"); setcolor(15); Ellipsoid(x,y,z,rx,ry,rz); setcolor(15); outtextxy(110,460,\"Press <Enter> to continue or any other key to exit.\"); int key=int(getch( )); if(key!=13) break; } while(1); return 0; } //--------------------------- Ellipsoid( ) ----------------------------// void Ellipsoid(const int _x,const int _y,const int _z, const int rx,const int ry,const int rz) { double x; double y; double z; for(float u=0;u<=1;u+=0.0005) { for(float v=0;v<=1;v+=0.05) { x=((rx*cosl((u*M_PI))*cosl((v*2*M_PI)))+_x); y=((ry*cosl((u*M_PI))*sinl((v*2*M_PI)))+_y); z=((rz*sinl((u*M_PI)))+_z); get_projected_point(x,y,z); putpixel(int(x+0.5),int(y+0.5),15); } } for(float v=0;v<=1;v+=0.0005) { for(float u=0;u<=1;u+=0.05) { x=((rx*cosl((u*M_PI))*cosl((v*2*M_PI)))+_x); y=((ry*cosl((u*M_PI))*sinl((v*2*M_PI)))+_y); z=((rz*sinl((u*M_PI)))+_z); get_projected_point(x,y,z); putpixel(int(x+0.5),int(y+0.5),15); } } } /************************************************************************/ //--------------------- get_projected_point( ) -----------------------// /************************************************************************/ void get_projected_point(double& x,double& y,double& z) { double fcos0=(f*cos(projection_angle*(M_PI/180))); double fsin0=(f*sin(projection_angle*(M_PI/180))); double Par_v[4][4]={ {1,0,0,0}, {0,1,0,0}, {fcos0,fsin0,0,0}, {0,0,0,1} }; double xy[4]={x,y,z,1}; double new_xy[4]={0}; multiply_matrices(xy,Par_v,new_xy); x=new_xy[0]; y=new_xy[1]; z=new_xy[2]; } /************************************************************************/ //---------------------- multiply_matrices( ) ------------------------// /************************************************************************/ void multiply_matrices(const double matrix_1[4], const double matrix_2[4][4],double matrix_3[4]) { for(int count_1=0;count_1<4;count_1++) { for(int count_2=0;count_2<4;count_2++) matrix_3[count_1]+= (matrix_1[count_2]*matrix_2[count_2][count_1]); } } //-------------------------- show_screen( ) ---------------------------// void show_screen( ) { restorecrtmode( ); clrscr( ); textmode(C4350); cprintf(\"\\n********************************************************************************\"); cprintf(\"*-******************************- -*******************************-*\"); cprintf(\"*-------------------------------- \"); textbackground(1); cprintf(\" Ellipsoid \"); textbackground(8); cprintf(\" ---------------------------------*\"); cprintf(\"*-******************************- -*******************************-*\"); cprintf(\"*-****************************************************************************-*\"); for(int count=0;count<42;count++) cprintf(\"*-* *-*\"); gotoxy(1,46); cprintf(\"*-****************************************************************************-*\"); cprintf(\"*------------------------------------------------------------------------------*\"); cprintf(\"********************************************************************************\"); gotoxy(1,2); }