home *** CD-ROM | disk | FTP | other *** search
- /*
- This code is far from optimized. It didn't really seem worth the time to
- regroup everything for an application that isn't written to sit resident
- in RAM. It is provided for those who are weary of viruses, trojans, and
- other such filthy vermin.
- */
-
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
-
- #define CONVERT 57.29577951 /* Degrees in a Radian */
-
- main(argc,argv)
- int argc;
- char *argv[];
-
- {
- double a,b,c,A,B,C,s,temp1,temp2,temp3;
- void explain();
- void results();
-
- if(argc != 5 || argv[1][0] == '?')
- explain();
-
- argv[1][0] = toupper(argv[1][0]);
- argv[1][1] = toupper(argv[1][1]);
- argv[1][2] = toupper(argv[1][2]);
-
- if(argv[1][3] != '\0')
- explain();
- if(argv[1][0] != 'S' && argv[1][0] != 'A')
- explain();
- if(argv[1][1] != 'S' && argv[1][1] != 'A')
- explain();
- if(argv[1][2] != 'S' && argv[1][2] != 'A')
- explain();
- if(argv[1][0] == 'A' && argv[1][1] == 'A' && argv[1][2] == 'A')
- explain();
-
- temp1 = atof(argv[2]);
- temp2 = atof(argv[3]);
- temp3 = atof(argv[4]);
-
- /* SSS */
-
- if(argv[1][0] == 'S' && argv[1][1] == 'S' && argv[1][2] == 'S') {
- a = temp1;
- b = temp2;
- c = temp3;
- s = (a + b + c)/2;
- A = atan( sqrt(( (s-b)*(s-c) )/(s*(s-a))) )*CONVERT*2;
- B = atan( sqrt(( (s-a)*(s-c) )/(s*(s-b))) )*CONVERT*2;
- C = atan( sqrt(( (s-b)*(s-a) )/(s*(s-c))) )*CONVERT*2;
- results(A,B,C,a,b,c);
- }
-
- /* SSA */
-
- if(argv[1][0] == 'S' && argv[1][1] == 'S' && argv[1][2] == 'A') {
- a = temp1;
- b = temp2;
- A = temp3;
- B = asin ((b * sin(A/CONVERT))/a)*CONVERT;
- C = (180.00 - A - B);
- c = sqrt( (b*b)+(a*a)-(2*b*a)*(cos(C/CONVERT)) );
- results(A,B,C,a,b,c);
- }
-
- /* SAS */
-
- if(argv[1][0] == 'S' && argv[1][1] == 'A' && argv[1][2] == 'S') {
- a = temp1;
- C = temp2;
- b = temp3;
- c = sqrt( (b*b)+(a*a)-(2*b*a)*(cos(C/CONVERT)) );
- A = asin ((a * sin(C/CONVERT))/c)*CONVERT;
- B = asin ((b * sin(C/CONVERT))/c)*CONVERT;
- results(A,B,C,a,b,c);
- }
-
- /* ASS */
-
- if(argv[1][0] == 'A' && argv[1][1] == 'S' && argv[1][2] == 'S') {
- A = temp1;
- c = temp2;
- a = temp3;
- C = asin ((c * sin(A/CONVERT))/a)*CONVERT;
- B = (180.00 - A - C);
- b = sqrt( (a*a)+(c*c)-(2*a*c)*(cos(B/CONVERT)) );
- results(A,B,C,a,b,c);
- }
-
- /* AAS */
-
- if(argv[1][0] == 'A' && argv[1][1] == 'A' && argv[1][2] == 'S') {
- A = temp1;
- B = temp2;
- a = temp3;
- C = (180.00 - A - B);
- c = (a*sin(C/CONVERT))/sin(A/CONVERT);
- b = sqrt( (a*a)+(c*c)-(2*a*c)*(cos(B/CONVERT)) );
- results(A,B,C,a,b,c);
- }
-
- /* ASA */
-
- if(argv[1][0] == 'A' && argv[1][1] == 'S' && argv[1][2] == 'A') {
- A = temp1;
- c = temp2;
- B = temp3;
- C = (180.00 - A - B);
- a = (c*sin(A/CONVERT))/sin(C/CONVERT);
- b = (c*sin(B/CONVERT))/sin(C/CONVERT);
- results(A,B,C,a,b,c);
- }
-
- /* SAA */
-
- if(argv[1][0] == 'S' && argv[1][1] == 'A' && argv[1][2] == 'A') {
- a = temp1;
- C = temp2;
- A = temp3;
- B = (180.00 - A - C);
- c = (a*sin(C/CONVERT))/sin(A/CONVERT);
- b = (a*sin(B/CONVERT))/sin(A/CONVERT);
- results(A,B,C,a,b,c);
- }
- }
- void explain()
- {
- printf("H\n\nmTrigMaster1.0m © 1990 by Don Lester\n");
- printf("Calculates three unknown triangle values from three user\n");
- printf("supplied values and a format qualifier.\n\n");
- printf("Usage: mTrigMasterm [qualifiers] [value] [value] [value]\n\n");
- printf("Qualifiers: A - Angle S - Side\n");
- printf("You will need three qualifiers.\n");
- printf("\nThe values are the angles and sides that correspond to the\n");
- printf("qualifers already given (AAA is an impossible calculation).\n\n");
- printf("Example command string: mTrigMasterm ASA 45 10 30 <RETURN>\n\n");
- exit(10);
- }
-
- void results(A,B,C,a,b,c)
- double A,B,C,a,b,c;
- {
- if(A<=0 || B<=0 || C<=0 || a<=0 || b<=0 || c<=0) explain();
- printf("m\n\nSide a = %1.2f units\n",a);
- printf("Angle A = %1.2f degrees\n\n",A);
- printf("Side b = %1.2f units\n",b);
- printf("Angle B = %1.2f degrees\n\n",B);
- printf("Side c = %1.2f units\n",c);
- printf("Angle C = %1.2f degrees\n\n\nm",C);
- exit(10);
- }
-