def test_bounded_cylinder_bounding_box(self): shape = Cylinder() shape.minimum = -5 shape.maximum = 3 box = shape.bounds_of() self.assertEqual(box.min, Point(-1, -5, -1)) self.assertEqual(box.max, Point(1, 3, 1))
def test_a_ray_strikes_a_cylinder1(self): cyl = Cylinder() direction = Vector(0, 0, 1).normalize() r = Ray(Point(1, 0, -5), direction) xs = cyl.local_intersect(r) self.assertEqual(2, xs.count) self.assertTrue(equals(5.0, xs[0].t)) self.assertTrue(equals(5.0, xs[1].t))
def test_a_ray_strikes_a_cylinder3(self): cyl = Cylinder() direction = Vector(0.1, 1, 1).normalize() r = Ray(Point(0.5, 0, -5), direction) xs = cyl.local_intersect(r) self.assertEqual(2, xs.count) self.assertTrue(equals(6.80798, xs[0].t)) self.assertTrue(equals(7.08872, xs[1].t))
def sinusoidal_cylinder(): N = 11 M = 2 eps = 0.1 # eps2 = 0.1 z = np.linspace(0, 1, N) theta = np.linspace(0, 1, N) # ED configuration rho_ed = 30 h_ed = 80 r_ed = [] drdt_ed = [] drdz_ed = [] # Deformed Configuration rho_es = 20 h_es = 60 r_es = [] drdt_es = [] drdz_es = [] # eps2*np.sin( 2 * np.pi * theta[j] ) ) for i in range(0, len(z)): for j in range(0, len(theta)): cylinder_ed = Cylinder( rho_ed * ((1 + eps * np.sin(M * 2 * np.pi * z[i]))), h_ed, theta[j], z[i]) r_ed.append(cylinder_ed.cylinder2cart()) drdt_ed.append(cylinder_ed.partial_theta()) drdz_ed.append(cylinder_ed.partial_z_sin(M, eps)) cylinder_es = Cylinder( rho_es * ((1 + eps * np.sin(M * 2 * np.pi * z[i]))), h_es, theta[j], z[i]) r_es.append(cylinder_es.cylinder2cart()) drdt_es.append(cylinder_es.partial_theta()) drdz_es.append(cylinder_es.partial_z_sin(M, eps)) pts_ed = r_ed pts_es = r_es size_u = N size_v = N degree_u = 3 degree_v = 3 # Do global surface approximation surf_ed = fitting.approximate_surface(pts_ed, size_u, size_v, degree_u, degree_v) surf_ed = convert.bspline_to_nurbs(surf_ed) # Do global surface approximation surf_es = fitting.approximate_surface(pts_es, size_u, size_v, degree_u, degree_v) surf_es = convert.bspline_to_nurbs(surf_es) return surf_ed, surf_es, drdt_ed, drdz_ed, drdt_es, drdz_es
def test_normal_vector_on_cylinder(self): cyl = Cylinder() PointNormal = namedtuple("PointNormal", ["point", "normal"]) point_normals = [ PointNormal(Point(1, 0, 0), Vector(1, 0, 0)), PointNormal(Point(0, 5, -1), Vector(0, 0, -1)), PointNormal(Point(0, -2, 1), Vector(0, 0, 1)), PointNormal(Point(-1, 1, 0), Vector(-1, 0, 0)) ] for point_normal in point_normals: n = cyl.local_normal_at(point_normal.point) self.assertEqual(n, point_normal.normal)
def test_ray_misses_cylinder(self): cyl = Cylinder() rays = [ Ray(Point(1, 0, 0), Vector(0, 1, 0)), Ray(Point(0, 0, 0), Vector(0, 1, 0)), Ray(Point(0, 0, -5), Vector(1, 1, 1)) ] for ray in rays: direction = Vector.normalize(ray.direction) r = Ray(ray.origin, direction) xs = cyl.local_intersect(r) self.assertEqual(len(xs), 0)
def test_group_bounding_box_contains_children(self): s = Sphere() s.transform = Transformations.translation(2, 5, -3).dot( Transformations.scaling(2, 2, 2)) c = Cylinder() c.minimum = -2 c.maximum = 2 c.transform = Transformations.translation(-4, -1, 4).dot( Transformations.scaling(0.5, 1, 0.5)) shape = Group() shape.add_child(s) shape.add_child(c) box = shape.bounds_of() self.assertEqual(box.min, Point(-4.5, -3, -5)) self.assertEqual(box.max, Point(4, 7, 4.5))
def __spawnDependOnObjectType(self, obj): if obj['type'] == "BOX": pos = [ self.position[0] + obj['local_pos'][0], self.position[1] + obj['local_pos'][1], self.position[2] + obj['local_pos'][2] ] scale = obj['local_scale'] model_path = obj['path'] obj_col_pos = obj['col_pos'] obj_col_scale = obj['col_scale'] quat = obj['local_quaternion'] chair = Cube(pos, scale, model_path, obj_col_scale, obj_col_pos, quat) self.showcase.add(chair.model) return chair if obj['type'] == "CYLINDER": pos = [ self.position[0] + obj['local_pos'][0], self.position[1] + obj['local_pos'][1], self.position[2] + obj['local_pos'][2] ] scale = obj['local_scale'] model_path = obj['path'] obj_col_pos = obj['col_pos'] quat = obj['local_quaternion'] col_rad = obj['col_radius'] col_height = obj['col_height'] isStatic = obj['isStatic'] cylinder = Cylinder(pos, scale, model_path, col_rad, col_height, obj_col_pos, quat, isStatic) if obj['canCollider'] == "TRUE": self.collision_objects[str(cylinder.colId)] = cylinder self.showcase.add(cylinder.model)
def test_intersect_constrained_cylinder(self): cyl = Cylinder() cyl.minimum = 1 cyl.maximum = 2 CylinderIntersection = namedtuple("CyliderIntersection", ["point", "direction", "count"]) cylinder_intersections = [ CylinderIntersection(Point(0, 1.5, 0), Vector(0.1, 1, 0), 0), CylinderIntersection(Point(0, 3, -5), Vector(0, 0, 1), 0), CylinderIntersection(Point(0, 0, -5), Vector(0, 0, 1), 0), CylinderIntersection(Point(0, 2, -5), Vector(0, 0, 1), 0), CylinderIntersection(Point(0, 1, -5), Vector(0, 0, 1), 0), CylinderIntersection(Point(0, 1.5, -2), Vector(0, 0, 1), 2) ] for cylinder_intersection in cylinder_intersections: direction = Vector.normalize(cylinder_intersection.direction) r = Ray(cylinder_intersection.point, direction) xs = cyl.local_intersect(r) self.assertEqual(len(xs), cylinder_intersection.count)
def test_ray_strikes_cylinder(self): cyl = Cylinder() RayIntersection = namedtuple("RayIntersection", ["origin", "direction", "t0", "t1"]) ray_intersections = [ RayIntersection(Point(1, 0, -5), Vector(0, 0, 1), 5, 5), RayIntersection(Point(0, 0, -5), Vector(0, 0, 1), 4, 6), RayIntersection(Point(0.5, 0, -5), Vector(0.1, 1, 1), 6.80798, 7.08872) ] for ray_intersection in ray_intersections: direction = Vector.normalize(ray_intersection.direction) r = Ray(ray_intersection.origin, direction) xs = cyl.local_intersect(r) self.assertEqual(len(xs), 2) self.assertAlmostEqual(xs[0].t, ray_intersection.t0, delta=Constants.epsilon) self.assertAlmostEqual(xs[1].t, ray_intersection.t1, delta=Constants.epsilon)
def main() -> None: pg.init() pg.display.set_caption("Cylinder") screen = pg.display.set_mode((const.WIDTH, const.HEIGHT)) screen.fill(const.WHITE) clock = pg.time.Clock() cylinder = Cylinder(size=(const.WIDTH, const.HEIGHT)) running = True while running: screen.fill(const.WHITE) clock.tick(const.FPS) screen.blit(cylinder, (0, 0)) for event in pg.event.get(): if event.type == pg.QUIT: running = False cylinder.update() pg.display.flip()
def FitCylinder(self, cloud, viewPoints, viewPointIndices, k): '''Utilizes Matlab's cylinder fitting capabilities for point clouds.''' mCloud = matlab.double(cloud.tolist()) mViewPoints = matlab.double(viewPoints.tolist()) mViewPointIndices = matlab.int32(viewPointIndices.tolist(), size=(1, len(viewPointIndices))) plotBitmap = matlab.logical([False, False, False, False]) mCylinder = self.eng.FitCylinder(mCloud, mViewPoints, mViewPointIndices, k, plotBitmap) center = array(mCylinder["center"]).flatten() axis = array(mCylinder["axis"]).flatten() radius = mCylinder["radius"] height = mCylinder["height"] return Cylinder(center, axis, radius, height)
def __spawnCylinderTypeObject(self, obj): pos = [ self.position[0] + obj['local_pos'][0], self.position[1] + obj['local_pos'][1], self.position[2] + obj['local_pos'][2] ] scale = obj['local_scale'] model_path = obj['path'] obj_col_pos = obj['col_pos'] quat = obj['local_quaternion'] col_rad = obj['col_radius'] col_height = obj['col_height'] isStatic = obj['isStatic'] cylinder = Cylinder(pos, scale, model_path, col_rad, col_height, obj_col_pos, quat, isStatic) if 'canCollider' in obj and obj['canCollider'] == "TRUE": self.collision_objects[str(cylinder.colId)] = cylinder self.showcase.add(cylinder.model) return cylinder
def test_normal_vector_cylinder_end_caps(self): cyl = Cylinder() cyl.minimum = 1 cyl.maximum = 2 cyl.closed = True PointNormal = namedtuple("PointNormal", ["point", "normal"]) point_normals = [ PointNormal(Point(0, 1, 0), Vector(0, -1, 0)), PointNormal(Point(0.5, 1, 0), Vector(0, -1, 0)), PointNormal(Point(0, 1, 0.5), Vector(0, -1, 0)), PointNormal(Point(0, 2, 0), Vector(0, 1, 0)), PointNormal(Point(0.5, 2, 0), Vector(0, 1, 0)), PointNormal(Point(0, 2, 0.5), Vector(0, 1, 0)) ] for point_normal in point_normals: n = cyl.local_normal_at(point_normal.point) self.assertEqual(n, point_normal.normal)
def test_interserct_caps_of_closed_cylinder(self): cyl = Cylinder() cyl.minimum = 1 cyl.maximum = 2 cyl.closed = True cyl.maximum = 2 CylinderIntersection = namedtuple("CyliderIntersection", ["point", "direction", "count"]) cylinder_intersections = [ CylinderIntersection(Point(0, 3, 0), Vector(0, -1, 0), 2), CylinderIntersection(Point(0, 3, -2), Vector(0, -1, 2), 2), CylinderIntersection(Point(0, 4, -2), Vector(0, -1, 1), 2), # corner case CylinderIntersection(Point(0, 0, -2), Vector(0, 1, 2), 2), CylinderIntersection(Point(0, -1, -2), Vector(0, 1, 1), 2) # corner case ] for cylinder_intersection in cylinder_intersections: direction = Vector.normalize(cylinder_intersection.direction) r = Ray(cylinder_intersection.point, direction) xs = cyl.local_intersect(r) self.assertEqual(len(xs), cylinder_intersection.count)
from circle import Circle from cylinder import Cylinder from shape import Shape circle = Circle() shape = Shape() print("***Circle Testing***") print(circle.to_string()) print(circle.get_area()) print("\n") print("***Cylinder Testing***") cylinder = Cylinder() print(cylinder.to_string()) print(cylinder.get_area())
S[0, 0] *= factor S[1, 1] *= factor # draw line def draw_triangle(x1, y1, x2, y2, x3, y3): pygame.draw.line(screen, pygame.color.THECOLORS['white'], (x1, y1), (x2, y2), 1) pygame.draw.line(screen, pygame.color.THECOLORS['white'], (x2, y2), (x3, y3), 1) pygame.draw.line(screen, pygame.color.THECOLORS['white'], (x3, y3), (x1, y1), 1) cyl = Cylinder() # translation matrix T = np.eye(4) T[3, 1] = -cyl.get_center_y() T2 = np.eye(4) T2[3, 1] = cyl.get_center_y() T2[3, 2] = 5 # offset on Z axis (from screen) # CAMERA vCamera = np.zeros(3) # load texture image im = Image.open('tex.png') im = im.rotate(180)
from rigid_body import BaseObject from constrains import Coincident, Fixed t = sym.Symbol('t') start = time.time() d_l = 0.5 R = 0.01 rho = 2700 transl = np.array([0, 0, 1]) symbolic_origin = sym.Matrix([0, 0, 0]) origin = BaseObject('origin', 0, symbolic_origin) segment_1 = Cylinder(R, d_l, rho) segment_2 = Cylinder(R, d_l, rho) segment_2.move(transl) joint_1 = Fixed(segment_1, origin, 0) joint_2 = Coincident(segment_2, segment_1, 0, 1) baumgarte_params = [0, 0, 0] pendulum = Mechanism([segment_1, segment_2], [joint_1, joint_2], baumgarte_params) coeff = pendulum.global_mass_matrix.row_join(pendulum.phi_r) sym.pprint(pendulum.coefficient_mtx.shape)
def test_intersecting_a_constrained_cylinder(self): cyl = Cylinder(1, 2) direction = Vector(0.1, 1, 0) r = Ray(Point(0, 1.5, 0), direction) xs = cyl.local_intersect(r) self.assertEqual(xs.count, 0)
def test_default_minimum_and_maximum_for_a_cylinder(self): cyl = Cylinder() self.assertEqual(cyl.minimum, float('-inf')) self.assertEqual(cyl.maximum, float('inf'))
def test_normal_vector_on_a_cylinder(self): cyl = Cylinder() n = cyl.local_normal_at(Point(-1, 1, 0)) self.assertTrue(Vector(-1, 0, 0) == n)
return tmp # parsing JSON file with open(FILE) as json_file: data = json.load(json_file) for f in data['figures']: if f['type'] == "cones": for cone in f['params']: temp_con = Cone(cone['x'], cone['y'], cone['z'], cone['radius'], cone['height'], cone['density']) cones_arr.append(temp_con) elif f['type'] == "cylinders": for cylinder in f['params']: temp_cylin = Cylinder(cylinder['x'], cylinder['y'], cylinder['z'], \ cylinder['radius'], cylinder['height'], cylinder['density']) cyli_arr.append(temp_cylin) elif f['type'] == "cuboids": for cuboid in f['params']: temp_cuboid = Cuboid(cuboid['x'], cuboid['y'], cuboid['z'], cuboid['a'], cuboid['b'], cuboid['c']) cub_arr.append(temp_cuboid) elif f['type'] == "spheres": for sphere in f['params']: temp_sphere = Sphere(sphere['x'], sphere['y'], sphere['z'], sphere['radius'], \ sphere['meridians'], sphere['parallels']) sphere_arr.append(temp_sphere) # Global variables, matrices, and triggers aspect = width / height FOV = cos(pi / 4) / sin(pi / 4)
# Informações dos cones altura_cone = 8 raio_cone = 2 vetor_unitario_cone = Coordinate(0, 1, 0, 0) centro_base_cone1 = Coordinate(1.4142, 0, -11.3137, 1) centro_base_cone2 = Coordinate(-2.8284, 0, -15.5563, 1) # Inicializando raio e chapa raio = Ray(p0) chapa = Plate(tamanho_chapa, numero_furos_chapa, distancia_chapa) # Inicializando objetos cubo1 = Cube(centro_base_cubo1, aresta_cubo) cubo2 = Cube(centro_base_cubo2, aresta_cubo) cubo3 = Cube(centro_base_cubo3, aresta_cubo) cilindro1 = Cylinder(centro_base_cilindro1, vetor_unitario_cilindro, altura_cilindo, raio_cilindro) cone1 = Cone(centro_base_cone1, vetor_unitario_cone, altura_cone, raio_cone) cilindro2 = Cylinder(centro_base_cilindro2, vetor_unitario_cilindro, altura_cilindo, raio_cilindro) cone2 = Cone(centro_base_cone2, vetor_unitario_cone, altura_cone, raio_cone) # Colorindo objetos para facilitar identificacao cubo1.color = (46, 119, 187) cubo2.color = (29, 131, 195) cubo3.color = (39, 174, 227) imagem = Image.new('RGB', (numero_furos_chapa, numero_furos_chapa)) for l in range(chapa.number_of_holes): for c in range(chapa.number_of_holes): colisoes = []
def test_unbounded_cylinder_bounding_box(self): shape = Cylinder() box = shape.bounds_of() self.assertEqual(box.min, Point(-1, -math.inf, -1)) self.assertEqual(box.max, Point(1, math.inf, 1))
def keyPressed(*args): global camera global lineVision global objVision key=glutGetModifiers() #print(args[0]) # If escape is pressed, kill everything. if args[0]==ESCAPE: sys.exit() elif args[0] == b'z': scene.objects[0].rotate_point_z(10,scene.objects[0].center) elif args[0] == b"x": scene.objects[0].rotate_point_x(10,scene.objects[0].center) elif args[0] == b"c": scene.objects[0].rotate_point_y(10,scene.objects[0].center) elif args[0] == b"b": scene.objects[0].increase_subdivisions() elif args[0] == b"n": scene.objects[0].decrease_subdivisions() elif args[0] == b"w": camera.move_forward(.1) elif args[0] == b"s": camera.move_backward(.1) elif args[0] == b"1": scene.cleanScene() scene.addObject(Sphere(18,12,1)) scene.addObject(grid) elif args[0] == b"2": scene.cleanScene() scene.addObject(Torus(11,11,.3,1)) scene.addObject(grid) elif args[0] == b"3": scene.cleanScene() scene.addObject(Cylinder(2,11,0.08)) scene.addObject(grid) elif args[0] == b"4": scene.cleanScene() scene.addObject(Box(1,1,1)) scene.addObject(grid) elif args[0] == b"5": scene.cleanScene() scene.addObject(Pyramid(.4)) scene.addObject(grid) elif args[0] == b"6": scene.cleanScene() scene.addObject(Icosahedron()) scene.addObject(grid) elif args[0] == b"7": scene.cleanScene() scene.addObject(Octahedron(1,3)) scene.addObject(grid) elif args[0] == b"l": lineVision=True objVision=False elif args[0] == b"o": lineVision=False objVision=True elif args[0] == b"p": lineVision=True objVision=True elif args[0] == b"f": camera=Camera(Vec3d(0,0,5),Vec3d(0,0,-1))
def test_default_minimum_maximum_cylinder(self): cyl = Cylinder() self.assertEqual(cyl.minimum, -math.inf) self.assertEqual(cyl.maximum, math.inf)
def __init__(self, factory, radii, heights, layers_lcs, transform_data, layers_physical_names, transfinite_r_data, transfinite_h_data, transfinite_phi_data, divide_r_data, divide_h_data, straight_boundary=None, layers_surfaces_names=None, surfaces_names=None, volumes_names=None): """ Divided multilayer cylinder for boolean operations :param str factory: see Cylinder :param list of float radii: see Cylinder :param list of float heights: see Cylinder :param list of list of float layers_lcs: see Cylinder :param list of float transform_data: see Cylinder :param list of list of str layers_physical_names: see Cylinder :param list of list of float transfinite_r_data: see Cylinder :param list of list of float transfinite_h_data: see Cylinder :param list of float transfinite_phi_data: see Cylinder :param list of int divide_r_data: [number of r1 parts, number of r2 parts, ..., number of rN parts] :param list of int divide_h_data: [number of h1 parts, number of h2 parts, ..., number of hM parts] :param list of int straight_boundary: See Cylinder :param list of list of int layers_surfaces_names: See Cylinder :param list of str surfaces_names: See Cylinder :param list of str volumes_names: See Cylinder :return None """ new_radii = list() new_heights = list() new_layers_physical_names = list() new_primitives_lcs = list() new_transfinite_r_data = list() new_transfinite_h_data = list() map_new_to_old_r = dict() map_old_to_new_r = dict() map_old_to_new_h = dict() map_new_to_old_h = dict() if straight_boundary is None: straight_boundary = [1] for _ in range(len(radii) - 1): straight_boundary.append(3) if divide_r_data is None: divide_r_data = [1 for _ in radii] if divide_h_data is None: divide_h_data = [1 for _ in heights] if layers_lcs is None: layers_lcs = [[1 for _ in radii] for _ in heights] # Evaluate new radii for i, n in enumerate(divide_r_data): map_old_to_new_r[i] = list() if i == 0: r0 = 0 r1 = radii[i] else: r0 = radii[i - 1] r1 = radii[i] delta_r = float(r1 - r0) # total delta dr = delta_r / n # increment delta r = r0 # new r for j in range(n): r += dr new_radii.append(r) new_i = len(new_radii) - 1 map_old_to_new_r[i].append(new_i) map_new_to_old_r[new_i] = i # Evaluate new heights for i, n in enumerate(divide_h_data): map_old_to_new_h[i] = list() h0 = 0 h1 = heights[i] delta_h = float(h1 - h0) # total delta dh = delta_h / n # increment delta for j in range(n): new_heights.append(dh) new_i = len(new_heights) - 1 map_old_to_new_h[i].append(new_i) map_new_to_old_h[new_i] = i # Evaluate new 1d arrays for i, h in enumerate(new_heights): old_i = map_new_to_old_h[i] new_transfinite_h_data.append(transfinite_h_data[old_i]) for j, r in enumerate(new_radii): old_j = map_new_to_old_r[j] new_transfinite_r_data.append(transfinite_r_data[old_j]) # Evaluate new 2d arrays for i, h in enumerate(new_heights): old_i = map_new_to_old_h[i] radii_lcs = list() radii_physical_names = list() for j, r in enumerate(new_radii): old_j = map_new_to_old_r[j] radii_lcs.append(layers_lcs[old_i][old_j]) radii_physical_names.append( layers_physical_names[old_i][old_j]) new_primitives_lcs.append(radii_lcs) new_layers_physical_names.append(radii_physical_names) # pprint(map_old_to_new_r) # pprint(map_old_to_new_h) # print(new_radii) # print(new_heights) # print(new_layers_physical_names) # print(new_primitives_lcs) # print(new_transfinite_r_data) # print(new_transfinite_h_data) Cylinder.__init__(self, factory, new_radii, new_heights, new_primitives_lcs, transform_data, new_layers_physical_names, new_transfinite_r_data, new_transfinite_h_data, transfinite_phi_data, straight_boundary, layers_surfaces_names, surfaces_names, volumes_names)
def test_cylinder_default_closed_value(self): cyl = Cylinder() self.assertFalse(cyl.closed)
def test_a_ray_misses_a_cylinder3(self): cyl = Cylinder() direction = Vector(1, 1, 1).normalize() r = Ray(Point(0, 0, -5), direction) xs = cyl.local_intersect(r) self.assertEqual(0, xs.count)