dmurdoch / rgl

rgl is a 3D visualization system based on OpenGL. It provides a medium to high level interface for use in R, currently modelled on classic R graphics, with extensions to allow for interaction.
https://dmurdoch.github.io/rgl/
GNU General Public License v2.0
85 stars 20 forks source link

`addNormals` warnings #372

Closed stla closed 1 year ago

stla commented 1 year ago

Hello,

I have this mesh (you can read it with Rvcg::vcgPlyRead).

When I do addNormals(mesh), I have some warnings:

1: In acos(dot/veclen(a)/veclen(b)) : NaNs produced
2: In acos(dot/veclen(a)/veclen(b)) : NaNs produced
......

I find it's strange because I don't see what is bad in this mesh.

When I do addNormals(mesh, angleWeighted = FALSE), there's no warning.

There's also an angle weighted method in the Rvcg package (Rvcg::vcgUpdateNormals(mesh, type=1)), it works without errors/warnings.

dmurdoch commented 1 year ago

I think that's caused by rounding error. In the first case, the dot/veclen(a)/veclen(b) value comes out to 1 + 2e-16, and acos gives NaN as the answer. I'll force the values to the range -1 to 1.

Thanks for the report.