Beispiel #1
0
    def locate(self, point):
        r"""Find a point on the current curve.

        Solves for :math:`s` in :math:`B(s) = p`.

        This method acts as a (partial) inverse to :meth:`evaluate`.

        .. note::

           A unique solution is only guaranteed if the current curve has no
           self-intersections. This code assumes, but doesn't check, that
           this is true.

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

        .. doctest:: curve-locate

           >>> nodes = np.asfortranarray([
           ...     [0.0, 0.0],
           ...     [1.0, 2.0],
           ...     [3.0, 1.0],
           ...     [4.0, 0.0],
           ... ])
           >>> curve = bezier.Curve(nodes, degree=3)
           >>> point1 = np.asfortranarray([[3.09375, 0.703125]])
           >>> s = curve.locate(point1)
           >>> s
           0.75
           >>> point2 = np.asfortranarray([[2.0, 0.5]])
           >>> curve.locate(point2) is None
           True

        .. testcleanup:: curve-locate

           import make_images
           make_images.curve_locate(curve, point1, point2)

        Args:
            point (numpy.ndarray): A (``1xD``) point on the curve,
                where :math:`D` is the dimension of the curve.

        Returns:
            Optional[float]: The parameter value (:math:`s`) corresponding
            to ``point`` or :data:`None` if the point is not on
            the ``curve``.

        Raises:
            ValueError: If the dimension of the ``point`` doesn't match the
                dimension of the current curve.
        """
        if point.shape != (1, self._dimension):
            point_dimensions = ' x '.join(
                str(dimension) for dimension in point.shape)
            msg = _LOCATE_ERROR_TEMPLATE.format(self._dimension,
                                                self._dimension, point,
                                                point_dimensions)
            raise ValueError(msg)

        return _curve_helpers.locate_point(self, point)
Beispiel #2
0
    def _call_function_under_test(curve, point):
        from bezier import _curve_helpers

        return _curve_helpers.locate_point(curve, point)