def check_type(frame): """Return the type of the element. """ a = abs(frame.xaxis.dot(Vector.Zaxis())) b = abs(frame.xaxis.dot(Vector.Yaxis())) if a > 0.9: elem_type = 'Z' elif a < 0.1: if b > 0.9: elem_type = 'Y' else: elem_type = 'X' else: elem_type = None return elem_type
import random from math import radians from compas.geometry import pointcloud from compas.geometry import Point from compas.geometry import Vector from compas.geometry import Rotation from compas.geometry import Translation from compas.geometry import icp_numpy from compas_plotters import Plotter2 R = Rotation.from_axis_and_angle(Vector.Zaxis(), radians(30)) source = [Point(*xyz) for xyz in pointcloud(30, (0, 10), (0, 5), (0, 3))] observations = Point.transformed_collection(source, R) noise = [] for i in range(5): point = random.choice(observations) T = Translation([random.random(), random.random(), random.random()]) noise.append(point.transformed(T)) outliers = [Point(*xyz) for xyz in pointcloud(3, (10, 15), (0, 5), (0, 3))] Point.transform_collection(outliers, R) target = observations + noise + outliers # A, X = icp_numpy(source, target) # source_new = [Point(*point) for point in A] plotter = Plotter2()
surface = OCCNurbsSurface.from_points(points=points) # ============================================================================== # Intersections # ============================================================================== base = Point(*centroid_points_xy(list(flatten(points)))) line = Line(base, base + Vector(0, 0, 1)) Ry = Rotation.from_axis_and_angle(Vector.Yaxis(), radians(30), point=base) line.transform(Ry) lines = [] for i in range(30): Rz = Rotation.from_axis_and_angle(Vector.Zaxis(), radians(i * 360 / 30), point=base) lines.append(line.transformed(Rz)) intersections = [] for line in lines: x = surface.intersections_with_line(line) if x: intersections.append(x[0]) # ============================================================================== # Visualisation # ============================================================================== view = App(viewmode='ghosted')