pyvista / pyvista-support

[moved] Please head over to the Discussions tab of the PyVista repository
https://github.com/pyvista/pyvista/discussions
59 stars 4 forks source link

Understanding, plotting, and flipping 2D cell normals #507

Closed WadeRobertEvans closed 3 years ago

WadeRobertEvans commented 3 years ago

Hello,

I have imported point cloud data (xyz coordinates) and performed triangulation using delaunay 2d to get a mesh of triangular faces / elements. pdata = pv.PolyData(xyz_points) surf = pdata.delaunay_2d().clean()

I extracted the cell center points using: centers = surf.cell_centers() center_pts = centers.points

I computed the normals using: surf_with_norms = surf.compute_normals(cell_normals=True,point_normals=False)

I plot the normals using: pl = pv.Plotter() pl.add_mesh(surf_with_norms, show_edges=True, line_width=1) pl.add_axes() pl.background_color='w' pl.add_arrows(center_pts,surf_with_norms['Normals'],mag=20,color='red') pl.add_mesh(centers, color="g", point_size=10.0, render_points_as_spheres=True) pl.show()

Basically, I got arrays for the cell center points and the cell normals. I used the cell center points array for the tail of the "normals arrow", and the cell normals array as the head of the "normals arrow" (refer to pl.add_arrows(center_pts,surf_with_norms['Normals'],mag=20,color='red')).

Is this a correct method to plot the cell normals? I'm unsure of what "compute_normals" outputs, is it the head of the normal and is the tail of the normal supposed to be the cell center point?

For the cell normals array, I would've expected two coordinate points per cell normal (one for the tail and one for the head), but this doesn't seem to be the case when inspecting the array... There are the same number of cells as there are normals, both with only three columns (i.e. they have the same shape).

Below is a snippet of a plot showing the face centers and face normals.

image

I will also need to flip the face normals. Using surf_with_norms.flip_normals() doesn't seem to work. Does this only flip the point normals?

In the end, I need the normals data to compare the data to that of ideal geometry (i.e. find the difference between the normals of the manufactured part to the normals of the ideal part).

Please assist!

WadeRobertEvans commented 3 years ago

Closed this issue as I duplicated it in the discussions forum.