目次 | |
0、はじめに 1、C言語(C99)での実装 2、テスト結果 3、ライセンス及び免責事項 4、終わりに |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
typedef struct POINT { float x, y; } POINT;
const char *GetTheStringOfIndicatesTheAngleAttribute( POINT A, POINT B, POINT C ){
static const char *S[] = {"an acute angle","a right angle","an obtuse angle"};
int attribute = (A.x-B.x)*(C.x-B.x) + (A.y-B.y)*(C.y-B.y);
return 0<attribute ? S[0] : ( attribute<0 ? S[2] : S[1] );
}
double GetTheAngleAsDegree( POINT A, POINT B, POINT C ){
double d = (A.x-B.x)*(C.x-B.x) + (A.y-B.y)*(C.y-B.y);
double m = sqrt( (A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y) )
* sqrt( (C.x-B.x)*(C.x-B.x) + (C.y-B.y)*(C.y-B.y) );
return (180./3.14159265358979323846)*acos(d/m); //cos: transcendental functions
}
int main(){ srand((unsigned int)time(NULL));
for(int e=0; e<64; e++ ) { // 0
<= x < 1000, 0 <= y < 1000
POINT A = (POINT){ rand() % 1000, rand() % 1000 };
POINT B = (POINT){ rand() % 1000, rand() % 1000 };
POINT C = (POINT){ rand() % 1000, rand() % 1000 };
if( (A.x-C.x)*(B.y-C.y) == (B.x-C.x)*(A.y-C.y) ) continue;
printf( "A:(% 5.0f,% 5.0f), ", A.x, A.y );
printf( "B:(% 5.0f,% 5.0f), ", B.x, B.y );
printf( "C:(% 5.0f,% 5.0f)\n", C.x, C.y );
double AngleABC = GetTheAngleAsDegree( A, B, C );
double AngleBCA = GetTheAngleAsDegree( B, C, A );
double AngleCAB = GetTheAngleAsDegree( C, A, B );
const char *abc = GetTheStringOfIndicatesTheAngleAttribute( A, B, C );
const char *bca = GetTheStringOfIndicatesTheAngleAttribute( B, C, A );
const char *cab = GetTheStringOfIndicatesTheAngleAttribute( C, A, B );
printf("\t Angle ABC, %6.2f deg., is %s.\n", AngleABC, abc );
printf("\t Angle BCA, %6.2f deg., is %s.\n", AngleBCA, bca );
printf("\t Angle CAB, %6.2f deg., is %s.\n", AngleCAB, cab );
printf( "\n");
}
return 0;
}
A:( 27, 565), B:( 7, 807), C:( 75, 349) Angle ABC, 3.72 deg., is an acute angle. Angle BCA, 4.08 deg., is an acute angle. Angle CAB, 172.20 deg., is an obtuse angle. A:( 889, 21), B:( 709, 122), C:( 795, 624) Angle ABC, 109.58 deg., is an obtuse angle. Angle BCA, 18.58 deg., is an acute angle. Angle CAB, 51.84 deg., is an acute angle. A:( 66, 317), B:( 902, 839), C:( 299, 82) Angle ABC, 19.48 deg., is an acute angle. Angle BCA, 83.29 deg., is an acute angle. Angle CAB, 77.23 deg., is an acute angle. A:( 948, 48), B:( 846, 21), C:( 960, 252) Angle ABC, 48.91 deg., is an acute angle. Angle BCA, 22.90 deg., is an acute angle. Angle CAB, 108.19 deg., is an obtuse angle. A:( 938, 783), B:( 216, 40), C:( 742, 25) Angle ABC, 47.45 deg., is an acute angle. Angle BCA, 102.86 deg., is an obtuse angle. Angle CAB, 29.68 deg., is an acute angle. A:( 194, 934), B:( 703, 16), C:( 413, 163) Angle ABC, 34.11 deg., is an acute angle. Angle BCA, 132.74 deg., is an obtuse angle. Angle CAB, 13.15 deg., is an acute angle. A:( 817, 626), B:( 705, 50), C:( 753, 728) Angle ABC, 6.95 deg., is an acute angle. Angle BCA, 36.16 deg., is an acute angle. Angle CAB, 136.89 deg., is an obtuse angle. A:( 658, 1), B:( 184, 924), C:( 905, 411) Angle ABC, 27.39 deg., is an acute angle. Angle BCA, 94.37 deg., is an obtuse angle. Angle CAB, 58.25 deg., is an acute angle. A:( 338, 836), B:( 35, 118), C:( 559, 368) Angle ABC, 41.61 deg., is an acute angle. Angle BCA, 90.23 deg., is an obtuse angle. Angle CAB, 48.16 deg., is an acute angle. A:( 166, 861), B:( 682, 593), C:( 642, 896) Angle ABC, 55.03 deg., is an acute angle. Angle BCA, 93.31 deg., is an obtuse angle. Angle CAB, 31.65 deg., is an acute angle. A:( 617, 482), B:( 52, 18), C:( 876, 660) Angle ABC, 1.47 deg., is an acute angle. Angle BCA, 3.42 deg., is an acute angle. Angle CAB, 175.10 deg., is an obtuse angle. A:( 129, 228), B:( 49, 372), C:( 624, 785) Angle ABC, 96.63 deg., is an obtuse angle. Angle BCA, 12.68 deg., is an acute angle. Angle CAB, 70.68 deg., is an acute angle. A:( 646, 591), B:( 104, 242), C:( 721, 410) Angle ABC, 17.55 deg., is an acute angle. Angle BCA, 82.72 deg., is an acute angle. Angle CAB, 79.73 deg., is an acute angle. A:( 861, 722), B:( 53, 803), C:( 781, 180) Angle ABC, 34.83 deg., is an acute angle. Angle BCA, 57.84 deg., is an acute angle. Angle CAB, 87.33 deg., is an acute angle. A:( 926, 628), B:( 696, 148), C:( 679, 385) Angle ABC, 29.70 deg., is an acute angle. Angle BCA, 130.43 deg., is an obtuse angle. Angle CAB, 19.87 deg., is an acute angle. A:( 191, 627), B:( 658, 903), C:( 556, 95) Angle ABC, 52.22 deg., is an acute angle. Angle BCA, 41.65 deg., is an acute angle. Angle CAB, 86.13 deg., is an acute angle. A:( 376, 424), B:( 27, 970), C:( 129, 4) Angle ABC, 26.56 deg., is an acute angle. Angle BCA, 36.49 deg., is an acute angle. Angle CAB, 116.95 deg., is an obtuse angle. A:( 127, 514), B:( 326, 938), C:( 119, 425) Angle ABC, 3.17 deg., is an acute angle. Angle BCA, 16.84 deg., is an acute angle. Angle CAB, 159.99 deg., is an obtuse angle. A:( 933, 431), B:( 154, 118), C:( 372, 766) Angle ABC, 49.52 deg., is an acute angle. Angle BCA, 77.75 deg., is an acute angle. Angle CAB, 52.73 deg., is an acute angle. A:( 866, 620), B:( 522, 962), C:( 493, 705) Angle ABC, 51.61 deg., is an acute angle. Angle BCA, 96.40 deg., is an obtuse angle. Angle CAB, 32.00 deg., is an acute angle. A:( 507, 856), B:( 737, 809), C:( 258, 376) Angle ABC, 53.66 deg., is an acute angle. Angle BCA, 20.47 deg., is an acute angle. Angle CAB, 105.87 deg., is an obtuse angle. A:( 169, 268), B:( 692, 644), C:( 363, 422) Angle ABC, 1.70 deg., is an acute angle. Angle BCA, 175.57 deg., is an obtuse angle. Angle CAB, 2.73 deg., is an acute angle. A:( 386, 962), B:( 389, 205), C:( 543, 935) Angle ABC, 12.14 deg., is an acute angle. Angle BCA, 87.85 deg., is an acute angle. Angle CAB, 80.01 deg., is an acute angle. A:( 695, 928), B:( 579, 741), C:( 561, 158) Angle ABC, 149.96 deg., is an obtuse angle. Angle BCA, 8.10 deg., is an acute angle. Angle CAB, 21.94 deg., is an acute angle. A:( 271, 614), B:( 48, 117), C:( 426, 785) Angle ABC, 5.34 deg., is an acute angle. Angle BCA, 12.69 deg., is an acute angle. Angle CAB, 161.98 deg., is an obtuse angle. A:( 430, 644), B:( 92, 109), C:( 696, 387) Angle ABC, 33.00 deg., is an acute angle. Angle BCA, 68.73 deg., is an acute angle. Angle CAB, 78.27 deg., is an acute angle. A:( 9, 708), B:( 748, 321), C:( 128, 762) Angle ABC, 7.78 deg., is an acute angle. Angle BCA, 120.17 deg., is an obtuse angle. Angle CAB, 52.05 deg., is an acute angle. A:( 402, 446), B:( 420, 173), C:( 978, 42) Angle ABC, 106.98 deg., is an obtuse angle. Angle BCA, 21.83 deg., is an acute angle. Angle CAB, 51.18 deg., is an acute angle. A:( 170, 623), B:( 902, 494), C:( 620, 41) Angle ABC, 68.09 deg., is an acute angle. Angle BCA, 69.61 deg., is an acute angle. Angle CAB, 42.29 deg., is an acute angle. A:( 322, 850), B:( 918, 875), C:( 97, 486) Angle ABC, 22.95 deg., is an acute angle. Angle BCA, 32.93 deg., is an acute angle. Angle CAB, 124.12 deg., is an obtuse angle. A:( 223, 74), B:( 305, 989), C:( 787, 353) Angle ABC, 42.28 deg., is an acute angle. Angle BCA, 79.16 deg., is an acute angle. Angle CAB, 58.56 deg., is an acute angle. A:( 27, 671), B:( 542, 803), C:( 148, 486) Angle ABC, 24.44 deg., is an acute angle. Angle BCA, 84.37 deg., is an acute angle. Angle CAB, 71.19 deg., is an acute angle. A:( 107, 159), B:( 719, 739), C:( 262, 125) Angle ABC, 9.88 deg., is an acute angle. Angle BCA, 114.29 deg., is an obtuse angle. Angle CAB, 55.83 deg., is an acute angle. A:( 158, 658), B:( 735, 681), C:( 126, 699) Angle ABC, 3.98 deg., is an acute angle. Angle BCA, 50.34 deg., is an acute angle. Angle CAB, 125.69 deg., is an obtuse angle. A:( 288, 366), B:( 299, 954), C:( 528, 252) Angle ABC, 19.14 deg., is an acute angle. Angle BCA, 46.53 deg., is an acute angle. Angle CAB, 114.34 deg., is an obtuse angle. A:( 396, 73), B:( 465, 828), C:( 849, 749) Angle ABC, 83.60 deg., is an acute angle. Angle BCA, 67.80 deg., is an acute angle. Angle CAB, 28.60 deg., is an acute angle. A:( 991, 739), B:( 2, 734), C:( 923, 54) Angle ABC, 36.73 deg., is an acute angle. Angle BCA, 59.23 deg., is an acute angle. Angle CAB, 84.04 deg., is an acute angle. A:( 81, 747), B:( 710, 630), C:( 434, 365) Angle ABC, 54.37 deg., is an acute angle. Angle BCA, 88.91 deg., is an acute angle. Angle CAB, 36.72 deg., is an acute angle. A:( 522, 564), B:( 122, 435), C:( 581, 430) Angle ABC, 18.50 deg., is an acute angle. Angle BCA, 65.61 deg., is an acute angle. Angle CAB, 95.89 deg., is an obtuse angle. A:( 526, 951), B:( 551, 234), C:( 358, 374) Angle ABC, 52.05 deg., is an acute angle. Angle BCA, 109.72 deg., is an obtuse angle. Angle CAB, 18.23 deg., is an acute angle. A:( 743, 858), B:( 106, 589), C:( 744, 536) Angle ABC, 27.64 deg., is an acute angle. Angle BCA, 85.07 deg., is an acute angle. Angle CAB, 67.28 deg., is an acute angle. A:( 483, 378), B:( 298, 60), C:( 205, 553) Angle ABC, 40.87 deg., is an acute angle. Angle BCA, 47.13 deg., is an acute angle. Angle CAB, 92.00 deg., is an obtuse angle. A:( 22, 645), B:( 723, 0), C:( 602, 301) Angle ABC, 25.48 deg., is an acute angle. Angle BCA, 142.57 deg., is an obtuse angle. Angle CAB, 11.95 deg., is an acute angle. A:( 748, 453), B:( 470, 256), C:( 757, 670) Angle ABC, 19.95 deg., is an acute angle. Angle BCA, 32.36 deg., is an acute angle. Angle CAB, 127.70 deg., is an obtuse angle. A:( 942, 133), B:( 343, 722), C:( 881, 957) Angle ABC, 68.11 deg., is an acute angle. Angle BCA, 70.64 deg., is an acute angle. Angle CAB, 41.25 deg., is an acute angle. A:( 522, 766), B:( 17, 908), C:( 162, 346) Angle ABC, 59.83 deg., is an acute angle. Angle BCA, 55.07 deg., is an acute angle. Angle CAB, 65.10 deg., is an acute angle. A:( 84, 246), B:( 257, 549), C:( 578, 748) Angle ABC, 151.52 deg., is an obtuse angle. Angle BCA, 13.66 deg., is an acute angle. Angle CAB, 14.82 deg., is an acute angle. A:( 533, 398), B:( 376, 247), C:( 947, 661) Angle ABC, 7.94 deg., is an acute angle. Angle BCA, 3.52 deg., is an acute angle. Angle CAB, 168.54 deg., is an obtuse angle. A:( 565, 780), B:( 404, 193), C:( 651, 761) Angle ABC, 8.16 deg., is an acute angle. Angle BCA, 78.96 deg., is an acute angle. Angle CAB, 92.88 deg., is an obtuse angle. A:( 343, 644), B:( 168, 159), C:( 360, 620) Angle ABC, 2.77 deg., is an acute angle. Angle BCA, 122.08 deg., is an obtuse angle. Angle CAB, 55.15 deg., is an acute angle. A:( 717, 640), B:( 439, 770), C:( 231, 795) Angle ABC, 161.79 deg., is an obtuse angle. Angle BCA, 10.84 deg., is an acute angle. Angle CAB, 7.37 deg., is an acute angle. A:( 116, 720), B:( 780, 261), C:( 986, 919) Angle ABC, 72.73 deg., is an acute angle. Angle BCA, 59.73 deg., is an acute angle. Angle CAB, 47.54 deg., is an acute angle. A:( 896, 642), B:( 657, 143), C:( 865, 93) Angle ABC, 77.92 deg., is an acute angle. Angle BCA, 79.72 deg., is an acute angle. Angle CAB, 22.36 deg., is an acute angle. A:( 248, 290), B:( 271, 244), C:( 690, 379) Angle ABC, 98.71 deg., is an obtuse angle. Angle BCA, 6.47 deg., is an acute angle. Angle CAB, 74.82 deg., is an acute angle. A:( 881, 128), B:( 625, 619), C:( 500, 283) Angle ABC, 47.94 deg., is an acute angle. Angle BCA, 91.73 deg., is an obtuse angle. Angle CAB, 40.33 deg., is an acute angle. A:( 673, 781), B:( 237, 875), C:( 758, 939) Angle ABC, 19.17 deg., is an acute angle. Angle BCA, 54.72 deg., is an acute angle. Angle CAB, 106.11 deg., is an obtuse angle. A:( 312, 318), B:( 528, 687), C:( 866, 910) Angle ABC, 153.76 deg., is an obtuse angle. Angle BCA, 13.48 deg., is an acute angle. Angle CAB, 12.76 deg., is an acute angle. A:( 574, 54), B:( 132, 455), C:( 329, 490) Angle ABC, 52.29 deg., is an acute angle. Angle BCA, 109.26 deg., is an obtuse angle. Angle CAB, 18.45 deg., is an acute angle. A:( 265, 438), B:( 123, 968), C:( 978, 813) Angle ABC, 64.73 deg., is an acute angle. Angle BCA, 38.02 deg., is an acute angle. Angle CAB, 77.26 deg., is an acute angle. A:( 207, 938), B:( 175, 964), C:( 274, 5) Angle ABC, 45.01 deg., is an acute angle. Angle BCA, 1.79 deg., is an acute angle. Angle CAB, 133.20 deg., is an obtuse angle. A:( 994, 458), B:( 922, 245), C:( 655, 277) Angle ABC, 101.84 deg., is an obtuse angle. Angle BCA, 34.93 deg., is an acute angle. Angle CAB, 43.22 deg., is an acute angle. A:( 286, 575), B:( 382, 150), C:( 271, 519) Angle ABC, 4.01 deg., is an acute angle. Angle BCA, 148.26 deg., is an obtuse angle. Angle CAB, 27.72 deg., is an acute angle. A:( 644, 544), B:( 926, 508), C:( 590, 74) Angle ABC, 59.53 deg., is an acute angle. Angle BCA, 31.19 deg., is an acute angle. Angle CAB, 89.28 deg., is an acute angle. A:( 614, 513), B:( 623, 27), C:( 690, 685) Angle ABC, 6.87 deg., is an acute angle. Angle BCA, 18.02 deg., is an acute angle. Angle CAB, 155.10 deg., is an obtuse angle.