from compas.geometry import Vector, Point, Plane from compas.geometry import Polyline from compas.geometry import Circle from compas_occ.geometry import OCCNurbsCurve from compas_view2.app import App circle = Circle(Plane(Point(0, 0, 0), Vector(0, 0, 1)), 1.0) curve = OCCNurbsCurve.from_circle(circle) # ============================================================================== # Visualisation # ============================================================================== view = App() view.add(Polyline(curve.locus()), linewidth=3) view.add(Polyline(curve.points), show_points=True, pointsize=20, pointcolor=(1, 0, 0), linewidth=1, linecolor=(0.3, 0.3, 0.3)) view.run()
front = Plane([0, -1, 0], [0, -1, 0]) back = Plane([0, +1, 0], [0, +1, 0]) halfspaces = array( [left.abcd, right.abcd, top.abcd, bottom.abcd, front.abcd, back.abcd], dtype=float) interior = array([0, 0, 0], dtype=float) hsi = HalfspaceIntersection(halfspaces, interior) hull = ConvexHull(hsi.intersections) mesh = Mesh.from_vertices_and_faces( [hsi.intersections[i] for i in hull.vertices], hull.simplices) mesh.unify_cycles() to_merge = [] for a, b in combinations(mesh.faces(), 2): na = Vector(*mesh.face_normal(a)) nb = Vector(*mesh.face_normal(b)) if na.dot(nb) >= 1: if na.cross(nb).length < 1e-6: to_merge.append([a, b]) for faces in to_merge: mesh.merge_faces(faces) viewer = App() viewer.add(mesh, show_vertices=True, pointsize=10) viewer.run()