local D=120 function computeLaunchAngle(K,n,b)local Z=math.abs(b)local k=((D*D)*D)*D-Z*((Z*K)*K+((2*n)*D)*D)if k<=0 then return.25*math.pi end local f=math.sqrt(k)local R=(D*D+f)/(Z*K)local W=(D*D-f)/(Z*K)local g=math.atan(R)local h=math.atan(W)if g<h then return g end return h end


local Velocity = 120
function computeLaunchAngle(dx, dy, grav)	
	-- This function is nasty or what? :P 
	-- There are ways to solve launch angle of a projectile given a point in 3D space 
	-- This one solves for tan(theta) 
		
	-- Simplify the distance formula of a projectile 
	local g = math.abs(grav)
	local inRoot = (Velocity * Velocity * Velocity * Velocity) - (g * ((g * dx * dx) + (2 * dy * Velocity * Velocity)))
	if inRoot <= 0 then
		return 0.25 * math.pi
	end
	local root = math.sqrt(inRoot)
	local inATan1 = ((Velocity * Velocity) + root) / (g*dx)

	local inATan2 = ((Velocity * Velocity) - root) / (g*dx)
	local a1 = math.atan(inATan1)
	local a2 = math.atan(inATan2)
	if a1 < a2 then return a1 end
	return a2
end
