using System;
using System.Data.Sql;
using System.Data.SqlTypes;
public class CPulley
{
    [SqlFunction]
    public static double PulleyDistance(
		double Pulley1Diameter,
		double Pulley2Diameter,
		double BeltLength)
    {
		double a = 2.0;
		double b = BeltLength - 1.57 * (Pulley1Diameter + Pulley2Diameter);
		double c = System.Math.Pow(Pulley1Diameter - Pulley2Diameter, 2.0);
		double length = (b + Math.Sqrt(Math.Pow(b, 2.0) - (4 * a * c))) / (2 * a);
		return length;
    }

	[SqlFunction]
	public static double BeltLength(
		double Pulley1Diameter, 
		double Pulley2Diameter, 
		double PulleyDistance)
	{
		double length = (2 * PulleyDistance) + 
		(1.57 * (Pulley1Diameter + Pulley2Diameter)) + 
		((System.Math.Pow((Pulley1Diameter - Pulley2Diameter), 2.0) / (4 * PulleyDistance)));
		return length;
	}
};
#if false
class app
{
	static void Main()
	{
		double P1 = 20;
		double P2 = 10;
		double L = 120;
		Console.WriteLine(L);
		double C = CPulley.PulleyDistance(P1, P2, L);
		Console.WriteLine(C);
		Console.WriteLine(CPulley.BeltLength(P1, P2, C));
	}
}

#endif
