Hi,

The following code occasionally leaves p with NaN value:
[code]double cosFi=vec1*vec2/(vec1.length()*vec2.length());
//cosine of angle between vectors
p+=acos(cosFi)*...;[/code]
Due to numerical round-off errors it would rarely occur that cosFi>1 (something 
like 1.00000002534), and acos would produce NaN, which would then propagate 
further, causing a crash far away in the code.

I have solved it like this:
[code]if (cosFi>1)
        cosFi=1;
else if (cosFi<-1)
        cosFi=-1;[/code]
How common is this type of error and what is the usual way of dealing with it?

Thank you!

Cheers,
Dženan

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29431#29431





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to