----- Original Message ----- From: "Denny Esterline" To: "Microcontroller discussion list - Public." Sent: Friday, April 01, 2005 5:07 PM Subject: Re: [EE] Math formula help. > It's not an easy one... > > I don't know about mathematical crescent wrenches, but my crowbar (ti-89 > calculator) spits out this for the sin/cos version: > > (ad-bc)cos(theta)-(af-ce)sin(theta)-(bf+de)=0 Your calculator got partway there. Unfortunately it doesn't appear to be as bright as Scott Dattalo! > The equation as written is a monster, but with a better understanding of > the > underlying problem, we might be able to help you find a better solution. The underlying problem was trying to determine the correct angle to fire a gun of a certain length (gunLength) so that the projectile, travelling at a given velocity (bulletSpeed) would intercept an object that starts at location (x0,y0) relative to the gun and moves at velocity (deltaX,deltaY). Here is where the formula came from: where will the bullet be at time t relative to shoot time? sin(theta)*(gunLength + bulletSpeed*t) cos(theta)*(gunLength + bulletSpeed*t) where will the enemy be at time t relative to shoot time? x0+deltaX*t y0+deltaY*t so, the bullet hits the enemy when the two are at the same point: sin(theta)*(gunLength + bulletSpeed*t) = x0+deltaX*t cos(theta)*(gunLength + bulletSpeed*t) = y0+deltaY*t then solve each of the two equations above for t: (sin(theta)*gunLength-x0) t = ------------------------------- (deltaX-sin(theta)*bulletSpeed) and: (cos(theta)*gunLength-y0) t = -------------------------------- (deltaY-cos(theta)*bulletSpeed) Now use the above two substitutions for t to create an equation that has theta as the only unknown: cos(theta)*gunLength - y0 sin(theta)*gunLength-x0 ------------------------------- = ------------------------------- deltaY-cos(theta)*bulletSpeed deltaX - sin(theta)*bulletSpeed Doing a little judicious juggling and sign changing I substituted single letters for the funny variable names to create my post: a = gunLength c = -bulletSpeed b = -x0 d = deltaX e = -y0 f = deltaY Oh, and don't ask what I needed to know this for.. :-) Bob Ammerman RAm Systems -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist