GithubHelp home page GithubHelp logo

Comments (1)

banesullivan avatar banesullivan commented on June 16, 2024 1

The surface from the .slice filter can be oriented in any direction and centered at any location!

EDIT: I've made a number of edits to this because I messed it up the first time 🤦‍♂

Here's an example of how to get many slices at different bearings all centered around a user-chosen location:

import pyvista as pv
from pyvista import examples
import numpy as np

# Load RectilinearGrid of geo-data
mesh = examples.load_channels()

# Create a point to orient slices around
ranges = np.array(mesh.bounds).reshape(-1, 2).ptp(axis=1)
point = np.array(mesh.center) - ranges*0.25

# now generate a few normal vectors to rotate a slice around the z-axis
# use equation for circle since its about the Z-axis
increment = np.pi/6.
# use a container to hold all the slices
slices = pv.MultiBlock() # treat like a dictionary/list
for theta in np.arange(0, np.pi, increment):
    normal = np.array([np.cos(theta), np.sin(theta), 0.0]).dot(np.pi/2.)
    name = 'Bearing: {:.2f}'.format(np.rad2deg(theta))
    slices[name] = mesh.slice(origin=point, normal=normal)
slices
InformationBlocks
MultiBlockValues
N Blocks6
X Bounds0.000, 250.000
Y Bounds0.000, 250.000
Z Bounds0.000, 100.000
IndexNameType
0Bearing: 0.00PolyData
1Bearing: 30.00PolyData
2Bearing: 60.00PolyData
3Bearing: 90.00PolyData
4Bearing: 120.00PolyData
5Bearing: 150.00PolyData
# and now display it!
p = pv.Plotter()
p.add_mesh(slices, cmap='rainbow', n_colors=4,)
p.add_mesh(mesh.outline())
p.show()

download

from pyvista-support.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.