def test_surface_torus(self): # default torus surf = SurfaceFactory.torus(1, 3) start = surf.start() end = surf.end() # check a 13 evaluation points of v-evaluation (around the z-axis) v = np.linspace(start[1], end[1], 13) # check minor-circle u=0 (outmost ring) x = surf.evaluate(0, v) for pt in np.array(x[0, :, :]): self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], 4 * 4) # check radius=4 self.assertAlmostEqual(pt[2], 0) # check height=0 # check minor-circle u=pi (innermost ring) x = surf.evaluate(pi, v) 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], 0) # check height=0 # check minor-circle u=pi/2 (topmost ring) x = surf.evaluate(pi / 2, v) for pt in np.array(x[0, :, :]): self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], 3 * 3) # check radius=3 self.assertAlmostEqual(pt[2], 1) # check height=1 # check minor-circle u=3*pi/2 (mid-evaluation) x = surf.evaluate(3 * pi / 4, v) for pt in np.array(x[0, :, :]): self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], (3 - 1.0 / sqrt(2))**2) # check radius=3-1/sqrt(2) self.assertAlmostEqual(pt[2], 1.0 / sqrt(2)) # check height=1/sqrt(2)
def test_surface_torus(self): # default torus surf = sf.torus(1, 3) start = surf.start() end = surf.end() # check a 13 evaluation points of v-evaluation (around the z-axis) v = np.linspace(start[1], end[1], 13) # check minor-circle u=0 (outmost ring) x = surf.evaluate(0, v) for pt in np.array(x[0, :, :]): self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], 4 * 4) # check radius=4 self.assertAlmostEqual(pt[2], 0) # check height=0 # check minor-circle u=pi (innermost ring) x = surf.evaluate(pi, v) 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], 0) # check height=0 # check minor-circle u=pi/2 (topmost ring) x = surf.evaluate(pi / 2, v) for pt in np.array(x[0, :, :]): self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], 3 * 3) # check radius=3 self.assertAlmostEqual(pt[2], 1) # check height=1 # check minor-circle u=3*pi/2 (mid-evaluation) x = surf.evaluate(3 * pi / 4, v) for pt in np.array(x[0, :, :]): self.assertAlmostEqual( pt[0] * pt[0] + pt[1] * pt[1], (3 - 1.0 / sqrt(2))**2) # check radius=3-1/sqrt(2) self.assertAlmostEqual(pt[2], 1.0 / sqrt(2)) # check height=1/sqrt(2)
def torus(self): dim = int( self.read_next_non_whitespace().strip()) r2 = float( next(self.fstream).strip()) r1 = float( next(self.fstream).strip()) center = np.array(next(self.fstream).split(), dtype=float) z_axis = np.array(next(self.fstream).split(), dtype=float) x_axis = np.array(next(self.fstream).split(), dtype=float) select_out= next(self.fstream).strip() != '0' # I have no idea what this does :( param_u = np.array(next(self.fstream).split(), dtype=float) param_v = np.array(next(self.fstream).split(), dtype=float) swap = next(self.fstream).strip() != '0' result = SurfaceFactory.torus(minor_r=r1, major_r=r2, center=center, normal=z_axis, xaxis=x_axis) result.reparam(param_u, param_v) if(swap): result.swap() return result
def test_periodic_split(self): # create a double-periodic spline on the knot vector [-1,0,0,1,1,2,2,3,3,4,4,5]*pi/2 surf = sf.torus() surf2 = surf.split(pi / 2, 0) # split on existing knot surf3 = surf.split(1.23, 1) # split between knots surf4 = surf2.split(pi, 1) # split both periodicities # check periodicity tags self.assertEqual(surf.periodic(0), True) self.assertEqual(surf.periodic(1), True) self.assertEqual(surf2.periodic(0), False) self.assertEqual(surf2.periodic(1), True) self.assertEqual(surf3.periodic(0), True) self.assertEqual(surf3.periodic(1), False) self.assertEqual(surf4.periodic(0), False) self.assertEqual(surf4.periodic(1), False) # check parametric domain boundaries self.assertAlmostEqual(surf2.start(0), pi / 2) self.assertAlmostEqual(surf2.end(0), 5 * pi / 2) self.assertAlmostEqual(surf3.start(0), 0) self.assertAlmostEqual(surf3.end(0), 2 * pi) self.assertAlmostEqual(surf3.start(1), 1.23) self.assertAlmostEqual(surf3.end(1), 1.23 + 2 * pi) # check knot vector lengths self.assertEqual(len(surf2.knots(0, True)), 12) self.assertEqual(len(surf2.knots(1, True)), 12) self.assertEqual(len(surf3.knots(0, True)), 12) self.assertEqual(len(surf3.knots(1, True)), 14) self.assertEqual(len(surf4.knots(0, True)), 12) self.assertEqual(len(surf4.knots(1, True)), 12) # check that evaluation is unchanged over a 9x9 grid of shared parametric coordinates u = np.linspace(pi / 2, 2 * pi, 9) v = np.linspace(pi, 2 * pi, 9) pt = surf(u, v) pt2 = surf2(u, v) pt3 = surf3(u, v) pt4 = surf4(u, v) self.assertAlmostEqual(np.linalg.norm(pt - pt2), 0.0) self.assertAlmostEqual(np.linalg.norm(pt - pt3), 0.0) self.assertAlmostEqual(np.linalg.norm(pt - pt4), 0.0)
# Examples on how to write geometries to file # # Author: Kjetil Andre Johannessen # Institute: Norwegian University of Science and Technology (NTNU) # Date: March 2016 # from sys import path path.append('../') from splipy.io import G2, STL import splipy.surface_factory as surfaces # create a NURBS torus torus = surfaces.torus(minor_r=1, major_r=4) # STL files are tessellated linear triangles. View with i.e. meshlab with STL('torus.stl') as my_file: my_file.write(torus, n=(50, 150)) # specify resolution of 50x150 evaluation pts # G2 files are native GoTools (http://www.sintef.no/projectweb/geometry-toolkits/gotools/) with G2('torus.g2') as my_file: my_file.write(torus)