This Java Script calculator determines the type of conic section given a general conic equation. Press the Compute button to obtain the solution. The Test button loads a test case to demonstrate how the calculator works. On invalid entries, a popup window will display an error message.
Return to Contents
The Java Script source code for this program can be viewed by using the View|Source command of your web browser.
You may use or modify this source code in any way you find useful, provided that you agree that the author has no warranty, obligations or liability. You must determine the suitability of this source code for your use.
Return to Contents
Types of conic sections
A conic section is the intersection of an extended cone and a plane. Mathematically, conic sections are curves in a Cartesian plane described by second-degree equations in x and y. The type of conic section depends on the angle the cone makes with its axis and how the plane intersects the cone. There are four standard types:
There are several degenerate types:
circles
A circle is the locus of all points such that distance to the origin is constant. It can be written in the standard form:
where r is the radius of the circle. The center of a circle is its focus; it always has an eccentricity of 0.x2/r2 + y2/r2 = 1
ellipses
An ellipse is the locus of all points such that sum of distances to each focus is constant. It has two standard forms:
The length of major radius = a; the length of the minor radius = b; with a > b. The foci are located at ±c units from the center where:x2/a2 + y2/b2 = 1; foci on x-axis (major axis) y2/a2 + x2/b2 = 1; foci on y-axis (major axis)
The eccentricity of an ellipse is e = c/a and takes values between 0 (circle) and 1 (parabola).a2 - b2 = c2
parabolas
A parabola is the locus of all points such that distance to the focus equals the distance to the directrix, which is a straight line perpendicular to the axis of symmetry (on which the focus is located). It also has two standard forms:
In which the distance from vertex to focus (or directrix) = p; it has an eccentricity of 1.4·p·x = y2; focus on x-axis 4·p·y = x2; focus on y-axis
hyperbolas
A hyperbola is the locus of all points such that difference between distances to each focus is constant. Its two standard forms are:
where a > b. Like the ellipse, the foci are located at ±c units from the center, but in this conic:x2/a2 - y2/b2 = 1; foci on x-axis y2/a2 - x2/b2 = 1; foci on y-axis
The eccentricity of a hyperbola is e = c/a and takes values greater than 1 (parabola).a2 + b2 = c2
Determination of conic type
The general form of the equation of a conic section is:
The type of section can be found by evaluating the determinant and two of the minors of the symmetric matrix:A·x2 + B·x·y + C·y2 + D·x + E·y + F = 0
We can compute the determinant of M with:
M =
F D/2 E/2 D/2 A B/2 E/2 B/2 C
and minors M11 and M23 as follows:det(M) = A·C·F + (B·D·E - B2·F - C·D2 - A·E2)/4
Then the type of conic can be determined using the following logical steps:det(M11) = A·C - B2/4 det(M23) = D·E/4 - B·F/2
if det(M) = 0 then
if det(M11) > 0 then
"a point"
elsif det(M11) < 0 then
if A + C = 0 then
"two perpendicular lines"
else
"two intersecting lines"
end if
else
if det(M23) = 0 then
"a single line"
else
"two parallel lines"
end if
end if
else
if det(M11) > 0 then
if A·det(M| > 0 then
"nothing"
else
if (A = C) and (B = 0) then
"a circle"
else
"an ellipse"
end if
end if
elsif det(M11) < 0 then
"a hyperbola"
else
"a parabola"
end if
end if
Transformation to standard form
The general conic equation may represent a standard conic section that has been translated and rotated. To convert the general equation to a standard form, a rotation and a translation are applied to give a new set of coefficients for the equation the conic section that does not change its shape.
rotation
When the coefficient B of the general conic equation is non-zero; a rotational transformation to remove the x·y term will align the axes of the conic with the axes of the Cartesian plane giving a new equation:
From this new equation, a coordinate translation can be found by completing the squares in x and y that will convert the general equation into a standard form. The rotation angle is determined from:A'·x2 + C'·y2 + D'·x + E'·y + F' = 0
The rotation by angle θ around the coordinate origin is applied by replacing x and y using the equations below:θ = π/4 if A = C θ = 0.5·tan-1 B/(A - C) otherwise
and then collecting common terms to obtain new values for the coefficients:x := x·cos(θ) + y·sin(θ) y := -x·sin(θ) + y·cos(θ)
For example, the equationA' = A·cos(θ)·cos(θ) + B·sin(θ)·cos(θ) + C·sin(θ)·sin(θ) C' = A·sin(θ)·sin(θ) - B·sin(θ)·cos(θ) + C·cos(θ)·cos(θ) D' = D·cos(θ) + E·sin(θ) E' = -D·sin(θ) + E·cos(θ) F' = F
represents a hyperbola that has been rotated by 45°. By applying rotation, the standard form is obtained:x·y = 1
0.5000·x² - 0.5000·y² = 1.0000
translation
When the equation for a conic section in this form:
It can be changed by a translation that moves the center from the point {xo, yo} to the origin. The origin depends on the form of the standard conic equation. For a circle, ellipse, or hyperbola; the standard form isA'·x2 + C'·y2 + D'·x + E'·y + F' = 0
In these cases, the center is computed fromA"·x2 ± C"·y2 - 1 = 0
Then the coefficients for the standard conic can be calculated using:xo = -D'/(2·A') yo = -E'/(2·C')
For a parabola, there are two standard forms:A" = A'/(A'·xo2 + C'·yo2 - F') C" = C'/(A'·xo2 + C'·yo2 - F')
If C' is zero, the center and coefficient E" are computed using:x² + E"·y = 0 y² + D"·x = 0
Similarly, if A' is zero, the center and coefficient D" are computed using:xo = D'/(2·A') yo = [F' - D'2/(4·A')]/E' E" = E'/A'
xo = [F' - E'2/(4·C')]/D' yo = E'/(2·C') D" = D'/C'
location of foci and the eccentricity
If the conic section is determined to be a circle the focus is the center at {0, 0} and the eccentricity = 0; there is no need to calculate these.
If the conic is a parabola, then the eccentricity = 1 so this does not need to be calculated. The form of the parabola is determined by the values of A' and C'. The table below indicates how the location of the focus is calculated.
condition form focus
|A'| > 0 and C' = 0 4·p·y = x2 { 0, -E"/4}
|C'| > 0 and A' = 0 4·p·x = y2 {-D"/4, 0}
If the conic is either an ellipse or a hyperbola the orientation of the major axis is determined by the values of A" and C". The table below indicates how the location of the foci and the eccentricity are calculated for the ellipse.
condition form foci
|A"| < |C"| x2/a2 + y2/b2 = 1 {±c, 0}
|C"| < |A"| y2/a2 + x2/b2 = 1 { 0, ±c}
where c2 = a2 - b2 with
so that a2 > b2. The eccentricity = c/a which is always less than 1.a2 = 1 / min( |A"|, |C"| ) b2 = 1 / max( |A"|, |C"| )
The location of foci are similar for the hyperbola:
condition form foci
|A"| < |C"| x2/a2 - y2/b2 = 1 {±c, 0}
|C"| < |A"| y2/a2 - x2/b2 = 1 { 0, ±c}
where c2 = a2 + b2. The eccentricity = c/a which is always greater than 1.
Return to Contents