Physics golf: inclined shooting

Java

Works for radians only

double q(double a, double b, double u){
          return (Math.abs(((-Math.tan(a)+(Math.tan(b)))*(u*u)*(0.2*(Math.cos(b)*Math.cos(b))))));
      }

Golfed Version (Thanks to Peter)

double z=u*Math.cos(b);return(Math.tan(b)-Math.tan(a))*z*z/5;

Maths Used:

q=u Cos(B) t
q tan(A) = u sin (B) t - .5 * 10 * t^2

- tan (A)  + tan(B) = 5q/u^2 sec^2 (B)
q =  [ - tan(A) + tan (B) ] u^2
    ---------------------
    sec^2(B)*5

Haskell (37 35)

Based on Aman's solution:

q a b u=(tan a+tan b)*u*u*cos b^2/5

I think, this problem isn't real code-golf, as it is more implementing a formula than really doing some algorithm.


Python3 - 65 chars

from math import*
f=lambda α,β,u:(tan(α)+tan(β))*u*u*.2*cos(β)**2

Tags:

Math

Code Golf