Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wednesday Evening Physics

 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who said I wanted y to be 0? The object is at ( x , y ).
[ January 11, 2006: Message edited by: Nick George ]
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be able to use the velocity and angle and x to remove 't'
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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 ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and calculate the distance travelled by the projectile
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D'oh!

Yes, that's what I was thinking, unfortunately not what I actually said. Oopsie.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Professional code-artists use the dot-trick exclusively shown here:

 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
woah
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan, just checking that you saw this regarding jobs in Berlin.
 
Jon Pincott
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I actually found my mistake, just missed an x.

Thanks.
 
samantha hewamanage
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic