def __init__(self, width=1.5, thickness=0.3): tangent = v3.vector(0, 0, 1) up = v3.vector(0, width, 0) right = v3.cross(up, tangent) right = thickness / width * right self.arcs = [ right + up, +up, -right + up, -right - up, -up, right - up ] self.normals = calc_cyclic_normals(self.arcs, tangent)
def test_vector_make(): v = v3.vector() assert v3.is_similar_vector(v3.vector(), v3.vector(0, 0, 0)) v = v3.random_vector() w = v3.vector(v) assert v3.is_similar_vector(v, w) u = v3.vector(*v) assert v3.is_similar_vector(v, u) w = v u = v3.random_vector() v3.set_vector(w, *u) assert v3.is_similar_vector(w, v)
def __init__(self, n_arc=10, radius=1.0): self.n_arc = n_arc tangent = v3.vector(0, 0, 1) rotator = v3.vector(0, radius, 0) self.arcs = [] angle = v3.radians(360 / n_arc) rotation = v3.rotation(tangent, angle) self.arcs.append(v3.vector(rotator)) for i_segment in range(n_arc - 1): rotator = v3.transform(rotation, rotator) self.arcs.append(rotator) self.normals = calc_cyclic_normals(self.arcs, tangent)
def test_orthogonality(): x = v3.vector(v3.random_mag(), 0, 0) y = v3.vector(0, v3.random_mag(), 0) z = v3.vector(0, 0, v3.random_mag()) ry_x = v3.transform(v3.rotation(y, v3.radians(90)), x) assert v3.is_similar_vector(v3.norm(ry_x), -v3.norm(z)) assert v3.is_similar_mag(v3.mag(ry_x), v3.mag(x)) ry_z = v3.transform(v3.rotation(y, v3.radians(90)), z) assert v3.is_similar_vector(v3.norm(ry_z), v3.norm(x)) cross_x_y = v3.cross(x, y) assert v3.is_similar_vector(v3.norm(cross_x_y), v3.norm(z)) cross_y_x = v3.cross(y, x) assert v3.is_similar_vector(v3.norm(cross_y_x), -v3.norm(z))
def __init__(self, n_stack=5, n_arc=5, scale=1.0): self.arcs = [] self.stacks = [] self.indices = [] self.points = [] vert_angle = math.pi / (n_stack - 1) arc_angle = math.pi * 2.0 / n_arc for i_stack in range(n_stack): radius = math.sin(i_stack * vert_angle) z = -scale * math.cos(i_stack * vert_angle) for i_arc in range(n_arc): x = scale * radius * math.cos(i_arc * arc_angle) y = scale * radius * math.sin(i_arc * arc_angle) self.points.append(v3.vector(x, y, z)) for i_stack in range(n_stack - 1): for i_arc in range(n_arc): j_arc = (i_arc + 1) % n_arc self.indices.extend([ (i_stack) * n_arc + i_arc, (i_stack + 1) * n_arc + i_arc, (i_stack + 1) * n_arc + j_arc, (i_stack + 1) * n_arc + j_arc, (i_stack) * n_arc + j_arc, (i_stack) * n_arc + i_arc, ]) self.n_vertex = n_stack * n_arc
def __init__(self, n_arc, radius=1.0): self.points = [] self.normals = [] self.indices = [] arc_angle = math.pi * 2.0 / n_arc for z in [0.0, 1.0]: for j in range(n_arc): x = radius * math.cos(j * arc_angle) y = radius * math.sin(j * arc_angle) self.normals.append(v3.vector(x, y, 0.0)) self.points.append(v3.vector(x, y, z)) for i_arc in range(n_arc): j_arc = (i_arc + 1) % n_arc self.indices.extend([ j_arc, i_arc, n_arc + i_arc, j_arc, n_arc + i_arc, n_arc + j_arc ]) self.n_vertex = 2 * n_arc
def test_matrix_combination(): n = 4 x = v3.random_vector() y1 = v3.vector(x) matrix = v3.identity() for i in range(4): r_matrix = v3.random_matrix() y1 = v3.transform(r_matrix, y1) matrix = v3.combine(r_matrix, matrix) y2 = v3.transform(matrix, x) assert v3.is_similar_vector(y1, y2)
def __init__(self, length, width, thickness): self.vertices = [ v3.vector(thickness, 0, length), v3.vector(thickness, -width, -length), v3.vector(thickness, width, -length), v3.vector(-thickness, 0, length), v3.vector(-thickness, -width, -length), v3.vector(-thickness, width, -length), ] self.indices = [1, 0, 2, 3, 4, 5] n_arc = 3 for i in range(n_arc): j = (i + 1) % n_arc self.indices.extend([i + n_arc, i, j, j + n_arc, i + n_arc, j])
def test_translation(): x = v3.vector(v3.random_mag(), 0, 0) y = v3.vector(0, v3.random_mag(), 0) x_and_y = v3.transform(v3.translation(y), x) assert v3.is_similar_vector(x_and_y, x+y)
def test_translation(): x = v3.vector(v3.random_mag(), 0, 0) y = v3.vector(0, v3.random_mag(), 0) x_and_y = v3.transform(v3.translation(y), x) assert v3.is_similar_vector(x_and_y, x + y)