Extracting triangles from Mesh3d figure

Hi @mathguy350,

Welcome to forum!
Using this Mesh3d version you cannot extract the triangle vertex coordinates.
In order to get them, project the points of coordinates (x,y,z) onto a 2d plane of equation z=cst. Then triangulate the resulting 2d points, using scipy.spatial.Delaunay, and lift the planar triangulation, back to 3d.
From the 3d points and triangulation faces you can get the coordinates of each triangle vertices.
Example:

from scipy.spatial import Delaunay
import numpy as np
import plotly.graph_objects as go

pts3d = np.vstack((x, y, z)).T
pts2d = pts3d[:, :2]
tri =   Delaunay(pts2d)
i, j, k = tri.simplices.T  #tri.simplices (faces) is an array of integers of shape (no_triangles, 3)
fig = go.Figure(go.Mesh3d(x=x, y=y, z=z,
                          i=i, j=j, k=k, intensity=z, 
                          colorscale='matter_r', 
                          flatshading=True))

The coordinates of triangle vertices are then computed as follows:

tri_coords = pts3d[tri.simplices]

tri_coords[m] (m =0, 1, … number of triangles-1) is an array of shape (3,3)_. Each row contains the coordinates of a triangle vertex.

1 Like