def get_orthonormal_frame(u,v): # Orthogonal frame a = Vector.cross(u,v) b = Vector.cross(a,u) c = Vector.cross(a,b) # Normalized frame a.unitize() b.unitize() c.unitize() return (a,b,c)
def arrays_cross(array1, array2): cross_list = [] for i in range(len(array1)): u = Vector(array1[i][0], array1[i][1], array1[i][2]) v = Vector(array2[i][0], array2[i][1], array2[i][2]) cross_list.append(u.cross(v)) return cross_list
def ray_mesh_intersect_reflect(ray, mesh, hit, facemap): base, vector = ray index = hit[0] distance = hit[3] face = facemap[index] p = base + vector * distance n = Vector(*mesh.face_normal(face)) n = n.cross(vector.cross(n)) r = base.transformed(Reflection.from_plane((p, n))) return p, r
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()
from compas.geometry import Point from compas.geometry import Vector # Point p1 = Point(1, 2, 3) assert p1 ** 3 == [1, 8, 27] assert p1 + [0, 2, 1] == [1, 4, 4] # Vector u = Vector(1, 0, 0) v = Vector(0, 1, 0) assert u + v == [1, 1, 0] assert u.dot(v) == 0.0 assert u.cross(v) == [0, 0, 1] assert (u * 2).unitized() == [1, 0, 0]
from compas.geometry import Vector u = Vector(1.0, 0.0, 0.0) v = Vector(0.0, 1.0, 0.0) uxv = u.cross(v) u_uxv = u.angle(uxv) v_uxv = v.angle(uxv) print(u_uxv) print(v_uxv)
# ============================================================================== Z = Vector(0, 0, 1) controlpoints = [Point(0, 0, 0), Point(4, 2.5, 0), Point(6, -2.5, 0), Point(10, 0, 0)] controlpoly = Polyline(controlpoints) curve = Bezier(controlpoints) poly0 = Polyline(curve.locus()) poly1 = Polyline(offset_polyline(poly0, +0.15)) poly2 = Polyline(offset_polyline(poly0, -0.15)) points0 = [poly0.point(t) for t in linspace(0, 1, 20)] tangents0 = [(c - a).unitized() for a, b, c in window(points0, 3) if a and c] normals0 = [Z.cross(t) for t in tangents0] lines = [[point, point + normal] for point, normal in zip(points0[1:-1], normals0)] points1 = [intersection_line_polyline(line, poly1) for line in lines] points2 = [intersection_line_polyline(line, poly2) for line in lines] # ============================================================================== # Blocks # ============================================================================== frames = [] blocks = [] polygons = [] for (a, b), (a1, b1), (a2, b2) in zip(pairwise(points0[1:-1]), pairwise(points1), pairwise(points2)):
from compas.geometry import Vector u = Vector(1.0, 0.0, 0.0) v = Vector(0.0, 1.0, 0.0) print(u.cross(v)[2] > 0) print(v.cross(u)[2] > 0)