def test_revolve(self): # square torus square = CurveFactory.n_gon(4) square.rotate(pi / 2, (1, 0, 0)) square.translate((2, 0, 0)) # in xz-plane with corners at (3,0),(2,1),(1,0),(2,-1) surf = SurfaceFactory.revolve(square) surf.reparam() # set parametric space to (0,1)^2 v = np.linspace(0, 1, 13) x = surf.evaluate(0, v) # outer ring evaluation u=0 for pt in np.array(x[0, :, :]): self.assertAlmostEqual(np.linalg.norm(pt, 2), 3.0) # check radius=3 x = surf.evaluate(.25, v) # top ring evaluation u=.25 for pt in np.array(x[0, :, :]): self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], 2 * 2) # check radius=2 self.assertAlmostEqual(pt[2], 1) # check height=1 x = surf.evaluate(.375, v) # mid inner ring evaluation u=.375 for pt in np.array(x[0, :, :]): self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], 1.5 * 1.5) # check radius=1.5 self.assertAlmostEqual(pt[2], .5) # check height=0.5 # incomplete revolve c = CurveFactory.line([1,0], [0,1], relative=True) surf = SurfaceFactory.revolve(c, theta=4.2222, axis=[0,1,0]) surf.reparam() u = np.linspace(0,1,7) v = np.linspace(0,1,7) x = surf(u,v) for uPt in x: for pt in uPt: self.assertAlmostEqual(pt[0]**2 + pt[2]**2, 1.0) # radius 1 from y-axis
def test_revolve(self): # square torus square = cf.n_gon(4) square.rotate(pi / 2, (1, 0, 0)) square.translate( (2, 0, 0)) # in xz-plane with corners at (3,0),(2,1),(1,0),(2,-1) surf = sf.revolve(square) surf.reparam() # set parametric space to (0,1)^2 v = np.linspace(0, 1, 13) x = surf.evaluate(0, v) # outer ring evaluation u=0 for pt in np.array(x[0, :, :]): self.assertAlmostEqual(np.linalg.norm(pt, 2), 3.0) # check radius=3 x = surf.evaluate(.25, v) # top ring evaluation u=.25 for pt in np.array(x[0, :, :]): self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], 2 * 2) # check radius=2 self.assertAlmostEqual(pt[2], 1) # check height=1 x = surf.evaluate(.375, v) # mid inner ring evaluation u=.375 for pt in np.array(x[0, :, :]): self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], 1.5 * 1.5) # check radius=1.5 self.assertAlmostEqual(pt[2], .5) # check height=0.5 # incomplete revolve c = cf.line([1, 0], [0, 1], relative=True) surf = sf.revolve(c, theta=4.2222, axis=[0, 1, 0]) surf.reparam() u = np.linspace(0, 1, 7) v = np.linspace(0, 1, 7) x = surf(u, v) for uPt in x: for pt in uPt: self.assertAlmostEqual(pt[0]**2 + pt[2]**2, 1.0) # radius 1 from y-axis
def test_2d_self_connection(self): c = curve_factory.line([1, 0], [2, 0]) surf = surface_factory.revolve(c) surf = surf.split(surf.knots('v')[0], direction='v') # break periodicity surf.set_dimension(2) model = SplineModel(2, 2) model.add(surf) writer = IFEMWriter(model) expected = [IFEMConnection(1, 1, 3, 4, 0)] for connection, want in zip(writer.connections(), expected): self.assertEqual(connection, want)
c1 = curves.circle_segment(pi/3) c2 = c1.clone().rotate(2*pi/3) + [1,0] c3 = c1.clone().rotate(4*pi/3) + [cos(pi/3), sin(pi/3)] # merge the three circles into one, and center it at the origin c = c1.append(c2).append(c3) c -= c.center() # plot the reuleaux triangle t = np.linspace(c.start(0), c.end(0), 151) # 151 parametric evaluation points x = c(t) # evaluate (x,y)-coordinates plt.plot(x[:,0], x[:,1]) plt.axis('equal') plt.show() # split the triangle in two, and align this with the y-axis two_parts = c.split((c.start(0) + c.end(0)) / 2.0) half_curve = two_parts[0].rotate(2*pi/3) # create a surface by revolving around its symmetry axis (y-axis) surf = surfaces.revolve(half_curve, axis=[0,1,0]) # plot the resulting surface on a uniform grid of 71x71 evaluation points u = np.linspace(surf.start(0), surf.end(0), 71) v = np.linspace(surf.start(1), surf.end(1), 71) x = surf(u,v) ax = plt.figure().gca(projection='3d') ax.plot_wireframe(x[:,:,0], x[:,:,1], x[:,:,2]) plt.show()
# create the three sides of the triangle, each consisting of a circle segment c1 = curves.circle_segment(pi / 3) c2 = c1.clone().rotate(2 * pi / 3) + [1, 0] c3 = c1.clone().rotate(4 * pi / 3) + [cos(pi / 3), sin(pi / 3)] # merge the three circles into one, and center it at the origin c = c1.append(c2).append(c3) c -= c.center() # plot the reuleaux triangle t = np.linspace(c.start(0), c.end(0), 151) # 151 parametric evaluation points x = c(t) # evaluate (x,y)-coordinates plt.plot(x[:, 0], x[:, 1]) plt.axis('equal') plt.show() # split the triangle in two, and align this with the y-axis two_parts = c.split((c.start(0) + c.end(0)) / 2.0) half_curve = two_parts[0].rotate(2 * pi / 3) # create a surface by revolving around its symmetry axis (y-axis) surf = surfaces.revolve(half_curve, axis=[0, 1, 0]) # plot the resulting surface on a uniform grid of 71x71 evaluation points u = np.linspace(surf.start(0), surf.end(0), 71) v = np.linspace(surf.start(1), surf.end(1), 71) x = surf(u, v) ax = plt.figure().gca(projection='3d') ax.plot_wireframe(x[:, :, 0], x[:, :, 1], x[:, :, 2]) plt.show()