cihologramas / pyoptools

Python tools for optical design
GNU General Public License v3.0
137 stars 46 forks source link

3D surfaces not rotated correctly #130

Open rdgraham opened 1 year ago

rdgraham commented 1 year ago

In a new build, rotations are not being applied correctly to 3d surfaces in the Plot3d py3js output.

The underlying simulation seems to be correct, but the surfaces of components are not rotated correctly. In the example below (taken from the tutorial), the cylindrical sides of the lens are rotated about the wrong axis.

This was discussed in the comments of pull request https://github.com/cihologramas/pyoptools/pull/127 Initially this was suspected to be related to the windows build, but actually seems to happen in linux also on a new install, using python 3.10, pythreejs 2.4.1.

image

rdgraham commented 1 year ago

I have since found a solution, although I don't fully understand it.

It seems I can get it to work normally if change the code for applying rotations to the surfaces and components in ipywidgets.py, from directly applying the rotation via the attribute to calling the three individual rotation methods. I.e.

c.rotation = *D, "ZYX"
c.position = tuple(P)

to

c.position = tuple(P)
c.rotateZ(D[2])
c.rotateY(D[1])
c.rotateX(D[0])

although I couldn't see any notice or reason for this change in threejs.

Another thing that may or may not be related -- when testing in firefox I noticed that there is now an issue with the centering of the field of view. It is no longer centered on the center of rotation of the camera, so often it is not possible to see the whole model. However, this seemed to be firefox specific, and when I tried in chrome that problem does not occur.

In any case, I will go ahead and make a pull request for this small fix. Would be good to understand what is going on though.

ramezquitao commented 1 year ago

There is something weird going on here. In my case, this is working when opening a notebook in jupyterlab, but there are problems with the rotaions when the documentation is generated.

ramezquitao commented 1 year ago

@rdgraham do you use jupyter notebook or jupyter lab? . I'm not being able to make pythreejs work in Juyter notebook, but in Jupyter lab is working fine.

rdgraham commented 1 year ago

I am using jupyter lab.

I just tried with the legacy jupyter notebook. I am seeing an issue with threejs:

image

Is this the issue you are seeing, or something else?

In my case, it seems like some issue with my installation, not related to the surface rotation issue. In any case, I don't have much need to debug it since I don't have a reason to use jupyter notebook, which seems to be being deprecated.

I am not familiar with the documentation generation. If you could post the current procedure I could try to replicate the issue.

ramezquitao commented 1 year ago

Yes, that is exactly the issue. About the documentation, it is all located in the doc folder, and sphinx is being used. Also a sphinx extension called nbsphinx that allow to include Jupyter notebooks in the documentation, is being used. I'dont know the internals of nbsphinx, but it requires ipykernel to work so this is why I was trying to use the jupyter notebook to check how the documentation notebooks look there (because in Jupyter lab they look ok).

To generate a local copy of the documentation, you need to run make html inside the doc folder. The requirements.txt inside the doc folder is the one used by read the docs to generate the correct environment. If you have problems generating the documentation, you can check the branch docs of my personal pyoptools repository (https://github.com/ramezquitao/pyoptools/tree/docs), this one seems to be working.