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 compas.geometry import Ellipse from compas.geometry import Point from compas.geometry import Plane from compas.geometry import Vector from compas.geometry import Translation from compas_plotters import GeometryPlotter plotter = GeometryPlotter() plane = Plane(Point(0, 0, 0), Vector(0, 0, 1)) a = Ellipse(plane, 5.0, 3.0) b = Ellipse(plane, 2.0, 1.0) c = Ellipse(plane, 3.0, 1.0) T = Translation.from_vector([0.1, 0.0, 0.0]) plotter.add(a, edgecolor='#ff0000', fill=False) plotter.add(b, edgecolor='#00ff00', fill=False) plotter.add(c, edgecolor='#0000ff', fill=False) plotter.pause(1.0) for i in range(100): a.transform(T) plotter.redraw(pause=0.01) plotter.zoom_extents() plotter.show()
poly = Polyline(curve.locus()) poly1 = Polyline(offset_polyline(poly, +0.15)) poly2 = Polyline(offset_polyline(poly, -0.15)) points = [curve.point(t) for t in linspace(0, 1, 20)] tangents = [curve.tangent(t) for t in linspace(0, 1, 20)] normals = [Vector(0, 0, 1).cross(t) for t in tangents] # ============================================================================== # Visualization # ============================================================================== plotter = GeometryPlotter(figsize=(16, 9)) plotter.add(controlpoly, linestyle='dotted', linewidth=1.0, color=(0.5, 0.5, 0.5)) for point in controlpoints: plotter.add(point, edgecolor=(1.0, 0.0, 0.0)) for point in points: plotter.add(point, size=2) for point, vector in zip(points, normals): plotter.add(vector.scaled(0.5), point=point) plotter.add(poly, color=(0.4, 0.4, 0.4)) plotter.add(poly1, color=(0.0, 0.0, 0.0)) plotter.add(poly2, color=(0.0, 0.0, 0.0)) plotter.zoom_extents()
from compas.geometry import Point from compas.geometry import Polyline, Polygon from compas_plotters import GeometryPlotter a = Point(0, 0) b = Point(1, 0) c = Point(1, 1) d = Point(0, 1) plotter = GeometryPlotter(show_axes=True) plotter.add(a) plotter.add(b) plotter.add(c) plotter.add(d) plotter.zoom_extents() plotter.show()
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() for point in pcl.points: circle = Circle([point, [0, 0, 1]], random.random()) plotter.add(circle, facecolor=i_to_red(random.random(), normalize=True), edgecolor=i_to_green(random.random(), normalize=True)) plotter.zoom_extents() plotter.show()
from compas.geometry import Circle from compas.geometry import Point from compas.geometry import Plane from compas.geometry import Vector from compas.geometry import Translation from compas_plotters import GeometryPlotter plotter = GeometryPlotter() plane = Plane(Point(0, 0, 0), Vector(0, 0, 1)) a = Circle(plane, 4.0) b = Circle(plane, 3.0) c = Circle(plane, 2.0) T = Translation.from_vector([0.1, 0.0, 0.0]) plotter.add(a, edgecolor='#ff0000') plotter.add(b, edgecolor='#00ff00') plotter.add(c, edgecolor='#0000ff') plotter.pause(1.0) for i in range(100): a.transform(T) plotter.redraw(pause=0.01) plotter.zoom_extents() plotter.show()
# ============================================================================== # Main # ============================================================================== if __name__ == '__main__': from random import uniform from compas.geometry import Box from compas.geometry import Polygon from compas_plotters import GeometryPlotter n = 100 box = Box.from_width_height_depth(10, 3, 5) x, y, _ = zip(*box.points) xmin, xmax = min(x), max(x) ymin, ymax = min(y), max(y) x = [uniform(xmin, xmax) for i in range(n)] y = [uniform(ymin, ymax) for i in range(n)] z = [0] * n points = list(zip(x, y, z)) plotter = GeometryPlotter(show_axes=False) polygon = Polygon(points) plotter.add(polygon) plotter.zoom_extents() plotter.show()
frames = [] for a, b in pairwise(points[1:-1]): p = (a + b) * 0.5 t = (b - a).unitized() n = Vector(0, 0, 1).cross(t) frame = Frame(p, t, n) frames.append(frame) # ============================================================================== # Visualization # ============================================================================== plotter = GeometryPlotter(figsize=(16, 9)) plotter.add(controlpoly, linestyle='dotted', linewidth=0.5, color=(0.5, 0.5, 0.5)) for point in controlpoints: plotter.add(point, edgecolor=(1.0, 0.0, 0.0)) plotter.add(poly, color=(0.4, 0.4, 0.4)) plotter.add(poly1, color=(0.0, 0.0, 0.0)) plotter.add(poly2, color=(0.0, 0.0, 0.0)) for point in points: plotter.add(point, size=2) for point in points1: plotter.add(point, size=2) for point in points2:
from compas.geometry import Pointcloud, Polygon from compas.geometry import Translation from compas_plotters import GeometryPlotter pcl = Pointcloud.from_bounds(10, 5, 0, 100) polygon = Polygon.from_sides_and_radius_xy(5, 2.0) polygon.transform(Translation.from_vector([5, 2.5, 0])) plotter = GeometryPlotter(show_axes=True) plotter.add(polygon, edgecolor=(0, 0, 1), facecolor=(0.7, 0.7, 1.0)) for point in pcl.points: facecolor = (1, 1, 1) plotter.add(point, facecolor=facecolor) plotter.zoom_extents() plotter.show()
transformations = [ Translation.from_vector([ choice([-1, +1]) * random(), choice([-1, +1]) * random(), 0]) for _ in cloud] # ============================================================================== # Visualisation # ============================================================================== # basic plotter instance plotter = GeometryPlotter() # add boundary box and polygon plotter.add(box, edgecolor=(0, 0, 0), fill=False) plotter.add(polygon, edgecolor=(0, 0, 1), facecolor=(0.7, 0.7, 1.0)) # add the points of the pointcloud for point in cloud: plotter.add(point, facecolor=(1, 1, 1)) # start visualisation plotter.zoom_extents() plotter.pause(1) # move points in the direction of the randomly assigned translation vectors # bounce the points of the walls of the box # color points red when they paas through the polygon for _ in range(100): for i in range(N):
# ============================================================================== if __name__ == '__main__': from math import radians from compas.geometry import Point from compas.geometry import Vector from compas.geometry import Line from compas.geometry import Rotation from compas_plotters import GeometryPlotter plotter = GeometryPlotter() a = Point(3.0, 2.0) b = Point(3.0, 5.0) line = Line(a, b) R = Rotation.from_axis_and_angle(Vector(0.0, 0.0, 1.0), radians(10), point=line.end) plotter.add(line, draw_points=True, draw_segment=True) plotter.draw(pause=1.0) for i in range(9): line.transform(R) plotter.redraw(pause=0.01) plotter.show()
Point(6, -2.5, 0), Point(10, 0, 0) ] controlpoly = Polyline(controlpoints) curve = Bezier(controlpoints) poly = Polyline(curve.locus()) poly1 = Polyline(offset_polyline(poly, +0.15)) poly2 = Polyline(offset_polyline(poly, -0.15)) # ============================================================================== # Visualization # ============================================================================== plotter = GeometryPlotter(figsize=(16, 9)) plotter.add(controlpoly, linestyle='dotted', linewidth=1.0, color=(0.5, 0.5, 0.5)) for point in controlpoints: plotter.add(point, edgecolor=(1.0, 0.0, 0.0)) plotter.add(poly, color=(0.4, 0.4, 0.4)) plotter.add(poly1, color=(0.0, 0.0, 0.0)) plotter.add(poly2, color=(0.0, 0.0, 0.0)) plotter.zoom_extents() plotter.show()
from compas.geometry import Pointcloud, Polygon, Line from compas.geometry import Translation from compas.geometry import intersection_line_segment_xy from compas.utilities import grouper, pairwise from compas_plotters import GeometryPlotter pcl = Pointcloud.from_bounds(10, 5, 0, 50) polygon = Polygon.from_sides_and_radius_xy(5, 1.0) polygon.transform(Translation.from_vector([5, 2.5, 0])) plotter = GeometryPlotter(show_axes=True, figsize=(12, 7.5)) plotter.add(polygon, edgecolor=(0, 0, 1), facecolor=(0.7, 0.7, 1.0)) lines = [] for a, b in grouper(pcl.points, 2): line = Line(a, b) lines.append(line) plotter.add(line, color=(0.5, 0.5, 0.5)) plotter.redraw() plotter.zoom_extents() plotter.show()
blocks.append(block) polygons.append(Polygon(block.vertices[:4][::-1])) # ============================================================================== # Export # ============================================================================== compas.json_dump(blocks, FILE) # ============================================================================== # Visualization # ============================================================================== plotter = GeometryPlotter(figsize=(16, 9)) plotter.add(controlpoly, linestyle='dotted', linewidth=0.5, color=(0.5, 0.5, 0.5)) for point in controlpoints: plotter.add(point, edgecolor=(1.0, 0.0, 0.0)) plotter.add(poly0, color=(0.7, 0.7, 0.7), linewidth=0.5) plotter.add(poly1, color=(0.7, 0.7, 0.7), linewidth=0.5) plotter.add(poly2, color=(0.7, 0.7, 0.7), linewidth=0.5) for frame in frames: point = frame.point xaxis = Line(point, point + frame.xaxis * 0.1) yaxis = Line(point, point + frame.yaxis * 0.1) plotter.add(point, edgecolor=(0, 0, 1.0), size=2) plotter.add(xaxis, color=(1.0, 0, 0), draw_as_segment=True) plotter.add(yaxis, color=(0, 1.0, 0), draw_as_segment=True)
# ============================================================================== # Main # ============================================================================== if __name__ == '__main__': from random import uniform from compas.geometry import Box from compas.geometry import Polyline from compas_plotters import GeometryPlotter n = 100 box = Box.from_width_height_depth(10, 3, 5) x, y, _ = zip(*box.points) xmin, xmax = min(x), max(x) ymin, ymax = min(y), max(y) x = [uniform(xmin, xmax) for i in range(n)] y = [uniform(ymin, ymax) for i in range(n)] z = [0] * n points = zip(x, y, z) plotter = GeometryPlotter(show_axes=False) line = Polyline(points) plotter.add(line) plotter.zoom_extents() plotter.show()
# Main # ============================================================================== if __name__ == '__main__': from math import radians from compas.geometry import Point from compas.geometry import Vector from compas.geometry import Line from compas.geometry import Rotation from compas_plotters import GeometryPlotter plotter = GeometryPlotter() a = Point(3.0, 2.0) b = Point(3.0, 5.0) line = Line(a, b) R = Rotation.from_axis_and_angle(Vector(0.0, 0.0, 1.0), radians(10), point=line.end) plotter.add(line, draw_points=True, draw_as_segment=False) plotter.redraw(pause=1.0) for i in range(9): line.transform(R) plotter.redraw(pause=0.01) plotter.show()