def Arrow(start=(0.,0.,0.), direction=(1.,0.,0.), tip_length=0.25, tip_radius=0.1, tip_resolution=20, shaft_radius=0.05, shaft_resolution=20, scale=None): """Create a vtk Arrow. Parameters ---------- start : np.ndarray Start location in [x, y, z] direction : list or tuple or np.ndarray Direction the arrow points to in [x, y, z] tip_length : float, optional Length of the tip. tip_radius : float, optional Radius of the tip. tip_resolution : int, optional Number of faces around the tip. shaft_radius : float, optional Radius of the shaft. shaft_resolution : int, optional Number of faces around the shaft. scale : float or str, optional Scale factor of the entire object, default is None (i.e. scale of 1). 'auto' scales to length of direction array. Returns ------- arrow : pyvista.PolyData Arrow surface. """ # Create arrow object arrow = _vtk.vtkArrowSource() arrow.SetTipLength(tip_length) arrow.SetTipRadius(tip_radius) arrow.SetTipResolution(tip_resolution) arrow.SetShaftRadius(shaft_radius) arrow.SetShaftResolution(shaft_resolution) arrow.Update() surf = pyvista.PolyData(arrow.GetOutput()) if scale == 'auto': scale = float(np.linalg.norm(direction)) if isinstance(scale, float) or isinstance(scale, int): surf.points *= scale elif scale is not None: raise TypeError("Scale must be either float, int or 'auto'.") translate(surf, start, direction) return surf
def Arrow(start=(0., 0., 0.), direction=(1., 0., 0.), tip_length=0.25, tip_radius=0.1, tip_resolution=20, shaft_radius=0.05, shaft_resolution=20, scale=None): """Create an arrow. Parameters ---------- start : iterable, optional Start location in ``[x, y, z]``. direction : iterable, optional Direction the arrow points to in ``[x, y, z]``. tip_length : float, optional Length of the tip. tip_radius : float, optional Radius of the tip. tip_resolution : int, optional Number of faces around the tip. shaft_radius : float, optional Radius of the shaft. shaft_resolution : int, optional Number of faces around the shaft. scale : float or str, optional Scale factor of the entire object, default is ``None`` (i.e. scale of 1). ``'auto'`` scales to length of direction array. Returns ------- pyvista.PolyData Arrow mesh. Examples -------- Plot a default arrow. >>> import pyvista >>> mesh = pyvista.Arrow() >>> mesh.plot(show_edges=True) """ # Create arrow object arrow = _vtk.vtkArrowSource() arrow.SetTipLength(tip_length) arrow.SetTipRadius(tip_radius) arrow.SetTipResolution(tip_resolution) arrow.SetShaftRadius(shaft_radius) arrow.SetShaftResolution(shaft_resolution) arrow.Update() surf = pyvista.wrap(arrow.GetOutput()) if scale == 'auto': scale = float(np.linalg.norm(direction)) if isinstance(scale, float) or isinstance(scale, int): surf.points *= scale elif scale is not None: raise TypeError("Scale must be either float, int or 'auto'.") translate(surf, start, direction) return surf