/* Program: Cord.c Revision: 12-JAN-1996 Picture a circle of radius R that is cut by a cord of length L. This cord subtends an angle A of the circle. R = circle radius L = cord length A = angle of the circle's circumference that the cord subtends C = length along the circle's circumgerence that the cord subtends D = distance along the perpendicular radius from the circle center to cord d = distance along the perpendicular radius from the cord to the circle's circumference. This is called the sagitta. You Supply Program Returns You Supply Program Returns ---------- --------------- ---------- --------------- R L * A C D d A C R L D d R A * L C D d A D R L C d R C * L A D d A d * R L C D R D * A C L d R d * L A C D C D R L A d C d R L A D L A * R C D d L C R A D d D d R L A C L D R A C d L d R A C D Enter the majic value of "0" for 4 of the 6 parameters. This program will then calculate the value of all parameters and display them. This program defines a munber of functions. The are: angle_r_l You give it the radius and cord_length and it returns the angle subtended by the cord. length_r_a You give it the radius and cord_angle and it returns the length of the cord. dist_cnt_crd_A_d You git it the angle subtended by the cord and the distance along the perpendicular radius from the cord to the circle's circumference and it returns the distance from the circle's center to the cord. */ #include #include #define PI 3.1415926 main () { float radius, cord_length, cord_angle ; float circmf_subtnd, dist_cnt_crd, dist_crd_cmf ; float two_pi ; float angle_r_l( float radius, float cord_length ) ; float length_r_a( float radius, float cord_angle ) ; float dist_cnt_crd_A_d( float cord_angle, float dist_crd_cmf ) ; two_pi = 2.0 * PI ; /* First obtain the parameters */ printf(" \n "); printf("Enter the following: circle's radius, cord length, angle \n"); printf(" subtended by the cord, length along the circle's \n"); printf(" circumference subtended by the cord, length along the \n"); printf(" perpendicular radius from the circle's center to the \n"); printf(" cord, length along the perpendicular radius from the \n"); printf(" cord to the circle's circumference. \n"); printf(" Enter values for two of these 6 parameters and zeros \n"); printf(" for the other 4 parameters. \n"); printf(" \n "); printf(" Enter the circle's radius: "); scanf( "%f", &radius ) ; printf(" \n ") ; printf(" Enter the cord's length: "); scanf( "%f", &cord_length ) ; printf(" \n ") ; printf(" Enter the angle subtended by the cord (deg): "); scanf( "%f", &cord_angle ) ; printf(" \n ") ; printf(" Enter length along circle's circumference subtended by the cord: "); scanf( "%f", &circmf_subtnd ) ; printf(" \n ") ; printf(" Enter distance along perpenduclar radius from center to cord: "); scanf( "%f", &dist_cnt_crd ) ; printf(" \n ") ; printf(" Enter distance along perp radius from cord to circumferece: "); scanf( "%f", &dist_crd_cmf ) ; printf(" \n ") ; /* Now calculate all 6 parameters */ /* Test to see if radius and cord_length are not equal to zero */ if ( radius != 0 && cord_length != 0 ) { cord_angle = angle_r_l( radius, cord_length ) ; circmf_subtnd = (cord_angle / 360.0) * two_pi * radius ; dist_cnt_crd = radius * cos ( ( (cord_angle / 2.0) / 360.0) * two_pi ) ; dist_crd_cmf = radius - dist_cnt_crd ; } /* Test to see if radius and cord_angle are not equal to zero */ else if ( radius != 0 && cord_angle != 0 ) { cord_length = length_r_a( radius, cord_angle ) ; circmf_subtnd = (cord_angle / 360.0) * two_pi * radius ; dist_cnt_crd = radius * cos ( ( (cord_angle / 2.0) / 360.0) * two_pi ) ; dist_crd_cmf = radius - dist_cnt_crd ; } /* Test to see if the radius and the circumference subtended are not equal to zero */ else if ( radius != 0 && circmf_subtnd != 0 ) { cord_angle = 360.0 * ( circmf_subtnd / (two_pi * radius) ) ; cord_length = length_r_a( radius, cord_angle ) ; dist_cnt_crd = radius * cos ( ( (cord_angle / 2.0) / 360.0) * two_pi ) ; dist_crd_cmf = radius - dist_cnt_crd ; } /* Test to see if the radius and the distance circle center to cord are not equal to zero */ else if ( radius != 0 && dist_cnt_crd != 0 ) { cord_angle = 2.0 * (360.0/two_pi) * acos( dist_cnt_crd / radius ) ; cord_length = length_r_a( radius, cord_angle ) ; circmf_subtnd = (cord_angle / 360.0) * two_pi * radius ; dist_crd_cmf = radius - dist_cnt_crd ; } /* Test to see if the radius and the distance cord to circumference are not equal to zero */ else if ( radius != 0 && dist_crd_cmf != 0 ) { dist_cnt_crd = radius - dist_crd_cmf ; cord_angle = 2.0 * (360.0/two_pi) * acos( dist_cnt_crd / radius ) ; cord_length = length_r_a( radius, cord_angle ) ; circmf_subtnd = (cord_angle / 360.0) * two_pi * radius ; } /* Test to see if the cord length and the angle subtended by the cord are not equal to zero */ else if ( cord_length != 0 && cord_angle != 0 ) { radius = cord_length / (2 * sin( (cord_angle / 2) * (two_pi / 360.0) )) ; dist_cnt_crd = radius * cos( (cord_angle / 2) * (two_pi / 360.0) ) ; dist_crd_cmf = radius - dist_cnt_crd ; circmf_subtnd = (cord_angle / 360.0) * two_pi * radius ; } /* Test to see if cord_angle and cord to circumference distance are not equal to zero */ else if ( cord_angle != 0 && dist_crd_cmf != 0 ) { dist_cnt_crd = dist_cnt_crd_A_d( cord_angle, dist_crd_cmf ) ; radius = dist_cnt_crd + dist_crd_cmf ; circmf_subtnd = (cord_angle / 360.0) * two_pi * radius ; cord_length = 2.0 * ( radius * sin( (cord_angle / 360.0) * PI ) ) ; } /* Now finally just print the values for all 6 parameters */ printf( "\n The circle's radius is = %7.3f units \n", radius ) ; printf( "\n The cord's length is = %7.3f units \n", cord_length ) ; printf( "\n The angle subtended by the cord is = %7.3f degrees \n", cord_angle ) ; printf( "\n Length along Circumference subtended by cord = %7.3f units \n", circmf_subtnd ) ; printf( "\n Distance from circle's center to the cord is = %7.3f units \n", dist_cnt_crd ) ; printf( "\n Distance from cord to circle's circumference = %7.3f units \n", dist_crd_cmf ) ; printf( "\n " ) ; } /* define the angle_r_l function */ float angle_r_l( float radius, float cord_length ) { float cord_angle = 0 ; float temp_1 = 0 ; temp_1 = asin ( (cord_length / 2.0) / radius ) ; cord_angle = 360.0 * ( (2.0 * temp_1) / (2.0 * PI) ) ; return (cord_angle ) ; } /* define the length_r_a function */ float length_r_a( float radius, float cord_angle ) { float cord_length = 0 ; float temp_1 = 0 ; temp_1 = (cord_angle / 360.0) * PI ; cord_length = 2.0 * radius * sin( temp_1 ) ; return (cord_length ) ; } /* define the dist_cnt_crd_A_d function */ float dist_cnt_crd_A_d( float cord_angle, float dist_crd_cmf ) { float dist_cnt_crd = 0 ; float temp_1 = 0 ; temp_1 = ( (cord_angle / 360.0) * PI ) ; dist_cnt_crd = dist_crd_cmf * ( cos(temp_1) / (1 - cos(temp_1) ) ) ; return (dist_cnt_crd) ; }