Example #1
0
    def derivatives(self, u=-1, order=0):
        """ Evaluates n-th order curve derivatives at the given u from the rational curve.

        :param u: knot value
        :type u: float
        :param order: derivative order
        :type order: integer
        :return: A list containing up to {order}-th derivative of the curve
        :rtype: list
        """
        # Call the parent function to evaluate A(u) and w(u) derivatives
        CKw = super(Curve, self).derivatives(u, order)

        # Algorithm A4.2
        CK = [[None for x in range(self._dimension - 1)]
              for y in range(order + 1)]
        for k in range(0, order + 1):
            v = []
            for idx in range(self._dimension - 1):
                v.append(CKw[idx])

            for i in range(1, order + 1):
                v[:] = [
                    tmp - (utils.binomial_coefficient(k, i) * CKw[i][-1] * drv)
                    for tmp, drv in zip(v, CK[k - i])
                ]
            CK[k][:] = [tmp / CKw[0][-1] for tmp in v]

        # Return C(u) derivatives
        return CK
Example #2
0
def test_binomial_coefficient3():
    result = 680.0
    to_check = utilities.binomial_coefficient(17, 3)
    assert to_check == result
Example #3
0
def test_binomial_coefficient2():
    result = 1.0
    to_check = utilities.binomial_coefficient(13, 13)
    assert to_check == result
Example #4
0
def test_binomial_coefficient1():
    result = 0.0
    to_check = utilities.binomial_coefficient(13, 14)
    assert to_check == result
Example #5
0
    def derivatives(self, u=-1, v=-1, order=0):
        """ Evaluates n-th order surface derivatives at the given (u,v) parameter from the rational surface.

        * SKL[0][0] will be the surface point itself
        * SKL[0][1] will be the 1st derivative w.r.t. v
        * SKL[2][1] will be the 2nd derivative w.r.t. u and 1st derivative w.r.t. v

        :param u: parameter in the U direction
        :type u: float
        :param v: parameter in the V direction
        :type v: float
        :param order: derivative order
        :type order: integer
        :return: A list SKL, where SKL[k][l] is the derivative of the surface S(u,v) w.r.t. u k times and v l times
        :rtype: list
        """
        # Call the parent function to evaluate A(u) and w(u) derivatives
        SKLw = super(Surface, self).derivatives(u, v, order)

        # Algorithm A4.4
        du = min(self._degree_u, order)
        dv = min(self._degree_v, order)

        # Generate an empty list of derivatives
        SKL = [[[None for x in range(self._dimension)] for y in range(dv + 1)]
               for z in range(du + 1)]

        for k in range(0, order + 1):
            for l in range(0, order - k + 1):
                v = []
                for idx in range(self._dimension - 1):
                    v.append(SKLw[idx])

                for j in range(1, l + 1):
                    v[:] = [
                        tmp - (utils.binomial_coefficient(l, j) *
                               SKLw[0][j][-1] * drv)
                        for tmp, drv in zip(v, SKL[k][l - j])
                    ]
                for i in range(1, k + 1):
                    v[:] = [
                        tmp - (utils.binomial_coefficient(k, i) *
                               SKLw[i][0][-1] * drv)
                        for tmp, drv in zip(v, SKL[k - i][l])
                    ]
                    v2 = [0.0 for x in range(self._dimension - 1)]
                    for j in range(1, l + 1):
                        v2[:] = [
                            tmp + (utils.binomial_coefficient(l, j) *
                                   SKLw[i][j][-1] * drv)
                            for tmp, drv in zip(v2, SKL[k - i][l - j])
                        ]
                    v[:] = [
                        tmp - (utils.binomial_coefficient(k, i) * tmp2)
                        for tmp, tmp2 in zip(v, v2)
                    ]

                SKL[k][l][:] = [tmp / SKLw[0][0][-1] for tmp in v]

        # Return S(u,v) derivatives
        return SKL