Esempio n. 1
0
def _make_intersection(edge_info, all_edge_nodes):
    """Convert a description of edges into a curved polygon.

    .. note::

       This is a helper used only by :meth:`.Triangle.intersect`.

    Args:
        edge_info (Tuple[Tuple[int, float, float], ...]): Information
            describing each edge in the curved polygon by indicating which
            triangle / edge on the triangle and then start and end parameters
            along that edge. (See :func:`.ends_to_curve`.)
        all_edge_nodes (Tuple[numpy.ndarray, ...]): The nodes of three edges
            of the first triangle being intersected followed by the nodes of
            the three edges of the second.

    Returns:
        .CurvedPolygon: The intersection corresponding to ``edge_info``.
    """
    edges = []
    for index, start, end in edge_info:
        nodes = all_edge_nodes[index]
        new_nodes = _curve_helpers.specialize_curve(nodes, start, end)
        degree = new_nodes.shape[1] - 1
        edge = _curve_mod.Curve(new_nodes, degree, copy=False, verify=False)
        edges.append(edge)
    return curved_polygon.CurvedPolygon(*edges,
                                        metadata=edge_info,
                                        _verify=False)
Esempio n. 2
0
    def specialize(self, start, end):
        """Specialize the curve to a given sub-interval.

        .. image:: ../../images/curve_specialize.png
           :align: center

        .. doctest:: curve-specialize

           >>> nodes = np.asfortranarray([
           ...     [0.0, 0.5, 1.0],
           ...     [0.0, 1.0, 0.0],
           ... ])
           >>> curve = bezier.Curve(nodes, degree=2)
           >>> new_curve = curve.specialize(-0.25, 0.75)
           >>> new_curve.nodes
           array([[-0.25 ,  0.25 ,  0.75 ],
                  [-0.625,  0.875,  0.375]])

        .. testcleanup:: curve-specialize

           import make_images
           make_images.curve_specialize(curve, new_curve)

        This is generalized version of :meth:`subdivide`, and can even
        match the output of that method:

        .. testsetup:: curve-specialize2

           import numpy as np
           import bezier

           nodes = np.asfortranarray([
               [0.0, 0.5, 1.0],
               [0.0, 1.0, 0.0],
           ])
           curve = bezier.Curve(nodes, degree=2)

        .. doctest:: curve-specialize2

           >>> left, right = curve.subdivide()
           >>> also_left = curve.specialize(0.0, 0.5)
           >>> np.all(also_left.nodes == left.nodes)
           True
           >>> also_right = curve.specialize(0.5, 1.0)
           >>> np.all(also_right.nodes == right.nodes)
           True

        Args:
            start (float): The start point of the interval we
                are specializing to.
            end (float): The end point of the interval we
                are specializing to.

        Returns:
            Curve: The newly-specialized curve.
        """
        new_nodes = _curve_helpers.specialize_curve(self._nodes, start, end)
        return Curve(new_nodes, self._degree, _copy=False)