Beispiel #1
0
    def point(self, t, snap=False):
        """Point on the polyline at a specific normalized parameter.

        Parameters
        ----------
        t : float
            The parameter value.
        snap : bool, optional
            If True, return the closest polyline point.

        Returns
        -------
        :class:`compas.geometry.Point`
            The point on the polyline.

        Examples
        --------
        >>> polyline = Polyline([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0]])
        >>> polyline.point(0.75)
        Point(1.000, 0.500, 0.000)

        """
        if t < 0 or t > 1:
            return None

        points = self.points
        if t == 0:
            return points[0]
        if t == 1:
            return points[-1]

        polyline_length = self.length

        x = 0
        i = 0
        while x <= t:
            line = Line(points[i], points[i + 1])
            line_length = line.length
            dx = line_length / polyline_length
            if x + dx > t:
                if snap:
                    if t - x < x + dx - t:
                        return line.start
                    else:
                        return line.end
                return line.point((t - x) * polyline_length / line_length)
            x += dx
            i += 1
Beispiel #2
0
    def point(self, t, snap=False):
        """Point: The point from the start to the end at a specific normalized parameter.
        If snap is True, return the closest polyline point."""

        if t < 0 or t > 1:
            return None

        points = self.points

        if t == 0:
            return points[0]

        if t == 1:
            return points[-1]

        polyline_length = self.length

        x = 0
        i = 0

        while x <= t:

            line = Line(points[i], points[i + 1])
            line_length = line.length

            dx = line_length / polyline_length

            if x + dx > t:

                if snap:
                    if t - x < x + dx - t:
                        return line.start
                    else:
                        return line.end

                return line.point((t - x) * polyline_length / line_length)

            x += dx
            i += 1