/******************************************************* conic-sections.ch Conic Sections Use this program to illustrate how the coefficients of functions representing conic sections can be used to determine the type of conic section (circle, ellipse, hyperbola), and then display results based on that conic section. Have students analyze, fill in parts of, or use the program to check results to exercises they are already working on. ************************************************************ Copyright 2014 SoftIntegration Inc. http://www.softintegration.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 *******************************************************/ printf("The conic section is ax^2+by^2=c, where c is positive.\n"); // initialize variables used for this program double a, b, c; double radius; double vertical, horizontal; double boxwidth, boxheight; // get the values of the coefficients printf("What is a? "); scanf("%lf", &a); printf("What is b? "); scanf("%lf", &b); printf("What is c? "); scanf("%lf", &c); // figure out what conic section we have and print some facts about it // Circle if (a>0 && b>0 && a==b) { printf("\nIt is a circle.\n"); radius = sqrt(c/a); printf("The radius is %.2lf.\n", radius); } // Ellipse else if (a>0 && b>0 && a!=b) { printf("\nIt is an ellipse.\n"); vertical = 2*sqrt(c/b); horizontal = 2*sqrt(c/a); printf("The vertical axis is %.2lf units.\n", vertical); printf("The horizontal axis is %.2lf units.\n", horizontal); } // Hyperbola else if (a*b < 0) { printf("\nIt is a hyperbola.\n"); if (a < 0) printf("The hyperbola intersects the y-axis.\n"); else printf("The hyperbola intersects the x-axis.\n"); boxwidth = 2*sqrt(abs(c/a)); boxheight = 2*sqrt(abs(c/b)); printf("The bounding box is %.2lf units wide and %.2lf units tall\n", boxwidth, boxheight); } // none of the above else printf("\nIt is not a circle or an ellipse or a hyperbola.\n");