sdf icon indicating copy to clipboard operation
sdf copied to clipboard

Isolines in `show_slice`

Open dvd101x opened this issue 10 months ago • 0 comments

Hi,

This is not an issue, just a proposal to include isolines as other 2D representations of SDF.

Change this Image

To something like this

Image

The change in code is not that much, this is an example.

def show_slice(*args, **kwargs):
    import matplotlib.pyplot as plt
    from matplotlib.colors import TwoSlopeNorm
    a, extent, axes = sample_slice(*args, **kwargs)
    norm = TwoSlopeNorm(vmin=a.min(), vcenter=0, vmax=a.max())
    im = plt.imshow(a, extent=extent, origin='lower', cmap="PRGn", norm=norm)
    plt.contour(a, colors='white', alpha=0.5, extent=extent)  # Add semi-transparent isolines
    plt.contour(a, levels=[0], colors='black', extent=extent)  # Add isoline at 0
    plt.xlabel(axes[0])
    plt.ylabel(axes[1])
    plt.colorbar(im)
    plt.show()

The idea is to use a diverging color map centered at 0, add isonlines shown in white and add a single isoline shown in black representing the boundary of the solid.

dvd101x avatar Apr 17 '25 22:04 dvd101x