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 __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_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 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_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_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 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 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 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 __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_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 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)
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 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)
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)
# 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_default_minimum_maximum_cylinder(self): cyl = Cylinder() self.assertEqual(cyl.minimum, -math.inf) self.assertEqual(cyl.maximum, math.inf)
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))
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())
def test_cylinder_default_closed_value(self): cyl = Cylinder() self.assertFalse(cyl.closed)
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)
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))