I have also wrote a sqrt function, its accurate to 6 decimals:
To increase the accuracy write a bigger number in 'for' cycle.PHP Code:
sqrt( b )
{
a = 0;
for ( i = 1; i <= 1000000; i *= 10 )
{
while ( a * a <= b )
a += (1 / i);
if ( a * a > b )
a -= (1 / i);
}
return a;
}
And an other mathematical function:
PHP Code:
vectorCross(vec1, vec2)
{
result =
(vec1[1]*vec2[2] - vec2[1]*vec1[2]) -
(vec1[0]*vec2[2] - vec2[0]*vec1[2]) +
(vec1[0]*vec2[1] - vec2[0]*vec1[1]);
return result;
}