I would like to create a Surface or Mesh from a cloud of points that are at the contour of the object to be meshed.
What I have is a set of points with x and y for each z, similar to a topographic map, however the x and y are not unique like in those type of maps.
I think it will be easier with an example and an image:
Imagine you have a set of point like above.
How could I plot the shape of that cloud instead of the points?
I am open to any other 3D representation or approach in order to represent it in a cleaner way.
The points in the image are from two spheres: the shown points are the countor of one sphere and the intersection of the second one contour inside the first sphere. Use the following code to generate it:
import numpy as np
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
def equation(x, y, z):
a1 = 0; b1 = 0; c1 = 0; r1 = 5
sphere1_inside = (x - a1) ** 2 + (y - b1) ** 2 + (z - c1) ** 2 <= r1 ** 2
sphere1_inperimeter = abs(r1 ** 2 - ((x - a1) ** 2 + (y - b1) ** 2 + (z - c1) ** 2 )) < 0.05
a2 = 1; b2 = 1; c2 = -1; r2 = 4
sphere2_inside = (x - a2) ** 2 + (y - b2) ** 2 + (z - c2) ** 2 <= r2 ** 2
sphere2_inperimeter = abs(r2 ** 2 - ((x - a2) ** 2 + (y - b2) ** 2 + (z - c2) ** 2 )) < 0.05
return (sphere1_inperimeter and not sphere2_inside) or (sphere1_inside and sphere2_inperimeter)
data = {
'x': [],
'y': [],
'z': [],
'size': []
}
for z in np.linspace(-5, 5, num=20):
for y in np.linspace(-5, 5, num=200):
for x in np.linspace(-5, 5, num=200):
if(equation(x, y, z)):
data['x'].append(x)
data['y'].append(y)
data['z'].append(z)
data['size'].append(5)
df = pd.DataFrame(data)
fig = px.scatter_3d(df,
x='x',
y='y',
z='z',
size='size',
size_max=df['size'].max(),
title='plotly',
opacity=0.8,
color_continuous_scale='viridis',
)
fig.show()