Search code examples
geometrytrigonometryopenscad

OpenSCAD sin() returns wrong result


Trying to create a function which creates a vertex involving some sin and cos usage.

I'm noticing a discrepancy between what OpenSCAD returns and what the Google calculator returns. Eg:

OpenSCAD:

echo(sin(9)); // 0.156434
echo(cos(9)); // 0.987688

Whereas with Google:

sin(9) = 0.41211848524
cos(9) = -0.91113026188

I'm sure I'm missing something, but why is there a difference between the two results?


Solution

  • Google's doing it in radians - OpenSCAD is doing it in degrees

    Your code returns the right answer if your input is 9 degrees, rather than radians

    sin(9 degrees) = 0.15643446504
    sin(9 radians) = 0.41211848524
    

    For information, a radian is a unit for measuring angles, like the degree, but it is equal to about 57.3 degrees