Exemplo n.º 1
0
 def test_data():
     p = Pointcloud.from_bounds(10, 10, 10, 100)
     assert p.data == p.validate_data()
     o = Pointcloud.from_data(p.data)
     assert p == o
     assert not (p is o)
     assert o.data == o.validate_data()
Exemplo n.º 2
0
def test_inequality():
    a = Pointcloud.from_bounds(10, 10, 10, 10)
    b = Pointcloud.from_bounds(10, 10, 10, 11)
    assert a != b
    b = Pointcloud.from_bounds(10, 10, 10, 9)
    assert a != b
    b = Pointcloud.from_bounds(10, 10, 10, 10)
    assert a != b
Exemplo n.º 3
0
    def plot(self):
        """Visualize the current map with the plotter.

        Returns
        -------
        None

        """
        from compas_plotters.plotter import Plotter
        from compas.geometry import Pointcloud
        from compas.geometry import Plane, Circle, Polygon
        plotter = Plotter(figsize=(16, 12))
        w = 16
        h = 10
        n = len(self.colors)
        d = w / n
        cloud = Pointcloud.from_bounds(w, h, 0, n)
        white = Color.white()
        for i, color in enumerate(self.colors):
            c = Circle(Plane(cloud[i], [0, 0, 1]), 0.1)
            p = Polygon([[i * d, -2, 0], [(i + 1) * d, -2, 0],
                         [(i + 1) * d, -1, 0], [i * d, -1, 0]])
            plotter.add(c, facecolor=color, edgecolor=white, linewidth=0.5)
            plotter.add(p, facecolor=color, edgecolor=color)
        plotter.zoom_extents()
        plotter.show()
Exemplo n.º 4
0
import random

from compas.geometry import Pointcloud, Circle
from compas.utilities import i_to_red, i_to_green
from compas_plotters import GeometryPlotter

pcl = Pointcloud.from_bounds(10, 5, 0, 100)

plotter = GeometryPlotter(show_axes=True)

for point in pcl.points:
    plotter.add(point)

plotter.zoom_extents()
plotter.show()
from math import radians

from compas.geometry import Pointcloud, Box
from compas.geometry import Rotation
from compas.geometry import oriented_bounding_box_numpy

from compas_view2.app import App

cloud = Pointcloud.from_bounds(10, 5, 3, 100)

Rz = Rotation.from_axis_and_angle([0.0, 0.0, 1.0], radians(60))
Ry = Rotation.from_axis_and_angle([0.0, 1.0, 0.0], radians(20))
Rx = Rotation.from_axis_and_angle([1.0, 0.0, 0.0], radians(10))

cloud.transform(Rz * Ry * Rx)

bbox = oriented_bounding_box_numpy(cloud)
box = Box.from_bounding_box(bbox)

viewer = App()
viewer.add(cloud)
viewer.add(box, show_faces=False, linecolor=(1, 0, 0), linewidth=3)
viewer.run()
Exemplo n.º 6
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))

Exemplo n.º 7
0
def test_equality():
    a = Pointcloud.from_bounds(10, 10, 10, 10)
    points = a.points[:]
    random.shuffle(points)
    b = Pointcloud(points)
    assert a == b
from compas.geometry import intersection_segment_segment_xy, mirror_points_line_xy
from compas_plotters import GeometryPlotter

# ==============================================================================
# Parameters
# ==============================================================================

N = 50
W = 100
H = 50

# ==============================================================================
# Objects
# ==============================================================================

cloud = Pointcloud.from_bounds(W, H, 0, N)
polygon = Polygon.from_sides_and_radius_xy(5, 20.0)
polygon.transform(Translation.from_vector([0.5 * W, 0.5 * H, 0]))
box = Polygon([[0, 0], [W, 0], [W, H], [0, H]])

# ==============================================================================
# Transformations
# ==============================================================================

# random translation vector per point in the cloud
transformations = [
    Translation.from_vector([
        choice([-1, +1]) * random(),
        choice([-1, +1]) * random(),
        0])
    for _ in cloud]