K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
921 stars 123 forks source link

Fix coordinates order for implicit isosurface #344

Closed Davide-sd closed 2 years ago

Davide-sd commented 2 years ago

Issue #340 showed that K3D-Jupyter isosurfaces are incorrectly visualized on the screen, in comparison to Plotly and Sage math.

This commit swaps the order of the x and z coordinates, thanks to which the visualization appears correct.

This edit has been visually tested with the examples found at: https://doc.sagemath.org/html/en/reference/plot3d/sage/plot/plot3d/implicit_plot3d.html

K3D-Jupyter now plots isosurfaces with the correct orientation: the comparison was done against both Plotly and Sage math.

Davide-sd commented 2 years ago

How do I create new test images? I tried using Jupyter, but the aspect ratio of the image is clearly different than the reference images.

marcinofulus commented 2 years ago

Davide, it is actually indented, note that in matrix stored in row-major, the second index is the fast one and denotes columns (changing j you move left right), but while when plotting f(x,y) it is opposite- second argument is slow and changing y you move down-up. Going to 3d you can generalize to xyz <-> kji

Practically you do: z,y,x = np.meshgrid(z,y,x,indexing='ij') (or mgrid)

In Sage there x,y,z are not samples indexaraych so you cannot compare it. In plotly example they used ijk <-> xyz

Davide-sd commented 2 years ago

Davide, it is actually indented,

Ok, I think I understand. So this PR can be closed.

I'm probably going to open a new PR to modify this example and make clear this design choice! Thank you! :)