def gluepath_creator(int_surf, path_width): def interval_checker(dimension): underflow = dimension % path_width if underflow > 0.2: no_paths = dimension // path_width + 1 new_path_width = dimension / no_paths return new_path_width else: return path_width wid_gap = int_surf[1] - int_surf[0] wid_vec = Vector(wid_gap[0], wid_gap[1], wid_gap[2]) wid = wid_vec.length wid_vec.unitize() len_gap = int_surf[2] - int_surf[1] len_vec = Vector(len_gap[0], len_gap[1], len_gap[2]) len = len_vec.length len_vec.unitize() wid_path = interval_checker(wid) len_path = interval_checker(len) path_dims = [wid_path, len_path] path_points = [] iteration = 0 path_unfinished = True current_pt = int_surf[0] + scale_vector( wid_vec, wid_path / 2) + scale_vector(len_vec, len_path / 2) current_vec = len_vec.unitized() len_left = len - len_path wid_left = wid - wid_path dims_left = [len_left, wid_left] path_points.append(current_pt) R = Rotation.from_axis_and_angle([0, 0, 1], -math.pi / 2) while path_unfinished: current_index = iteration % 2 current_dim = dims_left[current_index] if iteration > 2: current_dim -= path_dims[current_index] dims_left[current_index] = current_dim if current_dim < path_width * 0.95: break current_pt = current_pt + scale_vector(current_vec, current_dim) path_points.append(current_pt) current_vec.transform(R) current_vec.unitize() iteration += 1 if not is_point_in_polygon_xy(current_pt, int_surf): print("Error: Point not in polygon") return path_points
"""Example: Create a rotation from and axis and an angle. """ from compas.geometry import Vector from compas.geometry import Rotation aav = Vector(-0.043, -0.254, 0.617) angle, axis = aav.unitized(), aav.length print(angle, axis) R = Rotation.from_axis_angle_vector(aav) axis, angle = R.axis_and_angle print(axis, angle)
# ============================================================================== if __name__ == '__main__': from math import radians from compas.geometry import Vector from compas.geometry import Line from compas.geometry import Rotation from compas.geometry import Translation from compas_plotters import Plotter2 point = Point(0.0, 3.0, 0.0) vector = Vector(2.0, 0.0, 0.0) direction = vector.unitized() loa = Line(point, point + direction) R = Rotation.from_axis_and_angle(Vector(0.0, 0.0, 1.0), radians(3.6)) T = Translation(direction.scaled(0.1)) plotter = Plotter2() plotter.add(vector, point=point, draw_point=True) plotter.add(loa) plotter.draw(pause=1.0) for i in range(100): point.transform(T) vector.transform(R) plotter.redraw(pause=0.01)