from vectors import * from draw3d import * octahedron = [ [(1, 0, 0), (0, 1, 0), (0, 0, 1)], [(1, 0, 0), (0, 0, -1), (0, 1, 0)], [(1, 0, 0), (0, 0, 1), (0, -1, 0)], [(1, 0, 0), (0, -1, 0), (0, 0, -1)], [(-1, 0, 0), (0, 0, 1), (0, 1, 0)], [(-1, 0, 0), (0, 1, 0), (0, 0, -1)], [(-1, 0, 0), (0, -1, 0), (0, 0, 1)], [(-1, 0, 0), (0, 0, -1), (0, -1, 0)], ] vs = [v for face in octahedron for v in face] segs = [ Segment3D(face[i], face[(i + 1) % len(face)]) for face in octahedron for i in range(len(face)) ] draw3d( Points3D(*vs), *segs, )
from math import pi from transforms import * from draw3d import * def infer_matrix(n, transformation): matrix = [] for i in range(n): row = [0] * n row[i] = 1 matrix.append(transformation(row)) return tuple(matrix) if __name__ == '__main__': v = (1, 1, 1) # m = infer_matrix(3, rotate_x_by(3/2 * pi)) m = infer_matrix(3, rotate_z_by(pi/2)) # m = infer_matrix(3, scale_by(2)) print(m) tv = multiply_matrix_vector(m, v) print(tv) draw3d(Arrow3D(v), Arrow3D(tv, color=blue))
from vectors import * from draw3d import * o = (0, 0, 0) v = (4, 0, 3) u = (-1, 0, 1) a = add(u, v) print("u v a", u, v, a) draw3d( # Segment3D(o, u, color=green), # Segment3D(u, add(u, v), color=red), Arrow3D(tip=u, color=blue), Arrow3D(tail=u, tip=a, color=red), Arrow3D(tip=v, color=red), Arrow3D(tail=v, tip=a, color=blue), Arrow3D(tip=a, color=purple), )
from math import sin, cos, pi from draw3d import * from vectors import * vs = [(sin(pi*t/6), cos(pi*t/6), 1.0/3) for t in range(0, 24)] arrows = [] running_sum = (0, 0, 0) for v in vs: step = add(running_sum, v) arrows.append(Arrow3D(tail=running_sum, tip=step)) running_sum = step a = add(*vs) print(a) draw3d(*arrows)
from draw3d import * from vectors import * v1 = (-1, 0, 0) v2 = (0, -1, 0) v3 = (0, 0, 1) points = Points3D(v1, v2, v3) segs = [Segment3D(v1, v2), Segment3D(v1, v3), Segment3D(v2, v3)] c = cross(subtract(v2, v1), subtract(v3, v1)) draw3d(points, *segs, Arrow3D(subtract(v2, v1), color=red), Arrow3D(subtract(v3, v1), color=purple), Arrow3D(c, color=green))
r = (1, -1) v = [(x, y, z) for x in r for y in r for z in r] edges = [((-1, y, z), (1, y, z)) for y in r for z in r] +\ [((x, -1, z), (x, 1, z)) for x in r for z in r] +\ [((x, y, -1), (x, y, 1)) for x in r for y in r] # segs = [] # for v1 in v: # for v2 in v: # print(v1, v2, distance(v1, v2)) # if distance(v1, v2) == 2.0: # segs.append(Segment3D(v1, v2)) segs = [ Segment3D(v1, v2, color=red) for v1 in v for v2 in v if distance(v1, v2) == 2.0 ] # segs = filter(lambda s: distance(s.start_point, s.end_point) == 2.0, segs) print("Segments:", len(edges)) # segs = [Segment3D(v[i], v[(i+1) % len(v)]) for i in range(0, len(v))] draw3d( Points3D(*v, color=blue), *[Segment3D(*e) for e in edges], *segs, # Box3D(*v), # Segment3D(o, v), )