How to write this triginometry equation?

Well my C++ class is mixed with CS majors and Engineer majors, so most of our labs are geared toward engineers. I'm still in precalculus so this is slightly confusing to me.

I have the entire program coded besides this equation.

The instructions state this:

Sin2θ=d*g/pow(V0,2.0)
2 θ in radians is asin(d*g/pow(V0,2.0))
Degree=radian*180/PI (PI=3.1416)

My professor explained it in class, but he has an extremely strong accent and I could not understand him.

I understand most of the equation, but when it talks about "Sin2θ" and "2 θ in radians is asin" I get lost.
Last edited on
sin2θ = 2sin(θ)cos(θ)
Google trig identities for more.
Use the highest resolution for PI that you can.
That equation does not really tell what you have, what you have to calculate, and why?

Who are the θ, d, g, V0?
These were instructions:

Projectiles follow a parabolic path through the air, due to the acceleration of gravity. In this problem set, you will calculate the optimum, minimum, and maximum release angle for throwing a ball into a basket. The equation describing the relationship between release angle, θ, initial speed, v0, and distance, d:
d= V02 *sin2θ /g
where g = 9.8 m/s2 is the acceleration due to gravity

Your program should prompt the user for the following inputs:

· distance, d, from thrower’s hand to the center of the basket (in meters)
· diameter of the basket (in meters)
· initial ball speed v0 (in meters/second)
· height of the ceiling from the basket (in meters)

Assume that the diameter of the ball is too small to make any difference in the calculation.
Optimum angle : ball drops in the middle of the basket (distance d)
Minimum angle: ball drops on the left edge of the basket (d – diameter of the basket/2)
Maximum angle: ball drops on the right edge of the basket (d+ diameter of the basket/2)

Sin2θ=d*g/pow(V0,2.0)
2 θ in radians is asin(d*g/pow(V0,2.0))
Degree=radian*180/PI (PI=3.1416) Declare as named constant

Main should prompt the user for inputs and display the output.
Calculations must be done in a function called calcAngle
This function should return the angle in degrees.
NO GLOBAL Variables.


My code so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cmath>

using namespace std;

double calcAngle(double, double, double, double);

int main()
{
    double distance, diameter, InitialBallSpeed, height;
    cout << "Enter the distance in meters:\t";
    cin >> distance;
    cout << "\nEnter the diameter of the basket in meters:\t";
    cin >> diameter;
    cout << "\nEnter the initial ball speed in meter/second:\t";
    cin >> InitialBallSpeed;
    cout << "\nEnter the height of the ceiling from the basket in meters:\t";
    cin >> height;
    return 0;
}

double calcAngle(double d, double dm, double ibs, double h){
double Degree;
const double PI = 3.1416;
//Calculations here
return Degree;
}


I'm just so confused with the calculations.
http://www.cplusplus.com/reference/cmath/asin/

http://en.wikipedia.org/wiki/Range_of_a_projectile


θ is an angle. 2*θ is double that. Lets call 2θ "A", i.e. A==2*θ.

You have: sin(A) == d * g / pow(v0, 2.0)
Take arc sine from both sides: asin(sin(A)) == asin(d * g / pow(v0, 2.0))
On the left side the asin and sin cancel each other: A == asin(d * g / pow(v0, 2.0))
In other words, by calculating the right side we will get A.

Can you calculate the θ from A?
calcAngle should return an angle from the inputs. The only inputs it needs are d and v0:
1
2
3
4
5
6
7
8
// Given an initial velocity and the distance that an object travels,
// compute the angle that should be used. Return the angle in degrees.
double calcAngle(double d, double v0)
{
    const double PI = 3.141592653589793;
    const double g = 9.8;
    // compute the angle and return it.
}


Your main program will call this function 3 times with 3 different distances: one to compute the minimum angle, one for the max angle and one for the optimum angle.

There's no reason to use the pow() function here. It would be faster and possibly more accurate to use (v0*v0) instead of pow(v0,2.0).

Have you studied trig? Do you know what sin() and asin() are?
No I have not studied trig, and I haven't gone over sin() and asin() since highschool (about 4 years ago). However I did check the link posted today and got some help from my instructor, so far I have this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <cmath>

using namespace std;

double calcAngle(double, double);

int main()
{
    double distance, diameter, InitialBallSpeed, height, Opt, Min, Max, MinD, MaxD;

    cout << "Enter the distance in meters:\t";
    cin >> distance;
    cout << "\nEnter the diameter of the basket in meters:\t";
    cin >> diameter;
    cout << "\nEnter the ball speed in meters/second:\t";
    cin >> InitialBallSpeed;
    cout << "\nEnter the height of the ceiling from the basket in meters:\t";
    cin >> height;

    Opt = calcAngle(distance,InitialBallSpeed);
    MinD = distance - diameter / 2;
    Min = calcAngle(MinD,InitialBallSpeed);
    MaxD = distance + diameter / 2;
    Max = calcAngle(MaxD,InitialBallSpeed);

    cout << "\n\nThe optimum angle is " << Opt << " Degrees";
    cout << "\nThe minimum angle is " << Min << " Degrees";
    cout << "\nThe maximum angle is " << Max << " Degrees" << endl;

    return 0;
}

double calcAngle(double dis, double inspeed){
double Degree, Radians;
const double PI = 3.1416;
const double g = 9.8;

Radians = asin(dis*g/(inspeed * inspeed));
Degree = Radians * 90/PI;
return Degree;
}


It runs, but there is a logical error somewhere.

When I input the example input he provides, Diameter: 10 Distance: 2 Initial speed: 5
This is the output:

The optimum angle is -1.#IND Degrees
The minimum angle is -1.#IND Degrees
The maximum angle is -1.#IND Degrees


He walked me through writing the equation, so according to him it is written correctly. It obviously isn't.
Last edited on
Do you mean distance 10m and diameter 2m? The other way the "near edge" would be at -3 m. Besides, 10m sounds like a big basket.


Anyway. Do you think that throwing a ball 5 m/s will make it fly far enough?
Range R == v^2 * sin(2θ) / g
At θ == 45 degrees the sin(2θ) == 1, and thus the maximal range is
R == v^2 / g == 25 / 9.8 m == 2.55 m

In other words: There is no angle that could get the ball in with those v and d.
Those were the examples he showed. He did say there was a logical error in his example, so that must be it! Thanks everyone!
Topic archived. No new replies allowed.