Exemplo n.º 1
0
    def test_cylinder_surface(self):
        # unit cylinder
        surf = sf.cylinder()
        # test 7x7 grid for xy-radius = 1 and v=z
        for u in np.linspace(surf.start()[0], surf.end()[0], 7):
            for v in np.linspace(surf.start()[1], surf.end()[1], 7):
                x = surf(u, v)
                self.assertAlmostEqual(np.linalg.norm(x[:2], 2),
                                       1.0)  # (x,y) coordinates to z-axis
                self.assertAlmostEqual(x[2],
                                       v)  # z coordinate should be linear
        self.assertAlmostEqual(surf.area(), 2 * pi, places=3)

        # cylinder with parameters
        surf = sf.cylinder(r=2, h=5, center=(0, 0, 1), axis=(1, 0, 0))
        for u in np.linspace(surf.start()[0], surf.end()[0], 7):
            for v in np.linspace(surf.start()[1], surf.end()[1], 7):
                x = surf(u, v)
                self.assertAlmostEqual(x[1]**2 + (x[2] - 1)**2,
                                       2.0**2)  # distance to (z-1)=y=0
                self.assertAlmostEqual(x[0],
                                       v * 5)  # x coordinate should be linear
        self.assertAlmostEqual(surf.area(), 2 * 2 * pi * 5, places=3)

        # test xaxis
        surf = sf.cylinder(r=sqrt(2), xaxis=(1, 1, 0))
        self.assertTrue(np.allclose(surf(0, 0), [1, 1, 0]))
Exemplo n.º 2
0
    def cylinder(self):
        dim = int(self.read_next_non_whitespace().strip())
        r = 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)
        finite = next(self.fstream).strip() != '0'
        param_u = np.array(next(self.fstream).split(), dtype=float)
        if finite:
            param_v = np.array(next(self.fstream).split(), dtype=float)
        else:
            param_v = [-state.unlimited, state.unlimited]
        swap = next(self.fstream).strip() != '0'

        center = center + z_axis * param_v[0]
        h = param_v[1] - param_v[0]
        result = SurfaceFactory.cylinder(r=r,
                                         center=center,
                                         xaxis=x_axis,
                                         axis=z_axis,
                                         h=h)
        result.reparam(param_u, param_v)
        if swap:
            result.swap()
        return result
Exemplo n.º 3
0
 def test_cylinder_surface(self):
     # unit cylinder
     surf = SurfaceFactory.cylinder()
     # test 7x7 grid for xy-radius = 1 and v=z
     for u in np.linspace(surf.start()[0], surf.end()[0], 7):
         for v in np.linspace(surf.start()[1], surf.end()[1], 7):
             x = surf(u, v)
             self.assertAlmostEqual(np.linalg.norm(x[:2], 2), 1.0)  # (x,y) coordinates to z-axis
             self.assertAlmostEqual(x[2], v)  # z coordinate should be linear
     self.assertAlmostEqual(surf.area(), 2*pi, places=3)
    def test_cylinder_surface(self):
        # unit cylinder
        surf = SurfaceFactory.cylinder()
        # test 7x7 grid for xy-radius = 1 and v=z
        for u in np.linspace(surf.start()[0], surf.end()[0], 7):
            for v in np.linspace(surf.start()[1], surf.end()[1], 7):
                x = surf(u, v)
                self.assertAlmostEqual(np.linalg.norm(x[:2], 2), 1.0)  # (x,y) coordinates to z-axis
                self.assertAlmostEqual(x[2], v)  # z coordinate should be linear
        self.assertAlmostEqual(surf.area(), 2*pi, places=3)

        # cylinder with parameters
        surf = SurfaceFactory.cylinder(r=2, h=5, center=(0,0,1), axis=(1,0,0))
        for u in np.linspace(surf.start()[0], surf.end()[0], 7):
            for v in np.linspace(surf.start()[1], surf.end()[1], 7):
                x = surf(u, v)
                self.assertAlmostEqual(x[1]**2+(x[2]-1)**2, 2.0**2) # distance to (z-1)=y=0
                self.assertAlmostEqual(x[0], v*5)                   # x coordinate should be linear
        self.assertAlmostEqual(surf.area(), 2*2*pi*5, places=3)

        # test xaxis
        surf = SurfaceFactory.cylinder(r=sqrt(2), xaxis=(1,1,0))
        self.assertTrue(np.allclose(surf(0,0), [1,1,0]))
Exemplo n.º 5
0
    def cylinder(self):
        dim      = int(     self.read_next_non_whitespace().strip())
        r        = 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)
        finite   =          next(self.fstream).strip() != '0'
        param_u  = np.array(next(self.fstream).split(), dtype=float)
        if finite:
            param_v=np.array(next(self.fstream).split(), dtype=float)
        else:
            param_v=[-state.unlimited, state.unlimited]
        swap     =          next(self.fstream).strip() != '0'

        center = center + z_axis*param_v[0]
        h      = param_v[1] - param_v[0]
        result = SurfaceFactory.cylinder(r=r, center=center, xaxis=x_axis, axis=z_axis, h=h)
        result.reparam(param_u, param_v)
        if swap:
            result.swap()
        return result