Hitting a target

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Hitting a target

Postby tod » Thu Sep 15, 2011 4:40 pm

I fixed my code and now it seems to work, at the first glance. Here it is:
//prepare values for angle computation
// the distance between the vectors
Real staightDistance = start.distance(stop);
// height on y
Real height = stop.y - start.y;
// distance on local x
Real distance = Math::Sqrt(staightDistance*staightDistance - height*height);
Real speed = getMaxThrowSpeed();
Real gravity = Math::Abs(SettingsManager::getSingleton().getGravity());
// compute angles from horizontal
Radian angle = Math::ATan((Math::Sqr(speed)-Math::Sqrt(Math::Pow(speed,4) - gravity*(gravity*Math::Sqr(distance)+2*height*Math::Sqr(speed))))/(gravity*distance));
//Radian angle = Math::ATan((Math::Sqr(speed)+Math::Sqrt(Math::Pow(speed,4) - gravity*(gravity*Math::Sqr(distance)+2*height*Math::Sqr(speed))))/(gravity*distance));
// compute velocity vector
Vector3 velocity = stop - start;
velocity.y = distance * Math::Tan(angle);
velocity.normalise();
velocity = velocity * speed;

return velocity;


I still have a question, there are two results to the equation, what is the difference between them?
tod
 
Posts: 29
Joined: Thu Mar 04, 2010 4:39 pm

Re: Hitting a target

Postby Julio Jerez » Thu Sep 15, 2011 5:49 pm

if you look at the image on wikipedia, you can see that for each target ther are tow diffrent angle tha can hit the same targe. those arehe tow angle you are getting.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests