POV-Ray : Newsgroups : povray.advanced-users : Physics of flying? : Re: Physics of flying? Server Time
29 Jul 2024 16:28:18 EDT (-0400)
  Re: Physics of flying?  
From: Trevor Quayle
Date: 5 Dec 2001 13:04:19
Message: <3c0e61a3$1@news.povray.org>
I finished a macro to do this and find out you don't need it anymore!
Oh well, here it is anyways. I have debugged it as best I can, if you try it
and have a problem, let me know.

Use it in a scene as follows:

#declare Angle= BA(V,D,H,g,P,Sno);

or equivilant, as the macro returns a number, not a declared variable.

Syntax:
V=total velocity (should be positive)
D=Horizontal distance (should be positive)
H=change in height (initial to final, can be any number)
g=gravitational acceleration (i.e., -9.81  (should be negative, but not
necessarily)
P=precision (decimal places, i.e. P=3 : 3 decimal places)
Sno=solution number (should be 1 or 2)*

*for every given set of variables there is up to four solutions possible,
the macro assumes the projectile wants to land on the spot coming down so
two possible solutions can be eliminated.
There remains up to (not necessarily always) 2 angles to reach the given
distance, using Sno=1 returns the first, Sno=2 returns the second.
The macro may return errors to let you know if, 1) the final height cannot
be reached, 2) the final distance cannot be reached or 3) the second
solution is selected and there is no second solution.
Macro returns angle in degrees

examples:

#declare A = BA(10,10,-10,-9.81,4,1);
returns 67.8849 degrees

#declare A = BA(10,10,-10,-9.81,4,2);
returns error (no second solution)

Now the macro:

//start
#macro BA(V,D,H,g,P,Sno)
  #if (-1/2*V^2/g<H) #error "Final height(H) unattainable at given
velocity(V)!" #end
  #local chk=0;
  #local dD1 = 1;
  #local dA =10;
  #local A=0;
  #local Sol=1;
  #while (dD1 != 0)
    #local Vy=V*sin(radians(A));
    #local Vx=V*cos(radians(A));
    #if (Vy^2+2*g*H>=0)
      #local dX=-Vx*(Vy+sqrt(Vy^2+2*g*H))/g;
      #local dD1=int((D-dX)*10^(P+1));
      #if (chk=0) #local dD2=dD1; #end
      #if (dD1 = dD2)
        #local chk=chk+1;
        #if (chk=3)
          #if (Sol=2)
            #error "No second solution!"
          #else
            #error "Final distance unattainable at given velocity!"
          #end
        #end
      #else
        #local chk=1;
      #end
      #if (dD1 != 0)
        #if (dD1*dD2<0)
          #if (Sno!=Sol)
            #local Sol=Sol+1;
          #else
            #local dA=-dA/2;
          #end
        #else
          #if (dD1>0 & dD1-dD2>0)
            #if (Sol=2)
              #error "No second solution!"
            #else
              #local A=A-dA*2;
              #local dA=dA/2;
            #end
          #end
        #end
      #end
      #local dD2=dD1;
    #end
    #if (dD1 != 0) #local A=A+dA; #end
  #end
  #debug concat("Angle = ",str(A,0,5)," degrees\n")
  A
#end
//end


-tgq


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.