# How to make an ellipse cover the full major axis?

I am calculating the points around the parameter of an ellipse using the C++ for loop below. I am starting with the end points of the Major Axis, Minor Axis, the ellipse center point and the angle of the major axis. When I draw my ellipse it does not reach the end points of the Major Axis. There should be a picture of this below. Is there a way to adjust my formula to draw the ellipse so it covers the full length of the Major Axis or do I need a different formula?

double x1=0, y1=0, x2=0, y2=0, x3=0, y3=0, phi=0;
int ZeroX=0, ZeroY=0;
int NUM_POINTS_PER_CONTOUR = 360;
int p=0;
int Major_Axis_Center_X=0, Full_Major_Axis_X=0;
int Major_Axis_Center_Y=0, Full_Major_Axis_Y=0;
int Full_Minor_Axis_X=0;
double AngleOfMajorAxis=0;
UnicodeString temp;

struct ell {
double a; //e.a is semi-major size
double b; //e.b is semi-minor size
double theta;
double x0; //major axis center X
double y0; //major axis center Y
} e;

//seed Values
x1=50; x2=250;
y1=75; y2=275;

//Vertical Line LEFT edge
Canvas->MoveTo(x1, y1);
Canvas->LineTo(x1, y2);

//Vertical Line RIGHT edge
Canvas->MoveTo(x2, y1);
Canvas->LineTo(x2, y2);

Full_Major_Axis_X = (x2 - x1);
Full_Major_Axis_Y = (y2 - y1);
Major_Axis_Center_X = (x1 + (Full_Major_Axis_X/2));
Major_Axis_Center_Y = (y2 - (Full_Major_Axis_Y/2));
Full_Minor_Axis_X = (Full_Major_Axis_X/2);

//Seed values
e.a = (Full_Major_Axis_X/2); //e.a is semi-major size
e.b = (Full_Minor_Axis_X/2); //e.b is semi-minor size
e.x0 = Major_Axis_Center_X;
e.y0 = Major_Axis_Center_Y;

AngleOfMajorAxis = 140.0;
e.theta = DegToRad(AngleOfMajorAxis);

//Calculate 360 points around edge of ellipse
for (p=0; p<NUM_POINTS_PER_CONTOUR; p++) {
phi = p*2*M_PI/(double)NUM_POINTS_PER_CONTOUR;
x1 = e.a * std::sin(phi);
y1 = e.b * std::cos(phi);
x2 = x1 * std::cos(e.theta) + y1 * std::sin(e.theta);
y2 = y1 * std::cos(e.theta) - x1 * std::sin(e.theta);
x3 = x2 + e.x0;
y3 = y2 + e.y0;
if(p==0){
Canvas->MoveTo(x3, y3);
}
Canvas->LineTo(x3, y3);
}


The Start Points

Ellipse Does Not Touch Ends of Major Axis

EDIT: Below are the changes to make the correct ellipse calculation.

The ellipse Major Axis size must be set using the Semi-Major Axis XY values like this: e.a=Sqrt(Power(SemiMajorAxisXRange,2) + Power(SemiMajorAxisYRange,2) );

The ellipse Minor Axis must be set as: e.b = (e.a/2);

These two changes make the for loop above draw the correct ellipse.

## 1 Answer

You're setting your $\mathtt{e.a}$ variable to half of $\mathtt{Full\_Major\_Axis\_X}$ rathrer than to half of the actual length of your major axis, which is $$\sqrt{\mathtt{Full\_Major\_Axis\_X}^2+\mathtt{Full\_Major\_Axis\_Y}^2}$$

• I had to adjust the Major Axis e.a and the Minor Axis e.b in my formula. I edited the question above to show the working formula. Thanks for the help – homebase Aug 10 '16 at 15:22