def test_n_gon(self): # test default 5 side n-gon c = CurveFactory.n_gon() self.assertEqual(len(c), 5) self.assertEqual(len(c.knots(0, True)), 8) self.assertEqual(c.order(0), 2) # evaluate at second corner (clockwise from (1,0) ) self.assertAlmostEqual(c.evaluate(c.end(0) / 5.0)[0], cos(2 * pi / 5)) self.assertAlmostEqual(c.evaluate(c.end(0) / 5.0)[1], sin(2 * pi / 5)) # evaluate at fourh corner (clockwise from (1,0) ) self.assertAlmostEqual(c.evaluate(c.end(0) / 5.0 * 4)[0], cos(2 * pi / 5 * 4)) self.assertAlmostEqual(c.evaluate(c.end(0) / 5.0 * 4)[1], sin(2 * pi / 5 * 4)) # test a radius 3 septagon c = CurveFactory.n_gon(n=7, r=3) self.assertEqual(len(c), 7) # evaluate at third corner (clockwise from (1,0) ) self.assertAlmostEqual(c.evaluate(c.end(0) / 7.0)[0], 3 * cos(2 * pi / 7)) self.assertAlmostEqual(c.evaluate(c.end(0) / 7.0)[1], 3 * sin(2 * pi / 7)) # test errors with self.assertRaises(ValueError): c = CurveFactory.n_gon(r=-2.5) with self.assertRaises(ValueError): c = CurveFactory.n_gon(n=1)
def test_n_gon(self): # test default 5 side n-gon c = cf.n_gon() self.assertEqual(len(c), 5) self.assertEqual(len(c.knots(0, True)), 8) self.assertEqual(c.order(0), 2) # evaluate at second corner (clockwise from (1,0) ) self.assertAlmostEqual(c.evaluate(c.end(0) / 5.0)[0], cos(2 * pi / 5)) self.assertAlmostEqual(c.evaluate(c.end(0) / 5.0)[1], sin(2 * pi / 5)) # evaluate at fourh corner (clockwise from (1,0) ) self.assertAlmostEqual( c.evaluate(c.end(0) / 5.0 * 4)[0], cos(2 * pi / 5 * 4)) self.assertAlmostEqual( c.evaluate(c.end(0) / 5.0 * 4)[1], sin(2 * pi / 5 * 4)) # test a radius 3 septagon c = cf.n_gon(n=7, r=3) self.assertEqual(len(c), 7) # evaluate at third corner (clockwise from (1,0) ) self.assertAlmostEqual( c.evaluate(c.end(0) / 7.0)[0], 3 * cos(2 * pi / 7)) self.assertAlmostEqual( c.evaluate(c.end(0) / 7.0)[1], 3 * sin(2 * pi / 7)) # test errors with self.assertRaises(ValueError): c = cf.n_gon(r=-2.5) with self.assertRaises(ValueError): c = cf.n_gon(n=1)
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