9 bool angSideAng(
double &angA,
double &sideB,
double &angC,
double sideA,
double angB,
double sideC) {
10 double const Epsilon = std::numeric_limits<double>::epsilon();
12 bool unknownAng =
false;
14 double sinHalfAngB =
sind(angB * 0.5);
15 double cosHalfAngB =
cosd(angB * 0.5);
16 double sinHalfSideA =
sind(sideA * 0.5);
17 double cosHalfSideA =
cosd(sideA * 0.5);
18 double sinHalfSideC =
sind(sideC * 0.5);
19 double cosHalfSideC =
cosd(sideC * 0.5);
21 if (std::abs(sinHalfSideA) < Epsilon) {
23 if (std::abs(sinHalfSideC) < Epsilon) {
29 }
else if (std::abs(cosHalfSideC) < Epsilon) {
41 }
else if (std::abs(cosHalfSideA) < Epsilon) {
43 if (std::abs(cosHalfSideC) < Epsilon) {
49 }
else if (std::abs(sinHalfSideC) < Epsilon) {
58 sideB = 180.0 - sideC;
61 }
else if (std::abs(sinHalfSideC) < Epsilon) {
66 }
else if (std::abs(cosHalfSideC) < Epsilon) {
69 sideB = 180.0 - sideA;
71 }
else if (std::abs(sinHalfAngB) < Epsilon) {
73 if (std::abs(sideA - sideC) < Epsilon) {
79 }
else if (sideC < sideA) {
81 sideB = sideA - sideC;
85 sideB = sideC - sideA;
93 double num1 = cosHalfAngB * ((cosHalfSideA * cosHalfSideC) + (sinHalfSideA * sinHalfSideC));
94 double den1 = sinHalfAngB * ((cosHalfSideA * cosHalfSideC) - (sinHalfSideA * sinHalfSideC));
95 double num2 = cosHalfAngB * ((sinHalfSideA * cosHalfSideC) - (cosHalfSideA * sinHalfSideC));
96 double den2 = sinHalfAngB * ((sinHalfSideA * cosHalfSideC) + (cosHalfSideA * sinHalfSideC));
100 if ( ((std::abs(num1) <= Epsilon) && (std::abs(den1) <= Epsilon))
101 || ((std::abs(num2) <= Epsilon) && (std::abs(den2) <= Epsilon))) {
102 std::ostringstream os;
103 os <<
"Bug: can't compute angA and angC with sideA=" << sideA <<
", angB=" << angB <<
", sideC=" << sideC;
104 throw std::runtime_error(os.str());
108 double h_sum_AC =
atan2d (num1, den1);
109 double h_diff_AC =
atan2d (num2, den2);
111 angA = h_sum_AC + h_diff_AC;
112 angC = h_sum_AC - h_diff_AC;
118 double sinHalfAngA =
sind(angA * 0.5);
119 double cosHalfAngA =
cosd(angA * 0.5);
122 double num3 = sinHalfSideC * ((sinHalfAngB * cosHalfAngA) - (cosHalfAngB * sinHalfAngA));
123 double den3 = cosHalfSideC * ((sinHalfAngB * cosHalfAngA) + (cosHalfAngB * sinHalfAngA));
126 double num4 = sinHalfSideC * ((cosHalfAngB * cosHalfAngA) + (sinHalfAngB * sinHalfAngA));
127 double den4 = cosHalfSideC * ((cosHalfAngB * cosHalfAngA) - (sinHalfAngB * sinHalfAngA));
130 if (std::abs(num3) + std::abs(den3) > std::abs(num4) + std::abs(den4)) {
132 sideB = 2.0 *
atan2d(num3, den3) + sideA;
134 sideB = 2.0 *
atan2d(num4, den4) - sideA;
double cosd(double ang)
cosine of angle in degrees
double sind(double ang)
sine of angle in degrees
double atan2d(double x, double y)
arctangent2 in degrees
bool angSideAng(double &angA, double &sideB, double &angC, double sideA, double angB, double sideC)
double wrapPos(double ang)