Esempio n. 1
0
def quiver(point,
           gradient,
           length=None,
           length_scale=1.,
           width_scale=1.,
           color=None,
           opacity=None,
           fig="gcf",
           label=None):
    """Create arrow(s) from 'point' towards a direction given by 'gradient' to
    make field/quiver plots. Arrow lengths by default are the magnitude of
    'gradient but can be scaled with 'length_scale' or frozen with 'length'.
    See arrow's docs for more detail.

    :param point: The starting point of the arrow(s).
    :type point: np.ndarray

    :param gradient: The displacement / gradient vector.
    :type gradient: np.ndarray

    :param length: A frozen length for each arrow, defaults to None.
    :type length: NoneType, optional

    :param length_scale: A scaling factor for the length of each arrow, defaults to 1.0.
    :type length_scale: int, optional

    :param width_scale: How fat to make each arrow, is relative to its length, defaults to 1.0.
    :type width_scale: int, optional

    :param color: The color of each arrow, defaults to white.
    :type color: str, 3-tuple, 4-tuple, np.ndarray of shape (n, 3)

    :param opacity: The translucency of the plot, from `0` invisible to `1` solid, defaults to `1`.
    :type opacity: float

    :param fig: The figure to plot into, can be None, defaults to :meth:`vtkplotlib.gcf`.
    :type fig: :class:`vtkplotlib.figure`, :class:`vtkplotlib.QtFigure`, optional

    :param label: Give the plot a label to use in legends, defaults to None.
    :type label: str, optional

    :return: arrow or array of arrows
    :rtype: vtkplotlib.plots.Arrow.Arrow, np.array of Arrows

    .. seealso:: ``vpl.arrow`` to draw arrows from a start point to an end point.

    """

    if length is None:
        length = geom.distance(gradient)
    if length_scale != 1:
        length *= length_scale

    return arrow(point, point + gradient, length, width_scale, color, opacity,
                 fig, label)
Esempio n. 2
0
def quiver(point,
           gradient,
           length=None,
           length_scale=1.,
           width_scale=1.,
           color=None,
           opacity=None,
           fig="gcf"):
    """Create an arrow from 'point' towards a direction given by 'gradient'.
    This is intended to make field/quiver plots. Arrow lengths by default are
    the magnitude of 'gradient but can be scaled with 'length_scale' or
    frozen with 'length'. See arrow's docs for more detail.

    :param point: The starting point of the arrow(s).
    :type point: np.ndarray

    :param gradient: The displacement / gradient vector.
    :type gradient: np.ndarray

    :param length: A frozen length for each arrow, defaults to None.
    :type length: NoneType, optional

    :param length_scale: A scaling factor for the length of each arrow, defaults to 1.0.
    :type length_scale: int, optional

    :param width_scale: How fat to make each arrow, is relative to its length, defaults to 1.0.
    :type width_scale: int, optional

    :param color: The color of each arrow, defaults to white.
    :type color: str, 3-tuple, 4-tuple, np.ndarray of shape(n, 3)

    :param opacity: The translucency of each arrow, 0 is invisible, 1 is solid, defaults to solid.
    :type opacity: float

    :param fig: The figure to plot into, can be None, defaults to vpl.gcf().
    :type fig: vpl.figure, vpl.QtFigure


    :return: arrow or array of arrows
    :rtype: vtkplotlib.plots.Arrow.Arrow, np.array of Arrows

    """

    if length is None:
        length = geom.distance(gradient)
    if length_scale != 1:
        length *= length_scale

    return arrow(point, point + gradient, length, width_scale, color, opacity,
                 fig)
Esempio n. 3
0
    def __init__(self,
                 start,
                 end,
                 length=None,
                 width_scale=1,
                 color=None,
                 opacity=None,
                 fig="gcf",
                 label=None):
        super().__init__(fig)

        diff = end - start
        if length is None:
            length = geom.distance(diff)

        # vtk needs a full set of axes to build about.
        # eX is just the direction the arrow is pointing in.
        # eY and eZ must be perpendicular to each other and eX. However beyond
        # that exact choice of eY and eZ does not matter. It only rotates the
        # arrow about eX which you can't see because it's (approximately) round.
        eX, eY, eZ = geom.orthogonal_bases(diff)
        arrowSource = vtk.vtkArrowSource()

        # This next bit puts the arrow where it's supposed to go
        matrix = vtk.vtkMatrix4x4()

        # Create the direction cosine matrix
        matrix.Identity()
        for i in range(3):
            matrix.SetElement(i, 0, eX[i])
            matrix.SetElement(i, 1, eY[i])
            matrix.SetElement(i, 2, eZ[i])

        # Apply the transforms
        transform = vtk.vtkTransform()
        transform.Translate(start)
        transform.Concatenate(matrix)
        transform.Scale(length, length * width_scale, length * width_scale)

        self.source = arrowSource

        self.connect()
        self.actor.SetUserMatrix(transform.GetMatrix())

        self.color_opacity(color, opacity)
        self.label = label