コード例 #1
0
    def area(self):
        r"""The area of the current curved polygon.

        This assumes, but does not check, that the current curved polygon
        is valid (i.e. it is bounded by the edges).

        This computes the area via Green's theorem. Using the vector field
        :math:`\mathbf{F} = \left[-y, x\right]^T`, since
        :math:`\partial_x(x) - \partial_y(-y) = 2` Green's theorem says

        .. math::

           \int_{\mathcal{P}} 2 \, d\textbf{x} =
           \int_{\partial \mathcal{P}} -y \, dx + x \, dy

        (where :math:`\mathcal{P}` is the current curved polygon).

        Note that for a given edge :math:`C(r)` with control points
        :math:`x_j, y_j`, the integral can be simplified:

        .. math::

            \int_C -y \, dx + x \, dy = \int_0^1 (x y' - y x') \, dr
                = \sum_{i < j} (x_i y_j - y_i x_j) \int_0^1 b_{i, d}
                b'_{j, d} \, dr

        where :math:`b_{i, d}, b_{j, d}` are Bernstein basis polynomials.

        Returns:
            float: The area of the current curved polygon.
        """
        edges = tuple(edge._nodes for edge in self._edges)
        return _triangle_helpers.compute_area(edges)
コード例 #2
0
ファイル: triangle.py プロジェクト: dhermes/bezier
    def area(self):
        r"""The area of the current triangle.

        For triangles in :math:`\mathbf{R}^2`, this computes the area via
        Green's theorem. Using the vector field :math:`\mathbf{F} =
        \left[-y, x\right]^T`, since :math:`\partial_x(x) - \partial_y(-y) = 2`
        Green's theorem says twice the area is equal to

        .. math::

           \int_{B\left(\mathcal{U}\right)} 2 \, d\mathbf{x} =
           \int_{\partial B\left(\mathcal{U}\right)} -y \, dx + x \, dy.

        This relies on the assumption that the current triangle is valid, which
        implies that the image of the unit triangle under the B |eacute| zier
        map --- :math:`B\left(\mathcal{U}\right)`  --- has the edges of the
        triangle as its boundary.

        Note that for a given edge :math:`C(r)` with control points
        :math:`x_j, y_j`, the integral can be simplified:

        .. math::

            \int_C -y \, dx + x \, dy = \int_0^1 (x y' - y x') \, dr
                = \sum_{i < j} (x_i y_j - y_i x_j) \int_0^1 b_{i, d}
                b'_{j, d} \, dr

        where :math:`b_{i, d}, b_{j, d}` are Bernstein basis polynomials.

        Returns:
            float: The area of the current triangle.

        Raises:
            NotImplementedError: If the current triangle isn't in
                :math:`\mathbf{R}^2`.
        """
        if self._dimension != 2:
            raise NotImplementedError(
                "2D is the only supported dimension",
                "Current dimension",
                self._dimension,
            )

        edge1, edge2, edge3 = self._get_edges()
        return _triangle_helpers.compute_area(
            (edge1._nodes, edge2._nodes, edge3._nodes)
        )