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 lines(self):
     """list of :class:`compas.geometry.Line` : The lines of the polygon."""
     if not self._lines:
         self._lines = [
             Line(a, b) for a, b in pairwise(self.points + self.points[:1])
         ]
     return self._lines
Beispiel #3
0
 def points(self, points):
     self._points = [Point(*xyz) for xyz in points]
     self._lines = [
         Line(self._points[i], self._points[i + 1])
         for i in range(0,
                        len(self._points) - 1)
     ]
Beispiel #4
0
 def points(self, points):
     if points[-1] == points[0]:
         del points[-1]
     self._points = [Point(*xyz) for xyz in points]
     self._lines = [
         Line(self.points[i], self.points[i + 1])
         for i in range(-1,
                        len(points) - 1)
     ]
Beispiel #5
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
Beispiel #6
0
    def from_data(cls, data):
        """Construct a capsule from its data representation.

        Parameters
        ----------
        data : :obj:`dict`
            The data dictionary.

        Returns
        -------
        :class: `Capsule`
            The constructed capsule.
        """
        line = Line.from_data(data['line'])
        capsule = Capsule(line, data['radius'])
        return capsule
Beispiel #7
0
 def lines(self):
     if not self._lines:
         self._lines = [Line(a, b) for a, b in pairwise(self.points)]
     return self._lines
Beispiel #8
0
 def data(self, data):
     self.line = Line.from_data(data['line'])
     self.radius = data['radius']
Beispiel #9
0
        -------
        :class: `Capsule`
            The transformed copy of the current capsule.
        """
        capsule = self.copy()
        capsule.line.transform(transformation)
        return capsule


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":
    from compas.geometry import Transformation

    capsule = Capsule(Line((1, 2, 3), (4, 5, 6)), 1.3)
    frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
    print(frame.normal)
    T = Transformation.from_frame(frame)
    capsule.transform(T)
    print(capsule)

    print(Plane.worldXY().data)
    data = {'line': Line((1, 2, 3), (5, 4, 2)).data, 'radius': 1.2}
    capsule = Capsule.from_data(data)
    print(capsule)

    import doctest
    doctest.testmod()