Skip to content

Instantly share code, notes, and snippets.

@croepha
Last active January 2, 2019 01:01
Show Gist options
  • Save croepha/08c61362b8d91bad99cdbeb1e72f6c7b to your computer and use it in GitHub Desktop.
Save croepha/08c61362b8d91bad99cdbeb1e72f6c7b to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
/*
* a1 \ a1 \
* |\ |\ s3 ______ a22
* | \ s3 s21 | \ | /
* | \ | \ s22 | / s1
* s2 | \ |___\ a21 a3 |/
* | \ a2
* | /
* | / s1
* a3 /
*/
void solve_triangle(double a1, double a2, double a3,
double&s1, double&s2, double&s3) {
double a21 = 90 - a1;
s3 = 1.0 / ( cos(a21*PI/180.0) );
double s21 = tan(a21*PI/180.0);
double a22 = a2-a21;
s1 = 1.0 / ( cos(a22*PI/180.0) );
double s22 = tan(a22*PI/180.0);
s2 = s21 + s22;
}
void divide(double&v1, double&v2, double&v3, double q) {
v1 = v1 / q;
v2 = v2 / q;
v3 = v3 / q;
}
int main () {
double CEDc, CEDe, CEDd, AECa, AECe, AECc, BEDb, BEDe, BEDd;
double ACDa, ACDc, ACDd, BDCb, BDCd, BDCc;
double AEBa, AEBe, AEBb;
solve_triangle(60, 70, 50, CEDc, CEDe, CEDd);
solve_triangle(50, 110, 20, AECa, AECe, AECc);
solve_triangle(40, 110, 30, BEDb, BEDe, BEDd);
solve_triangle(50, 20+60, 50, ACDa, ACDc, ACDd);
solve_triangle(40, 30+50, 60, BDCb, BDCd, BDCc);
divide(CEDc, CEDe, CEDd, CEDe/1.0 ); // CEDe := 1
divide(AECa, AECe, AECc, AECa/CEDd ); // AECa := CEDd
divide(BEDb, BEDe, BEDd, BEDb/CEDc ); // BEDb := CEDc
divide(ACDa, ACDc, ACDd, ACDa/1.0 ); // ACDa := 1
divide(BDCb, BDCd, BDCc, BDCb/1.0 ); // BDCb := 1
AEBa = BDCd - CEDd;
AEBb = ACDc - CEDc;
// Law of cosines
AEBe = sqrt( pow(AEBa, 2) + pow(AEBb, 2) - 2 * AEBa * AEBb * cos(70*PI/180.0));
// Law of sines
double BAE = asin( sin(70*PI/180.0) * AEBa / AEBe )*180.0/PI;
printf("BAE:%f", BAE);
// 80.00
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment