# getting distance from angles

• 06-08-2007
HermitCrab
getting distance from angles
....or triangulation.

I would like to use two angles on a triangle and the distance between them to calculate the distance to the third angle. there are a few ways to do this, although I can't remember them at the moment but what is the BEST way to do it in C++? I need accuracy to +-.05 or better more than I need speed but both is better. It will not always be an Isosceles. the only constant will be the distance between the two angles.
I started learning C++ on my own about a week ago but I can write a program to calculate most of the more simple mathematical formulas.
• 06-08-2007
Salem
Sounds like you need some maths help.
http://mathworld.wolfram.com/topics/Geometry.html
• 06-08-2007
scwizzo
If you know your trig identities it should be easy to calculate the distances. If you want I made a planimeter program (calculates total perimeter and area of a polygon) that you can look at.

I would go try to find some angles, and knowing two sides with angles you can find the distance of the third side.
• 06-08-2007
Dave++
Constructing triangles
Hermit,
You will want to use the ratio of sines for this problem (Look it up. Hint: if you know two angles you know them all). Also, there is no "one way" or key formula to do all things with triangles. But I think your looking to see what C++ can do?
So, I suggest you could create a class called Triangle and overload its constructor.
Triangle(double s1, double s2, double s3){...}
Triangle(double s1, double a1, double a2){...}
Triangle(double s1){...} // makes iso
While the above is notional (so get the right syntax as you code) each constructor would fill in the six variables (see below) in different ways. In other words create the class to contain all the tools to work with triangles -- just keep adding over time.
Start with Triangle() {s1= s2= s3=1, a1= a2=a3=2 x PI / 3;}
double Triangle.getS1()
void Triangle.makeS1()
double Triangle.getArea()
void Triangle.scale(double)
...

Good luck, Dave :cool:
• 06-08-2007
HermitCrab
I wrote the fallowing to test, I'm not sure why but I keep wanting to change the float to double. maybe I should. anyway I just used int main and return 0 until I know it works like it needs to. then I will add it to my program as double triangle1() or something like that. Most likely I will end up redoing the whole program a few times as I learn but programing is just to fun to wait until I really know what I am doing. (puts on geek hat)
salem, that is the site I have been looking for for the last hour, thanks.
Code:

```#include <iostream> #include <math.h> int main() {   // Variables A, B, and C are angles   // a, b and c are sides   float A, B, C, a, b, c, sum;   cout << "\nAngle A: ";   cin >> A;   cout << "\nAngle B: ";   cin >> B;   a = 12;   b = a * cos(A);   sum = (a * a) + (b * b);   c =  sqrt(sum);   C = 180 - (A + B);   cout << "\nAngle C = " << C           << "\n c = " << c;   cin.get();   cin.get();   return 0; }```
• 06-08-2007
CodeMonkey
Ok:
Code:

```sin A        sin B            sin C ------    =  -------  =      --------   a            b                  c```
If you know A (input), and you know B (input) and you know 'a' (magic number in your code), then you can find 'b'. Then, because you know A and B, you can find C. Then using either (sin A)/a or (sin B)/b, you can find c.

*edit* Go ahead and use doubles: higher precision; the functions are overloaded.

*edit* Of course 'a' is opposite A, 'b' opposite B, etc.