c# - Mathf.Tan giving strange results -


i have 1 problem in finding tan angle in unity3d game.

the code follows

b = mathf.deg2rad * (90.0f - angle); float tan = mathf.tan (b); debug.log ("value of b :  " + b + "  tan of b  :  " + tan); 

here value angle 0.

the problem me when calculate using calculator result of b 1.570796327 correct , value of tan 0.027422438 when calculator in degree mode , **infinity ** in radians mode

the debug log results follows

value of b : 1.570796 tan of b : -2.287733e+07

what problem? please excuse if wrong.

due inaccuracies in floating point numbers, tangent calculated angle on π/2 rad (90 deg), resulting in large negative answer.

if want better account case, should check if b close enough pi/2: if is, tangent undefined. e.g.

// if necessary, account 3pi/2 (270 deg) if (math.abs(b - math.pi / 2) < 0.00001)     // undefined or infinite else     // finite, calculate tangent normal 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -