Пример #1
0
from compas.geometry import Pointcloud, Translation
from compas.utilities import i_to_red, pairwise

from compas_plotters import Plotter

plotter = Plotter(figsize=(8, 5))

pointcloud = Pointcloud.from_bounds(8, 5, 0, 10)

for index, (a, b) in enumerate(pairwise(pointcloud)):
    artist = plotter.add(a,
                         edgecolor=i_to_red(max(index / 10, 0.1),
                                            normalize=True))

plotter.add(b, size=10, edgecolor=(1, 0, 0))
plotter.zoom_extents()
plotter.pause(1.0)


@plotter.on(interval=0.1,
            frames=50,
            record=True,
            recording='docs/_images/tutorial/plotters_dynamic.gif',
            dpi=150)
def move(frame):
    print(frame)
    for a, b in pairwise(pointcloud):
        vector = b - a
        a.transform(Translation.from_vector(vector * 0.1))

        vnext = mesh.face_vertex_descendant(faces[i], vertices[i])
        vnextnext = mesh.face_vertex_descendant(faces[i], vnext)

        fn = mesh.edge_faces(vnext, vnextnext)
        if faces[i] == fn[0]: fnext = fn[1]
        else: fnext = fn[0]

        vertices.append(vnext)
        edges.append((vertices[i], vnext))
        faces.append(fnext)
        i += 1

    return edges


plotter = Plotter(figsize=(16, 10))
lines = []
pts = []


def draw_edges_on_plotter(edges, color, width):

    for i in edges:
        lines.append({
            'start': mesh.vertex_coordinates(i[0]),
            'end': mesh.vertex_coordinates(i[1]),
            'color': color,
            'width': width
        })
        pts.append({
            'pos': mesh.vertex_coordinates(i[0]),
Пример #3
0
            exclude.add(nnbr[1])
        if distance_sort:
            return sorted(nnbrs, key=lambda nnbr: nnbr[2])
        return nnbrs


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

if __name__ == '__main__':

    from compas.geometry import pointcloud_xy
    from compas_plotters import Plotter

    plotter = Plotter()

    cloud = pointcloud_xy(999, (-500, 500))
    point = cloud[0]

    tree = KDTree(cloud)

    n = 50
    nnbrs = []
    exclude = set()

    for i in range(n):
        nnbr = tree.nearest_neighbor(point, exclude)
        nnbrs.append(nnbr)
        exclude.add(nnbr[1])
Пример #4
0
        return n
    lvec = length_vector_xy(n)
    return n[0] / lvec, n[1] / lvec, n[2] / lvec


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

if __name__ == "__main__":

    from compas.geometry import area_polygon
    from compas.geometry import centroid_points
    from compas_plotters import Plotter

    plotter = Plotter(figsize=(10, 7))

    points = [[0, 0, 0], [1.0, 0, 0], [1.0, 1.0, 0], [0.5, 0.0, 0],
              [0, 1.0, 0]]
    polygon = points[::-1]

    print(polygon)
    print(area_polygon(polygon))

    n = normal_polygon(polygon, unitized=False)
    print(n)

    if n[2] > 0:
        color = '#ff0000'
    else:
        color = '#0000ff'
Пример #5
0
        matrix : list of list
            The transformation matrix.

        Returns
        -------
        Polygon
            The transformed copy.

        """
        polygon = self.copy()
        polygon.transform(matrix)
        return polygon


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

if __name__ == '__main__':

    from compas_plotters import Plotter

    polygon = Polygon([[1, 1, 0], [0, 1, 0], [0, 0, 0], [1, 0, 0]])

    for point in polygon.points:
        print(point[0:2])

    plotter = Plotter(figsize=(10, 7))
    plotter.draw_polygons([{'points': polygon.points}])
    plotter.show()
Пример #6
0
                scale_vector(vector_from_points(points1[i], points2[i]),
                             scale)))
    return tweens


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

if __name__ == "__main__":

    from compas_plotters import Plotter

    points1 = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [2.0, 0.0, 0.0],
               [3.0, 0.0, 0.0]]
    points2 = [[0.0, 0.0, 0.0], [1.0, 3.0, 0.0], [2.0, 1.0, 0.0],
               [3.0, 0.0, 0.0]]

    tweens = tween_points(points1, points2, 5)

    polylines = [{'points': points1, 'width': 1.0}]

    for points in tweens:
        polylines.append({'points': points, 'width': 0.5})

    polylines.append({'points': points2, 'width': 1.0})

    plotter = Plotter(figsize=(10, 7))
    plotter.draw_polylines(polylines)
    plotter.show()
Пример #7
0
from compas.geometry import Pointcloud
from compas.utilities import i_to_red, pairwise

from compas_plotters import Plotter

plotter = Plotter(figsize=(8, 5))

pointcloud = Pointcloud.from_bounds(8, 5, 0, 10)

for index, (a, b) in enumerate(pairwise(pointcloud)):
    vector = b - a
    vector.unitize()
    plotter.add(vector,
                point=a,
                draw_point=True,
                color=i_to_red(max(index / 10, 0.1), normalize=True))

plotter.add(b, size=10, edgecolor=(1, 0, 0))

plotter.zoom_extents()
plotter.show()
plotter.save('docs/_images/tutorial/plotters_vector-options.png', dpi=300)
Пример #8
0
from random import random
from compas.geometry import pointcloud_xy
from compas_plotters import Plotter
from compas.utilities import i_to_green
from compas.utilities import i_to_red

cloud = pointcloud_xy(20, (0, 10), (0, 5))

points = []
for xyz in cloud:
    n = random()
    points.append({
        'pos': xyz,
        'radius': n,
        'edgecolor': i_to_green(n),
        'facecolor': i_to_red(n)
    })

plotter = Plotter(figsize=(8, 5))
plotter.draw_points(points)
plotter.show()
Пример #9
0
 def plotter(self):
     if not self._plotter:
         from compas_plotters import Plotter
         self._plotter = Plotter()
     return self._plotter
Пример #10
0
import random
from compas.geometry import Line
from compas.geometry import Pointcloud
from compas.utilities import i_to_rgb, grouper

from compas_plotters import Plotter

plotter = Plotter(figsize=(8, 5))

pointcloud = Pointcloud.from_bounds(8, 5, 0, 10)

for a, b in grouper(pointcloud, 2):
    line = Line(a, b)
    plotter.add(line,
                linewidth=2.0,
                linestyle=random.choice(['dotted', 'dashed', 'solid']),
                color=i_to_rgb(random.random(), normalize=True),
                draw_points=True)

plotter.zoom_extents()
plotter.show()
# plotter.save('docs/_images/tutorial/plotters_line-options.png', dpi=300)
        area += cross_vectors(vectors[i - 1], vectors[i])[2] / 2

    return area


if __name__ == "__main__":

    # Test task 1.1
    u = [10, 10.0, 0.0]
    v = [-10.0, 10.0, 0.0]
    i, j, k = orthonormals_from_two_vectors(u, v)
    print(i, j, k)

    # Test task 1.2

    plotter = Plotter()

    my_polygon = [[0.0, 0.0], [1.0, 0.0], [1.0, 0.5], [0.5, 2.0], [0.0, 1.0]]

    plotter.draw_polygons([{'points': my_polygon}])
    plotter.show()

    print('The area of the polygon is: ', convex_polygon_area(my_polygon))
    print('The area of the polygon using compas is: ',
          convex_polygon_area_compas(my_polygon))

    # Test task 1.3
    arr_1 = [[2.0, 0.0, 0.0], [1.0, 0.0, 1.0], [1.0, 0.5, 0.0]]
    arr_2 = [[0.5, 3.0, 0.0], [1.0, 0.0, 0.0], [1.0, 5.0, 2.0]]
    ## pure python
    print(cross_array_of_vectors_py(arr_1, arr_2))
Пример #12
0
from compas.geometry import Polygon, Translation

from compas_plotters import Plotter

poly1 = Polygon.from_sides_and_radius_xy(5, 1.0)
poly2 = Polygon.from_sides_and_radius_xy(5, 1.0).transformed(Translation.from_vector([0.5, -0.25, 0]))
poly3 = Polygon.from_sides_and_radius_xy(5, 1.0).transformed(Translation.from_vector([0.75, +0.25, 0]))

plotter = Plotter(figsize=(8, 5))
plotter.add(poly1, linewidth=3.0, facecolor=(0.8, 1.0, 0.8), edgecolor=(0.0, 1.0, 0.0))
plotter.add(poly2, linestyle='dashed', facecolor=(1.0, 0.8, 0.8), edgecolor=(1.0, 0.0, 0.0))
plotter.add(poly3, alpha=0.5)
plotter.zoom_extents()
plotter.show()
# plotter.save('docs/_images/tutorial/plotters_polygon-options.png', dpi=300)
        })
    else:
        b = polygon.points[i + 1] - polygon.centroid
        lines_out.append({
            'start': polygon.points[i],
            'end': polygon.points[i + 1],
            'width': 1.0
        })
    # draw lines from polygon vertices to centroid
    lines_in.append({
        'start': polygon.points[i],
        'end': polygon.centroid,
        'width': 1.0,
        'color': (130, 130, 130)
    })
    # cross product
    c = cross(a, b)
    area = area + c[
        2] / 2  # since polygon is in xy-plane, length of resulting vector from cross product is just the z-component

points.append({
    'pos': polygon.centroid,
    'radius': 0.005,
})

plotter = Plotter(figsize=(8, 5))
plotter.draw_points(points)
plotter.draw_lines(lines_out)
plotter.draw_lines(lines_in)
plotter.show()