Archived

This topic is now archived and is closed to further replies.

Rizo

ellipse problem

Recommended Posts

I have an ellipse center 0,0 majour axis radious 5 minor axis radious 2 i.e 2 | | | |----------------------5 does any one know how to generate the points for this ellipse for every degree i.e for(i=0; i<360; ++i) thanks

Share this post


Link to post
Share on other sites
sin() returns the y values for a unit circle and cos() returns the x values on an unit circle, thus, given the half_width (5 in your case) and the half_height (2 in your case) this would get you what you want:


double half_width = 5;
double half_height = 2;

for ( int i = 0; i < 360; i++ )
{
double a = degrees_to_radians(i); /* C/C++ sin/cos needs andgle in radians not degrees */
printf( "x = %lf y = %lf", half_width*cos(a), half_height*cos(a) );
}

....

double degrees_to_radians( double degrees )
{
/* with some comilers this could be:
static conversion = M_PI / 180.0; */

static double conversion = 3.1415926535 / 180.0;

return conversion * degrees;
}


Unchecked code: may have errors

Edit: added degrees_to_radians()


[edited by - mauman on October 15, 2003 9:47:57 AM]

Share this post


Link to post
Share on other sites