# Thread: Newbie: Stuck on some Math

1. ## Newbie: Stuck on some Math

Hi All

I'm new to the forum and new to C. I have an assignment that I am having trouble with.

First off what I need to do is re-organize this formula to find θ.

http://img395.imageshack.us/img395/7...tioncy4.th.jpg

Initially I had to write code to find "d". I managed that by breaking the formula into three sections (ie square root, division, and sine squared).

I am finding it very difficult to re-organize this formula and have written more than two pages of twisting and changing but cannot get it. Maybe it is not possible and I will need to break it down into subsections without changing it around??

Anyway, any and all help will be much appreciated.

Thanks

2. So, the formula is, rewritten as C-ish:
Code:
`d = (v * cos(B) / g) * (sin(B) + sqrt(v * v * (sin(B) * sin(B) - 2 * g * h))`
And you want to transform that into something that gives B = ....

That is beyond me - I'm just making sure that we're answering the right question first of all (one could easily spend quite a bit on rewriting the formula in different ways, and it's good to be sure that it's the RIGHT form first).

--
Mats

3. Yes, that's the first part.

I am fairly certain that it is necessary to change the formula in order to find θ.

Specifically I need to: "Extend your program to take three additional inputs v, h and d, and produce θ as output."

4. And what does that formula represent (does it have a name?) - it would possibly be googleable if you have something to actually search for. But sin, cos, θ and square root are far too common on the Web to make it searchable (and of course it may not use θ).

--
Mats

5. Well it's nothing common. It is the distance (d) traveled by a cannonball fired at velocity (v) at angle (θ) landing at a height (h).

I have googled as much as possible.

6. Originally Posted by filicudi
Well it's nothing common. It is the distance (d) traveled by a cannonball fired at velocity (v) at angle (θ) landing at a height (h).
Well, nothing common nowadays. I bet in medieval times that formula was all the rage.

QuantumPete

7. Ah, got it: It's a projectile trajectory calculation, right?

Note that the theta calculation would lead to a square equation - you get two different numerical answers (e.g. 30/60 degrees).

Edit: took too long to post!

--
Mats

8. Yes I think it would.

So can you or anyone help me out by switching it around (or hint, how to).

Many Thanks!

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

Look for "angle of elevation", and it gives the formula you need.

--
Mats

10. Thank you very much and I guess I do have to improve my google skills!

A resulting question though, to calculate sin^-1(θ) is there a math.h command or do I use 1/sinθ?

Is that the same thing?

11. that would be the asin() function - there is also acos, atan.

--
Mats

12. I just realised that is not enough.

My formula for the angle of elevation must take into account input (h) which is the height at which the cannonball stops. It is not continuing to the same level of the cannon.

13. Originally Posted by matsp
Ah, got it: It's a projectile trajectory calculation, right?

Note that the theta calculation would lead to a square equation - you get two different numerical answers (e.g. 30/60 degrees).

Edit: took too long to post!

--
Mats
Thats because one is considering a direct shot fired and the other angle is for a curved shot ( ie a mortar round's path of travel ). I would think for this problem you want the second, since a cannonball would travel as such, unless the distance was so minute that the shot didn't have time to begin its descent as gravity began to drag the ball down and the velocity of the shot slowed from friction, causing it to lose its ability to continue driving upward. Of course, your teacher may be treating this problem as a simple vacuum shot where neither gravity nor friction would come into play.

EDIT: whoops, sorry Mats...I didn't see your googled link which describes this much better than I could.

14. Does this help:

http://en.wikipedia.org/wiki/Traject...le#Height_at_x

Look for Angle theta required to hit coordinate ( x,y)