Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how do i can put a point inside a 3d mesh #443

Open
alialzobani opened this issue Jun 14, 2021 · 1 comment
Open

how do i can put a point inside a 3d mesh #443

alialzobani opened this issue Jun 14, 2021 · 1 comment

Comments

@alialzobani
Copy link

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

class Picker:
def init(self, plotter, mesh):
self.plotter = plotter
self.mesh = mesh
self._points = []

@property
def points(self):
    """To access all th points when done."""
    return self._points

def __call__(self, *args):
    picked_pt = np.array(self.plotter.pick_mouse_position())

    #picked_pt[2]=0
    print(picked_pt)

    direction = picked_pt - self.plotter.camera_position[0]
    direction = direction / np.linalg.norm(direction)
    start = picked_pt - 1000 * direction
    end = picked_pt + 10000 * direction
    point, ix = self.mesh.ray_trace(start, end, first_point=True)

    if len(point) > 0:
        self._points.append(point)
        w = p.add_mesh(pv.Sphere(radius=3.0 , center=picked_pt),
                       color='red')
    return

mesh = examples.load_airplane()

p = pv.Plotter(notebook=False)
p.add_mesh(mesh, show_edges=True, color='w')

picker = Picker(p, mesh)
p.track_click_position(picker, side='right')
p.add_text('Use right mouse click to pick points')
p.show_axes()

p.show()

@alialzobani
Copy link
Author

i can using this code to put points on the outside of the mesh, put i want to put points inside the mesh too.
thanks for our helpe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant