factory_test.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:Splipy 作者: sintefmath 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号