pyvista icon indicating copy to clipboard operation
pyvista copied to clipboard

Parallel projection spoils plot

Open fmamitrotta opened this issue 9 months ago • 0 comments

Describe the bug, what's wrong, and what you expected.

I'm plotting the internal structure of an idealized wingbox, made by ribs and stiffeners. The former are made by Plane objects parallel to the xz plane, the latter are made by Plane objects parallel to the yz plane.

When I plot the merged PolyData object I obtain the following image. image

This representation is correct, as the bottom stiffeners (the longitudinal elements running through the ribs) are not visible behind the ribs.

However, if I enable parallel projection, I obtain the following plot. image

As you can see now the bottom stiffeners appear to permeate the ribs, which is wrong.

Why does this happen? The stiffeners should always "stop" at each rib and be invisible for the portion that's behind each rib.

Steps to reproduce the bug.

import numpy as np
import pyvista

l = 29.38e3  # [mm] box beam length
w = 3.41e3  # [mm] box beam width
h = 0.77e3  # [mm] box beam height
stiffeners_height = h/10  # [mm] stiffeners height
no_stiffeners = 2  # number of stiffeners
stiffeners_x_locations = np.linspace(0, w, no_stiffeners + 2)[1:-1]  # [mm] stiffeners x-coordinates
stiffeners_spacing = w/(no_stiffeners + 1)  # [mm] stiffeners spacing
ribs_spacing = stiffeners_spacing*1.4 # [mm] ribs spacing
no_ribs = round(l/ribs_spacing) + 1  # number of ribs
ribs_y_locations = np.linspace(0, l, no_ribs)  # [mm] ribs y-coordinates

# Set transparent background
pyvista.global_theme.transparent_background = True

# Initialize lists of the PolyData objects corresponding to the stiffeners
top_stiffeners = []
bottom_stiffeners = []
# Iterate through the x-coordinates of the stiffeners, except last one
for count, x in enumerate(stiffeners_x_locations):
    # Discretize top stiffener
    top_stiffeners.append(pyvista.Plane(center=[x, l/2, h/2 - stiffeners_height/2], direction=[1, 0, 0], i_size=stiffeners_height, j_size=l,
                                        i_resolution=1, j_resolution=1))
    # Discretize bottom stiffener
    bottom_stiffeners.append(pyvista.Plane(center=[x, l/2, -h/2 + stiffeners_height/2], direction=[1, 0, 0], i_size=stiffeners_height,
                                           j_size=l, i_resolution=1, j_resolution=1))
    
# Initialize lists of the PolyData objects corresponding to the box segments and to the ribs
ribs = []
rib_segments_x_coordinates = np.concatenate(([0.], stiffeners_x_locations, [w]))  # create array of the x-coordiantes defining the rib segments
rib_segments_widths = np.ediff1d(rib_segments_x_coordinates)  # calculate the width of each rib segment
# Iterate through the y-coordinates of the rib, except last one
for y in ribs_y_locations:
    # Discretize current rib and add PolyData object to the list
    ribs = ribs + [pyvista.Plane(center=[w/2, y, 0], direction=[0, 1, 0], i_size=h, j_size=w, i_resolution=1, j_resolution=1)]

# Merge all box segments and ribs together
merged_parts = bottom_stiffeners[0].merge(bottom_stiffeners[1:] + top_stiffeners + ribs)
pl = pyvista.Plotter(notebook=True, window_size=[4000, 4000])
pl.add_mesh(merged_parts, show_edges=True, line_width=5)
pl.camera.azimuth = 80
pl.enable_parallel_projection()  # comment or uncomment to obtain the different results
pl.screenshot("InternalGeometry.png")
pl.show(jupyter_backend='static')

System Information

--------------------------------------------------------------------------------
  Date: Wed May 15 21:55:25 2024 GMT Summer Time

                OS : Windows
            CPU(s) : 12
           Machine : AMD64
      Architecture : 64bit
               RAM : 63.8 GiB
       Environment : Jupyter
        GPU Vendor : NVIDIA Corporation
      GPU Renderer : NVIDIA GeForce GT 1030/PCIe/SSE2
       GPU Version : 4.5.0 NVIDIA 536.23
  MathText Support : False

  Python 3.9.17 (main, Jul  5 2023, 20:47:11) [MSC v.1916 64 bit (AMD64)]

           pyvista : 0.43.3
               vtk : 9.0.3
             numpy : 1.23.5
        matplotlib : 3.7.1
            scooby : 0.7.1
             pooch : Trouble importing
            pillow : 9.4.0
           imageio : 2.26.0
         pyvistaqt : 0.9.1
             PyQt5 : 5.15.7
           IPython : 8.10.0
        ipywidgets : 8.0.4
             scipy : 1.10.0
      nest_asyncio : 1.5.6

  Intel(R) oneAPI Math Kernel Library Version 2021.4-Product Build 20210904
  for Intel(R) 64 architecture applications
--------------------------------------------------------------------------------

Screenshots

No response

fmamitrotta avatar May 15 '24 20:05 fmamitrotta