Plotly: visual artefact when rendering a 3D mesh ellipsoid

Viewed 114

With the following code:


import numpy as np

from plotly.offline import iplot, init_notebook_mode

import plotly.graph_objects as go
from numpy import sin, cos, pi

a = 6378.137  # centre-equator axis
c = 6357  # centre-north pole axis

phi = np.linspace(0, 2*pi)
theta = np.linspace(-pi/2, pi/2)
phi, theta = np.meshgrid(phi, theta)

x = a * cos(theta) * sin(phi)
y = a * cos(theta) * cos(phi)
z = c * sin(theta)

init_notebook_mode()

mesh = go.Mesh3d(
    {
        'x': x.flatten(), 
        'y': y.flatten(), 
        'z': z.flatten(), 
        'alphahull': 0.8,
    }
)


layout = go.Layout(
    scene=dict(aspectmode='data')
)

figure = go.Figure(data=[mesh], layout=layout)

iplot(figure)


I'm getting the ellipsoid that I wanted. Only there is an artefact in the 0 meridian, as you can see in the figure:

enter image description here

Any idea how to remove the extra line?

---- EDIT: after the Bounty

After a few minutes of attempts, and trying out the solution proposed by Dice have not solved the issue:

import numpy as np

import plotly.offline as pyo
import plotly.graph_objs as go

a = 6378.137  # centre-equator axis
c = 6357  # centre-north pole axis

phi = np.linspace(0, 2*np.pi, endpoint=False)
theta = np.linspace(-np.pi/2, np.pi/2, endpoint=False)
phi, theta = np.meshgrid(phi, theta)

x = a * np.cos(theta) * np.sin(phi)
y = a * np.cos(theta) * np.cos(phi)
z = c * np.sin(theta)


fig = go.Figure(
    data=[
        go.Mesh3d(
            x=x.flatten(),
            y=y.flatten(),
            z=z.flatten(),
            opacity=0.5,
        )
    ]
)


fig.show()

Showed:

more artefacts

Which are more artefacts than before. Though, with the current plotly version and python 3.9 these are the artefacts I have anyway, even without the endpoint=False.

Requirements (python 3.9.9):

numpy==1.22.0
plotly==5.5.0

The question remains open!

1 Answers

This seems to be caused by the mesh overlapping on the endpoints, removing the endpoints from phi and theta solved this.

phi = np.linspace(0, 2*pi, endpoint=False)
theta = np.linspace(-pi/2, pi/2, endpoint=False)

Changing this bit should do the trick.

Related