Hi Dženan,

"Dženan Zukić" writes:

> 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?

Did you try

vec1.normalize();
vec2.normalize();

acos(vec1 * vec2);

?

-- 
Alberto

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

Reply via email to