I am relatively new to OpenSCAD
, but I have plenty of experience in software development. I have written the following function
:
function GetSlope(angle)=sin(angle)/cos(angle);
When the angle is 90° or 270° the function
will, of course, return inf
due to cos
evaluating to 0, and therefore trying to divide by 0. This is obviously to be expected, but I need to be able to detect this when using the function
. OpenSCAD
contains several type-testing functions, but I could not find an is_inf
function or a constant named inf
to do my own test. Is there a way to test for inf
, or do I need to manually test the value from outside the function
?
You can use 1/0
as the inf
constant you are looking for, it's not very clean but it works. You could also check if cos(angle) == 0
although I don't think that's what you want.
(also you may already know it but sin(angle) / cos(angle) = tan(angle)
)
according to the documentation :
The constants
inf
andnan
are not supported as numeric constants by OpenSCAD, even though you can compute numbers that are printed this way by 'echo'. You can define variables with these values by using:inf = 1e200 * 1e200; nan = 0 / 0; echo(inf,nan);