How to use the dmsh.geometry.pypathlib.helpers.shoelace function in dmsh

To help you get started, we’ve selected a few dmsh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / dmsh / dmsh / geometry / pypathlib / closed_path.py View on Github external
def is_convex_node(self):
        points = self.points[:-1]
        if self._is_convex_node is None:
            tri = numpy.array(
                [numpy.roll(points, +1, axis=0), points, numpy.roll(points, -1, axis=0)]
            )
            self._is_convex_node = numpy.equal(
                shoelace(tri) >= 0, self.positive_orientation
            )
        return self._is_convex_node
github nschloe / dmsh / dmsh / geometry / pypathlib / closed_path.py View on Github external
pts0 = self.points
        pts1 = numpy.roll(self.points, -1, axis=0)

        # If the point is closest to a polygon edge, check which which side of the edge
        # it is on.
        is_closest_to_side = (0.0 < t[r, idx]) & (t[r, idx] < 1.0)
        tri = numpy.array(
            [
                x[is_closest_to_side],
                pts0[idx[is_closest_to_side]],
                pts1[idx[is_closest_to_side]],
            ]
        )

        contains_points[is_closest_to_side] = (
            shoelace(tri) > 0.0
        ) == self.positive_orientation

        # If the point is closest to a polygon node, check if the node is convex or
        # concave.
        is_closest_to_pt0 = t[r, idx] <= 0.0
        contains_points[is_closest_to_pt0] = ~self.is_convex_node[
            idx[is_closest_to_pt0]
        ]

        is_closest_to_pt1 = 1.0 <= t[r, idx]
        n = self.points.shape[0] - 1
        contains_points[is_closest_to_pt1] = ~self.is_convex_node[
            (idx[is_closest_to_pt1] + 1) % n
        ]

        return contains_points
github nschloe / dmsh / dmsh / geometry / pypathlib / closed_path.py View on Github external
def __init__(self, points):
        closed_points = numpy.concatenate([points, [points[0]]])
        super().__init__(closed_points)

        assert self.points.shape[0] > 2
        assert self.points.shape[1] == 2

        self.area = 0.5 * shoelace(self.points)
        self.positive_orientation = self.area >= 0
        if self.area < 0:
            self.area = -self.area

        self._is_convex_node = None
        return