Graphics program in C++ to create a ellipsoid using parametric equation

This program needs the library file 3dframe.cpp,so download it first and put it in the BIN directory of Turbo C++ installation path .


Read about : Functionalities provided by this 3dframe.cpp library file and download it


Use the Contact form to post any question or comment regarding these programs.

The following code is tested on Turbo C++ Version 3.0


Click here to see the output of the program


	  
/*
*********************************************************
Author:Satyabrata Jena
Program Created on Date:March-2007
*********************************************************

PROGRAM IN C++  TO CREATE AN ELLIPSOID 
USING PARAMETRIC EQUATIONS

*/

#include"3dframe.CPP"
void draw_ellipsoid()
{
     int arr[4];
     int xrad=2000;
     int yrad=500;
     int zrad=1000;
     for(double i=0;i<=90;i=i+1)
     {
     double phi=((3.14159)/180)*i;
     for(double j=0 ;j<90;j=j+0.005)
     {
           double theta,x,y,z;
           theta=((3.14159)/180)*j;
           x=xrad*cos(phi)*cos(theta);
           y=yrad*sin(theta)*cos(phi);
           z=zrad*sin(phi);
           putxyz(int(x),-int(y),(int)z,arr,BLUE);
           putxyz(int(x),-int(y),-(int)z,arr, BLUE);
           putxyz(-int(x),-int(y),(int)z,arr,MAGENTA);
           putxyz(-int(x),-int(y),-(int)z,arr,MAGENTA);
     }
     }
     for(  i=0;i<=90;i=i+1) //0.5
     {
           double phi=((3.14159)/180)*i;
     for(double j=0;j<90;j=j+0.005)//0.01
     {
           double theta,x,y,z;
           theta=((3.14159)/180)*j;
           x=xrad*cos(phi)*cos(theta);
           y=yrad*sin(theta)*cos(phi);
           z=zrad*sin(phi);
           putxyz(int(x),int(y),(int)z,arr,GREEN);
           putxyz(int(x),int(y),-(int)z,arr,GREEN);
           putxyz(-int(x),int(y),-(int)z,arr,RED);
           putxyz(-int(x),int(y),(int)z,arr,RED);
     }
     }
}

void main()
{
      int gd=DETECT,gm;
      initgraph(&gd,&gm,"c:\\tc\\bgi");
      DRAW3DFRAME();
      cleardevice();
      draw_ellipsoid();
      getch();
      closegraph();
}

  
	  

Download source code of ellipsoid program in C++