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()
# ============================================================================== # Main # ============================================================================== if __name__ == '__main__': 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)
controlpoly = Polyline(controlpoints) curve = Bezier(controlpoints) 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))
# ============================================================================== # 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()
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()
points1 = [intersection_line_polyline(line, poly1) for line in lines] points2 = [intersection_line_polyline(line, poly2) for line in lines] 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)
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()
# ============================================================================== # 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_segment=True) plotter.draw(pause=1.0) for i in range(9): line.transform(R) plotter.redraw(pause=0.01)
self._mpl_circle.set_facecolor(self.facecolor) self.plotter.axes.update_datalim([self.circle.center[:2]]) # ============================================================================== # Main # ============================================================================== if __name__ == '__main__': from compas.geometry import Circle from compas.geometry import Point from compas.geometry import Plane from compas.geometry import Vector 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) plotter.add(a, edgecolor='#ff0000') plotter.add(b, edgecolor='#00ff00') plotter.add(c, edgecolor='#0000ff') plotter.draw(pause=1.0) plotter.show()
# ============================================================================== # random translation vector per point in the cloud 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
self._mpl_ellipse.set_edgecolor(self.edgecolor) self._mpl_ellipse.set_facecolor(self.facecolor) # ============================================================================== # Main # ============================================================================== if __name__ == '__main__': from compas.geometry import Ellipse from compas.geometry import Point from compas.geometry import Plane from compas.geometry import Vector 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) plotter.add(a, edgecolor='#ff0000', fill=False) plotter.add(b, edgecolor='#00ff00', fill=False) plotter.add(c, edgecolor='#0000ff', fill=False) plotter.draw() 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()