View Single Post
  #11   Spotlight this post!  
Unread 23-02-2012, 19:56
Lalaland1125 Lalaland1125 is offline
Registered User
AKA: Ethan Steinberg
FRC #2429
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2011
Location: La Canada
Posts: 29
Lalaland1125 is an unknown quantity at this point
Re: Trajectory Calculator (W/ Drag)

I ran your numbers through my dead simple approximator(code at bottom) and got a different result(image + source code is attached)

I am fairly sure that your result cannot be correct due to running it through the standard projectile motion equations.

Assuming no loss of energy, the ball will follow the equation: .5*Vy^2 = g * h.
(mgh = 1/2 * m * v^2)

Plugging this into wolfram alpha(http://www.wolframalpha.com/input/?i=%28%2823+feet+per+second+in+meters+*+sin%2845+d egrees%29%29+**+2++*+.5+%29%2F9.8+meters+per+secon d+squared) ( using meters because I am more used to them) gets me 4.113 ft as the max possible height. Your graph shows the ball approaching 7 m.

(When I set the drag to 0 on my code the height reaches a max of about 4ft and change)

Oh, and the code attachment shows what I mean by trial and error. Look at findBestCurveWithin.

Code:
void calcY(double& x,double& y, double &xVel, double& yVel)
{
   double oldxVel = xVel;
   double oldyVel = yVel;


   xVel += drag * xVel * xVel * timeIncrement;
   yVel += (g + drag * yVel * yVel) * timeIncrement;

   x += oldxVel * timeIncrement + .5 * timeIncrement * (xVel - oldxVel);
   y += oldyVel * timeIncrement + .5 * timeIncrement * (yVel - oldyVel);
}

QVector<QPointF> findCurve(double velocity, double angle, double targetX)
{
   QVector<QPointF> result;

   double rads = angle * M_PI/180;
   double xVel = velocity * cos(rads);
   double yVel = velocity * sin(rads);
   double x = 0;
   double y = 0;

   do
   {
      calcY(x,y,xVel,yVel);
      result.push_back(QPointF(x,y));
   }
   while (fabs(x - targetX) > .01);


   return result;
}
Attached Thumbnails
Click image for larger version

Name:	blah.png
Views:	17
Size:	10.7 KB
ID:	12082  
Attached Files
File Type: cpp mainwindow.cpp (3.4 KB, 4 views)

Last edited by Lalaland1125 : 23-02-2012 at 20:08.