コード例 #1
0
    def plane(self):
        dim        = int(     self.read_next_non_whitespace().strip())
        center     = np.array(next(self.fstream).split(), dtype=float)
        normal     = np.array(next(self.fstream).split(), dtype=float)
        x_axis     = np.array(next(self.fstream).split(), dtype=float)
        finite     =          next(self.fstream).strip() != '0'
        if finite:
            param_u= np.array(next(self.fstream).split(), dtype=float)
            param_v= np.array(next(self.fstream).split(), dtype=float)
        else:
            param_u= [-state.unlimited, +state.unlimited]
            param_v= [-state.unlimited, +state.unlimited]
        swap       =          next(self.fstream).strip() != '0'

        result = Surface() * [param_u[1]-param_u[0], param_v[1]-param_v[0]] + [param_u[0],param_v[0]]
        result.rotate(rotate_local_x_axis(x_axis, normal))
        result = flip_and_move_plane_geometry(result,center,normal)
        result.reparam(param_u, param_v)
        if(swap):
            result.swap()
        return result
コード例 #2
0
    def test_swap(self):
        # more or less random 3D surface with p=[2,2] and n=[4,3]
        controlpoints = [[0, 0, 1], [-1, 1, 1], [0, 2, 1], [1, -1, 1],
                         [1, 0, .5], [1, 1, 1], [2, 1, 1], [2, 2, .5],
                         [2, 3, 1], [3, 0, 1], [4, 1, 1], [3, 2, 1]]
        basis1 = BSplineBasis(3, [0, 0, 0, .64, 2, 2, 2])
        basis2 = BSplineBasis(3, [0, 0, 0, 1, 1, 1])
        surf = Surface(basis1, basis2, controlpoints)

        evaluation_point1 = surf(0.23, .56)
        control_point1 = surf[1]  # this is control point i=(1,0), when n=(4,3)
        surf.swap()
        evaluation_point2 = surf(0.56, .23)
        control_point2 = surf[3]  # this is control point i=(0,1), when n=(3,4)

        # ensure that surface has not chcanged, by comparing evaluation of it
        self.assertAlmostEqual(evaluation_point1[0], evaluation_point2[0])
        self.assertAlmostEqual(evaluation_point1[1], evaluation_point2[1])
        self.assertAlmostEqual(evaluation_point1[2], evaluation_point2[2])

        # check that the control points have re-ordered themselves
        self.assertEqual(control_point1[0], control_point2[0])
        self.assertEqual(control_point1[1], control_point2[1])
        self.assertEqual(control_point1[2], control_point2[2])
コード例 #3
0
    def test_rational_derivative(self):
        # testing the parametrization x(u,v) = [.5*u^3*(1-v)^3 / ((1-v)^3*(1-u)^3 + .5*u^3*(1-v)^3), 0]
        # dx/du   =  (6*u^2*(u - 1)^2)/(u^3 - 6*u^2 + 6*u - 2)^2
        # d2x/du2 =  -(12*u*(u^5 - 3*u^4 + 2*u^3 + 4*u^2 - 6*u + 2))/(u^3 - 6*u^2 + 6*u - 2)^3
        # d3x/du3 =  (12*(3*u^8 - 12*u^7 + 10*u^6 + 48*u^5 - 156*u^4 + 176*u^3 - 72*u^2 + 4))/(u^3 - 6*u^2 + 6*u - 2)^4
        # dx/dv   =  0
        controlpoints = [[0, 0, 1], [0, 0, 0], [0, 0, 0], [.5, 0, .5],
                         [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0],
                         [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0],
                         [0, 0, 0], [0, 0, 0]]
        basis = BSplineBasis(4)
        surf = Surface(basis, basis, controlpoints, rational=True)

        def expect_derivative(u, v):
            return (6 * u**2 * (u - 1)**2) / (u**3 - 6 * u**2 + 6 * u - 2)**2

        def expect_derivative_2(u, v):
            return -(12 * u *
                     (u**5 - 3 * u**4 + 2 * u**3 + 4 * u**2 - 6 * u + 2)) / (
                         u**3 - 6 * u**2 + 6 * u - 2)**3

        def expect_derivative_3(u, v):
            return (12 * (3 * u**8 - 12 * u**7 + 10 * u**6 + 48 * u**5 -
                          156 * u**4 + 176 * u**3 - 72 * u**2 + 4)) / (
                              u**3 - 6 * u**2 + 6 * u - 2)**4

        # insert a few more knots to spice things up
        surf.insert_knot([.3, .51], 0)
        surf.insert_knot([.41, .53, .92], 1)

        # test first derivatives
        self.assertAlmostEqual(
            surf.derivative(0.32, 0.22, d=(1, 0))[0],
            expect_derivative(0.32, 0.22))
        self.assertAlmostEqual(surf.derivative(0.32, 0.22, d=(1, 0))[1], 0)
        self.assertAlmostEqual(
            surf.derivative(0.71, 0.22, d=(1, 0))[0],
            expect_derivative(0.71, 0.22))
        self.assertAlmostEqual(
            surf.derivative(0.71, 0.62, d=(1, 0))[0],
            expect_derivative(0.71, 0.62))

        # test second derivatives
        self.assertAlmostEqual(
            surf.derivative(0.32, 0.22, d=(2, 0))[0],
            expect_derivative_2(0.32, 0.22))
        self.assertAlmostEqual(
            surf.derivative(0.71, 0.22, d=(2, 0))[0],
            expect_derivative_2(0.71, 0.22))
        self.assertAlmostEqual(
            surf.derivative(0.71, 0.62, d=(2, 0))[0],
            expect_derivative_2(0.71, 0.62))

        # all cross derivatives vanish in this particular example
        self.assertAlmostEqual(surf.derivative(0.32, 0.22, d=(1, 1))[0], 0)
        self.assertAlmostEqual(surf.derivative(0.32, 0.22, d=(2, 1))[0], 0)
        self.assertAlmostEqual(surf.derivative(0.32, 0.22, d=(1, 2))[0], 0)

        # test third derivatives
        self.assertAlmostEqual(
            surf.derivative(0.32, 0.22, d=(3, 0))[0],
            expect_derivative_3(0.32, 0.22))
        self.assertAlmostEqual(
            surf.derivative(0.71, 0.22, d=(3, 0))[0],
            expect_derivative_3(0.71, 0.22))
        self.assertAlmostEqual(
            surf.derivative(0.71, 0.62, d=(3, 0))[0],
            expect_derivative_3(0.71, 0.62))

        # swapping u for v and symmetric logic
        surf.swap()
        self.assertAlmostEqual(
            surf.derivative(0.22, 0.32, d=(0, 2))[0],
            expect_derivative_2(0.32, 0.22))
        self.assertAlmostEqual(
            surf.derivative(0.22, 0.71, d=(0, 2))[0],
            expect_derivative_2(0.71, 0.22))
        self.assertAlmostEqual(
            surf.derivative(0.62, 0.71, d=(0, 2))[0],
            expect_derivative_2(0.71, 0.62))
        self.assertAlmostEqual(
            surf.derivative(0.22, 0.32, d=(0, 3))[0],
            expect_derivative_3(0.32, 0.22))
        self.assertAlmostEqual(
            surf.derivative(0.22, 0.71, d=(0, 3))[0],
            expect_derivative_3(0.71, 0.22))
        self.assertAlmostEqual(
            surf.derivative(0.62, 0.71, d=(0, 3))[0],
            expect_derivative_3(0.71, 0.62))