aspose file tools*
The moose likes Programming Diversions and the fly likes Wednesday Evening Physics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Wednesday Evening Physics" Watch "Wednesday Evening Physics" New topic
Author

Wednesday Evening Physics

Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
A particle is fired from ( 0 , 0 ) with velocity v at angle theta. It is to hit an object at ( x , y ).



in the x direction we have:

x = v * cos( theta ) * t

in the y direction we have:

y = v * sin( theta ) * t - 1/2 * g * t^2

The question is this: solve for theta.
It seems like the first thing an artilleryman ought to know, but I can't manage to do it. (The TI-89 couldn't hack it either, so I feel a little better).
If I solve for t in the x equation, I get a nightmare of trig.
If I solve for theta, and then use a right triangle to get rid of all the trig, I get a mess of sqare roots and squares that I can't simplify. I'd love for any help I can find around the 'ranch. I'm hoping I can get Jim on the job...


I've heard it takes forever to grow a woman from the ground
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

You want y=0. So set y=0 and solve for t. One value is t=0, the other is v sin theta = gt/2. So sin theta = gt/2v.
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
Who said I wanted y to be 0? The object is at ( x , y ).
[ January 11, 2006: Message edited by: Nick George ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

I missed that. (Did your picture get worse between when you posted it and now? Well, anyway...)

x = vt cos theta
y+gt^2/2 = vt sin theta

So tan theta = (y+gt^2/2)/x and theta = arctan((y+gt^2/2)/x).

(The answer doesn't depend on v? I find that a bit odd.)
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You should be able to use the velocity and angle and x to remove 't'
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Paul]: Did your picture get worse between when you posted it and now?

That seems... doubtful...

The answer doesn't depend on v? I find that a bit odd.

Ah, but your answer does depend on t, which was not part of the initial conditions, and which will depend on x, y, v, and of course g. So by the time you fully eliminate t, the answer will again depend on v.

[Nick]: If I solve for t in the x equation, I get a nightmare of trig.

Unfortunately, I think that's the best route to take here. Eliminate t by solving for it in one equation and substituting into the other. After that - it's pretty icky. The half-angle formulas from trigonometry are probably useful here - you can rewrite the various trig functions so they're all in terms of cos 2θ (or possibly cos 4θ, depending how you do it) then make some substitution like u = cos 2θ (if only to cut down on writing) and keep simplifying.

Alternately, I expect there's a complete formula and derivation in most university intro Physics textbooks (for the calculus-based intro courses, at least - the solution doesn't require calc but it's of comparable complexity). Or it's probably online somewhere, though it didn't jump out in a few quick googles. I worked through it once, but as I recall it's one of the more complex derivations in [supposedly] "basic" projectile motion.

it seems like the first thing an artilleryman ought to know

Yeah, but most of them just memorized the final formulas. Actually working them out on the spot would've been a bit much to expect, especially in the midst of battle. For extra fun, throw in centrifugal forces, Coriolis forces, and air resistance.
[ January 12, 2006: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

...and calculate the distance travelled by the projectile
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
The picture seems to work about 25% of the time- I thought 'code' tags preserved spacing.

I figured double angle formulas would come into play. I hate trig identities.


Thanks,
Nick
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

The picture is much better this morning. The line on the right is vertical, whereas last night it wasn't. But different computers were involved too.

And yeah, the answer not depending on v wasn't just "a bit odd", it should have been a big red flag.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
it seems like the first thing an artilleryman ought to know

Yeah, but most of them just memorized the final formulas. Actually working them out on the spot would've been a bit much to expect, especially in the midst of battle. For extra fun, throw in centrifugal forces, Coriolis forces, and air resistance.


This problem was one of the great early motivators for military funding of computing research. Killing people with math. Shudder.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Nick]: I thought 'code' tags preserved spacing.

The spaces are there, but whether or not they're rendered in monospace font is the issue. UBB has some bugs in this area, rendering nonstandard HTML which is interpreted differently by different browsers. I believe IE, Safari and Opera render the monospace consistently, while Firefox may not. Since the font tags are nested incorrectly to begin with, I'm not sure this is can be called a Firefox bug. The rendering also seems to depend on the content of other posts on the page, in a way I don't understand.

Most of the time this isn't a big issue - in code for example, it doesn't matter if the initial spaces are monospace or not, as long as all the indentation is done in spaces. The relative indentation of the beginning of each line of code works out the same. But in an ASCII diagram where we depend on the relative position of characters not at the beginning of a line, the problem becomes more noticeable.

[Paul C]: And yeah, the answer not depending on v wasn't just "a bit odd", it should have been a big red flag.

To be fair, it's not unheard of for variables to drop out unexpectedly. The fact that the period of a simple pendulum is unaffected by its length, for example. So I think I can see where you were coming from...
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
The fact that the period of a simple pendulum is unaffected by its length


At the risk of stepping into a big one...

I thought that the length was the ONLY factor that affected a pendulum's period? (In other words the weight of the bob, the angle of the swing, etc. don't affect the period.)


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
D'oh!

Yes, that's what I was thinking, unfortunately not what I actually said. Oopsie.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Professional code-artists use the dot-trick exclusively shown here:



http://home.arcor.de/hirnstrom/bewerbung
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
woah
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Stefan, just checking that you saw this regarding jobs in Berlin.
Jon Pincott
Greenhorn

Joined: Jul 28, 2004
Posts: 17
The nasty looking trig you get when you eliminate t can be turned into a quadratic in tan theta using:

1) sin / cos = tan
2) 1 / cos^2 = 1 + tan^2

You can then just calculate your coefficients and plug into the normal quadratic formula to get two values for tan theta.


SCJP SCWCD
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
Ok!

So!



Now, I know that t > 0, so I can just take the principle square root of t² to get t. If I want the projectile to hit at the earliest possible time (i.e. on the way up), do I want the discriminant in the t² to be plus or minus? My preliminary investigations suggest it depends on what's bigger than what and by how much.
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
Originally posted by Jon Pincott:
The nasty looking trig you get when you eliminate t can be turned into a quadratic in tan theta using:

1) sin / cos = tan
2) 1 / cos^2 = 1 + tan^2

You can then just calculate your coefficients and plug into the normal quadratic formula to get two values for tan theta.



Wow...
just saw that.
That works brilliantly, no half angles or nuthin'.
Thanks.
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
I'm hoping I can get my math checked now.

I get a = gx/v^2, b = vx, and c = gx/v^2 - y. If

tan theta = -b +/- root(b^2- 4ac)
...........---------------------
....................2a,

here are the results:

the plus one is garbage- my guy always shoots straight up. Don't know why it's garbage, but it is.

the minus one is not quite garbage, but almost. First off, for some reason it's in the wrong direction, so I say pi - that. Then, it always under shoots by a bit. I'm beginning to think it's the fault of my program and not the math, but I hope someone will look over my math.

Thanks,
Nick.
Jon Pincott
Greenhorn

Joined: Jul 28, 2004
Posts: 17
Nick, I get something different for my coefficients:

[CODE]import java.util.Arrays;

public class Projectile {

private static final double GRAVITY = 9.80665;

public static void main(String[] args) {

double x = 100;
double y = 10;
double v = 35;

double[] thetas = solve(x, y, v);

System.out.println(Arrays.toString(toDegrees(thetas)));
}

private static double[] solve(double x, double y, double v) {

/*
* Eqn's of motion:
*
* x = v.cos th.t
* y = v.sin th.t - g.t^2/2
*
* Eliminate t:
*
* y = x.tan th -(g.x^2)/(2.v^2).(1 + tan^2 th)
*
* Collect terms for quadratic in theta:
*
* a = (g.x^2)/(2.v^2)
* b = -x
* c = a + y
*
* Solve quadratic eqn and calculate arctan
*/

double a, b, c;

a = x / v;
a *= a;
a /= 2;
a *= GRAVITY;

b = -x;

c = a + y;

double[] roots = getRoots(a, b, c);

return new double[] {
Math.atan(roots[0]),
Math.atan(roots[1])
};
}

private static double[] getRoots(double a, double b, double c) {

double t1, t2;

t1 = -b / a / 2;

t2 = t1 * t1;
t2 -= (c / a);
t2 = Math.sqrt(t2);

return new double[] {
t1 - t2,
t1 + t2
};
}

private static double[] toDegrees(double[] radians) {
double[] degrees = new double[radians.length];
for (int i = 0; i < degrees.length; i++) {
degrees[i] = Math.toDegrees(radians[i]);
}
return degrees;
}

}[CODE]
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
Yeah, I actually found my mistake, just missed an x.

Thanks.
samantha hewamanage
Greenhorn

Joined: Feb 22, 2006
Posts: 4
ok here is what u do
this need little trig. math

x = v * cos( theta ) * t ---------(A)

y = v * sin( theta ) * t - 1/2 * g * t^2 -------------(B)

first: solve (A) for t;

t = x /(v*cos(theta))

plug this into (B) and simplify

y = x*tan(theta) - 1/2*g*(1+(tan(theta))^2)--------------(C)

{used these trig. relations

tan(theta) = sin(theta)/cos(theta)

sec(theta) = 1/cos(theta)

(sec(theta))^2 = 1 + (tan(theta))^2

}


now u have a quadratic equation in terms of tan(theta)

solve it using
{

a*X^2+b*X +c = 0

roots:
X1 = (-b + sqrt(b^2 - 4*a*c))/(2*a)
X2 = (-b - sqrt(b^2 - 4*a*c))/(2*a)

}

take X= tan(theta)

then (C) becomes

y = x*X - 1/2*g*(1+X^2)

1/2*g*X^2 -x*X + (y+1/2*g) --------------(D)

now your a = 1/2*g b = -x c = y+1/2*g

now get X1 and X2

then

theta1 = ArcTan(X1)
theta2 = ArcTan(X2)

u can eliminate one of these by some argument like:
if it is negative or > 90 degrees
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Sam]u can eliminate one of these by some argument like:
if it is negative or > 90 degrees


That seems unlikely, as there will generally be two solutions in the range 0-90 degrees. One represents a more direct shot, the other represents a high lob. Usually you'd want the direct shot unless there are mountains or other impediments in the way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wednesday Evening Physics