Assignment- generate random angle theta within and circle and calculate chord length

Could someone please give me a clue. Thanks much for any help!
theta between 1-180 degrees

// Program to generate a random angle and chord subtended by said angle.

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{// Define and initialize variables
const pi_value = M_PI
const float radius = 2.5;
srand(time(0));
int random_angle = 0;
double chord_length = 0;
chord_length = (2*radius*sin(random_angle/2));


srand((unsigned)time(0));
random_angle = (rand()%180)+1;
cout << "angle";
cin >> random_angle;
cout << chord_length;







system("pause");
return 0;
Please forgive the crude ASCII art, but here's what is being asked:

                     a
        .     '     o
    .              /    .
  .               /       .
 .               /         .
                /        
.              / Θ          .
              o-------------o b
'            c              '

 '                         '
  '                       '
    '                   '
        '    .      '

What is the distance between points a and b, given Θ (and r, presumably)?

A lot of math problems include information that is more-or-less a distraction. Stuff about the circle is a distraction. You are being asked to find the odd side of an isoceles triangle. More ASCII art:

         c
        o
       / \
      /   \
     /     \
  r /       \ r
   /         \
  /           \
 /             \
o---------------o a
 b

To find the third side of any triangle, given two sides and an angle between them, use the Law of Cosines:
https://en.wikipedia.org/wiki/Law_of_cosines#Applications
(Conveniently, ac and bc are the same; ac==bc==r.)

Hope this helps.

[edit] Just re-read this, and fixed a statement to match the picture.
Last edited on
Thanks Duoas!
Topic archived. No new replies allowed.