getting distance from angles

This is a discussion on getting distance from angles within the C++ Programming forums, part of the General Programming Boards category; ....or triangulation. I would like to use two angles on a triangle and the distance between them to calculate the ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    at the bottom of the tank
    Posts
    6

    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.
    Last edited by HermitCrab; 06-08-2007 at 04:40 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Sounds like you need some maths help.
    http://mathworld.wolfram.com/topics/Geometry.html
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    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.

  4. #4
    Registered User Dave++'s Avatar
    Join Date
    Jun 2007
    Location
    Where the Buffalo Roam
    Posts
    40

    Thumbs up 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
    Last edited by Dave++; 06-08-2007 at 05:07 PM. Reason: typo

  5. #5
    Registered User
    Join Date
    Jun 2007
    Location
    at the bottom of the tank
    Posts
    6
    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;
    }

  6. #6
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907
    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.
    Last edited by CodeMonkey; 06-08-2007 at 07:30 PM.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segfaulting Distance Program
    By radiohead in forum C Programming
    Replies: 2
    Last Post: 01-09-2006, 07:48 PM
  2. Replies: 6
    Last Post: 01-08-2006, 01:49 PM
  3. Distance Formula in my program..... I need help fast!!!
    By Mackology101 in forum C Programming
    Replies: 3
    Last Post: 09-23-2004, 10:10 PM
  4. Distance Formula Implecations: Urgent!
    By KneeLess in forum C Programming
    Replies: 6
    Last Post: 03-20-2004, 09:52 PM
  5. Fuzzy Logic
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-13-2002, 04:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21