#include #include int main(void) { double x1, x2, x3, y1, y2, y3, m12, xc, yc, r
ID: 3529268 • Letter: #
Question
#include #include int main(void) { double x1, x2, x3, y1, y2, y3, m12, xc, yc, r; double circle_x_coord(double x1,double y1,double x2,double y2,double x3,double y3); printf("Enter x and y coordinates for first point: "); scanf("%lf %lf",&x1,&y1); printf("Enter x and y coordinates for second point: "); scanf("%lf %lf",&x2,&y2); printf("Enter x and y coordinates for third point: "); scanf("%lf %lf",&x3,&y3); xc = circle_x_coord(x1,y1,x2,y2,x3,y3); m12 = (y2 - y1)/(x2 - x1); yc = -(1/m12) * (xc - (x1 + x2) /2) + ((y1 + y2)/2); r = sqrt((x1 - xc)*(x1 - xc) + (y1 - yc)*(y1 - yc)); printf(" Center of Circle: (%.1f,%.1f) ",xc,yc); printf("Radius of Circle: %.1f ",r); return 0; } double circle_x_coord(double x1,double y1,double x2,double y2,double x3,double y3) { double m12, m23, xc_num, xc_den, xc; m12 = (y2 - y1)/(x2 - x1); m23 = (y3 - y2)/(x3 - x2); xc_num = m12*m23*(y1 - y3) + m23*(x1 + x2) - m12*(x2 + x3); xc_den = 2*(m23 - m12); xc = xc_num/xc_den; return xc; } 1. Modify the program so that it also prints the equation of the circle. 2. If either line is vertical, then the corresponding slope is infinite. Determine if this occurs, and print an error message before exiting the program. 3. If line P1P2 is vertical, exchange the values of P1 with P3. Then check to see if this now yields two non-vertical lines. If so, continue processing. 4. If line P2P3 is vertical, exchange the values of P2 with P1. Then check to see if this now yields two non-vertical lines. If so, continue processing.Explanation / Answer
#include #include int main(void)
{ double x1, x2, x3, y1, y2, y3, m12, xc, yc, r;
double circle_x_coord(double x1,double y1,double x2,double y2,double x3,double y3);
printf("Enter x and y coordinates for first point: ");
scanf("%lf %lf",&x1,&y1);
printf("Enter x and y coordinates for second point: ");
scanf("%lf %lf",&x2,&y2);
printf("Enter x and y coordinates for third point: ");
scanf("%lf %lf",&x3,&y3);
xc = circle_x_coord(x1,y1,x2,y2,x3,y3);
if(x2!=x1){ ///Line is vertical if x2!=x1. Condition is to check if line is vertical or not.
m12 = (y2 - y1)/(x2 - x1);}
else{
printf(" Line is vertical. Slope is infinity ");
yc = -(1/m12) * (xc - (x1 + x2) /2) + ((y1 + y2)/2);
r = sqrt((x1 - xc)*(x1 - xc) + (y1 - yc)*(y1 - yc));
printf(" Center of Circle: (%.1f,%.1f) ",xc,yc);
printf(" Equation of circle is: (x - )^2 + (y - )^2 = 0 ",xc,yc); ////Equation of circle
printf("Radius of Circle: %.1f ",r); return 0; }
double circle_x_coord(double x1,double y1,double x2,double y2,double x3,double y3)
{
double m12, m23, xc_num, xc_den, xc;
if(x2!=x1){ ///if P1 P2 is vertical
m12 = (y2 - y1)/(x2 - x1);}
else if(x2!=x3){ //Exchange value of P1 with P3
x1=x3;
y1=y3;
m12 = (y2 - y1)/(x2 - x1);}
if(x2!=x3){ //if P2P3 is vertical
m23 = (y3 - y2)/(x3 - x2);}
else{ //Exchange P2 with P1
x2=x1;
y2=y1;
m23 = (y3 - y2)/(x3 - x2);}
xc_num = m12*m23*(y1 - y3) + m23*(x1 + x2) - m12*(x2 + x3);
xc_den = 2*(m23 - m12);
xc = xc_num/xc_den;
return xc;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.