Exemplo n.º 1
0
    def evaluate_rational(self):
        """ Evaluates the NURBS curve.

        .. note:: The evaluated surface points are stored in :py:attr:`~curvepts`.

        :return: None
        """
        # Check all parameters are set before the curve evaluation
        self._check_variables()
        # Clean up the curve points, if necessary
        self._reset_curve()

        # Algorithm A4.1
        for u in utils.frange(0, 1, self._mDelta):
            span = utils.find_span(self._mDegree, tuple(self._mKnotVector),
                                   len(self._mCtrlPts), u)
            basis = utils.basis_functions(self._mDegree,
                                          tuple(self._mKnotVector), span, u)
            curveptw = [0.0, 0.0, 0.0]
            for i in range(0, self._mDegree + 1):
                curveptw[0] += (basis[i] *
                                (self._mCtrlPts[span - self._mDegree + i][0] *
                                 self._mWeights[span - self._mDegree + i]))
                curveptw[1] += (basis[i] *
                                (self._mCtrlPts[span - self._mDegree + i][1] *
                                 self._mWeights[span - self._mDegree + i]))
                curveptw[2] += (basis[i] *
                                self._mWeights[span - self._mDegree + i])
            # Divide by weight
            curvept = [
                float(curveptw[0] / curveptw[2]),
                float(curveptw[1] / curveptw[2])
            ]
            self._mCurvePts.append(curvept)
Exemplo n.º 2
0
    def evaluate(self):
        """ Evaluates the B-Spline curve.

        .. note:: The evaluated surface points are stored in :py:attr:`~curvepts`.

        :return: None
        """
        # Check all parameters are set before the curve evaluation
        self._check_variables()
        # Clean up the curve points, if necessary
        self._reset_curve()

        # Algorithm A3.1
        for u in utils.frange(0, 1, self._mDelta):
            span = utils.find_span(self._mDegree, tuple(self._mKnotVector),
                                   len(self._mCtrlPts), u)
            basis = utils.basis_functions(self._mDegree,
                                          tuple(self._mKnotVector), span, u)
            curvept = [0.0, 0.0]
            for i in range(0, self._mDegree + 1):
                curvept[0] += (basis[i] *
                               self._mCtrlPts[span - self._mDegree + i][0])
                curvept[1] += (basis[i] *
                               self._mCtrlPts[span - self._mDegree + i][1])
            self._mCurvePts.append(curvept)
Exemplo n.º 3
0
    def evaluate(self):
        """ Evaluates the B-Spline surface.

        .. note:: The evaluated surface points are stored in :py:attr:`~surfpts`.

        :return: None
        """
        # Check all parameters are set before the surface evaluation
        self._check_variables()
        # Clean up the surface points lists, if necessary
        self._reset_surface()

        # Algorithm A3.5
        for v in utils.frange(0, 1, self._mDelta):
            span_v = utils.find_span(self._mDegreeV, tuple(self._mKnotVectorV),
                                     self._mCtrlPts_sizeV, v)
            basis_v = utils.basis_functions(self._mDegreeV,
                                            tuple(self._mKnotVectorV), span_v,
                                            v)
            for u in utils.frange(0, 1, self._mDelta):
                span_u = utils.find_span(self._mDegreeU,
                                         tuple(self._mKnotVectorU),
                                         self._mCtrlPts_sizeU, u)
                basis_u = utils.basis_functions(self._mDegreeU,
                                                tuple(self._mKnotVectorU),
                                                span_u, u)
                idx_u = span_u - self._mDegreeU
                surfpt = [0.0, 0.0, 0.0]
                for l in range(0, self._mDegreeV + 1):
                    temp = [0.0, 0.0, 0.0]
                    idx_v = span_v - self._mDegreeV + l
                    for k in range(0, self._mDegreeU + 1):
                        temp[0] += (basis_u[k] *
                                    self._mCtrlPts2D[idx_u + k][idx_v][0])
                        temp[1] += (basis_u[k] *
                                    self._mCtrlPts2D[idx_u + k][idx_v][1])
                        temp[2] += (basis_u[k] *
                                    self._mCtrlPts2D[idx_u + k][idx_v][2])
                    surfpt[0] += (basis_v[l] * temp[0])
                    surfpt[1] += (basis_v[l] * temp[1])
                    surfpt[2] += (basis_v[l] * temp[2])
                self._mSurfPts.append(surfpt)
Exemplo n.º 4
0
    def evaluate_rational(self):
        """ Evaluates the NURBS surface.

        .. note:: The evaluated surface points are stored in :py:attr:`~surfpts`.

        :return: None
        """
        # Check all parameters are set before the surface evaluation
        self._check_variables()
        # Clean up the surface points lists, if necessary
        self._reset_surface()

        # Prepare a 2D weighted control points array
        ctrlptsw = []
        c_u = 0
        while c_u < self._mCtrlPts_sizeU:
            ctrlptsw_v = []
            c_v = 0
            while c_v < self._mCtrlPts_sizeV:
                temp = [
                    self._mCtrlPts2D[c_u][c_v][0] *
                    self._mWeights[c_u + (c_v * self._mCtrlPts_sizeU)],
                    self._mCtrlPts2D[c_u][c_v][1] *
                    self._mWeights[c_u + (c_v * self._mCtrlPts_sizeU)],
                    self._mCtrlPts2D[c_u][c_v][2] *
                    self._mWeights[c_u + (c_v * self._mCtrlPts_sizeU)],
                    self._mWeights[c_u + (c_v * self._mCtrlPts_sizeU)]
                ]
                ctrlptsw_v.append(temp)
                c_v += 1
            ctrlptsw.append(ctrlptsw_v)
            c_u += 1

        # Algorithm A4.3
        for v in utils.frange(0, 1, self._mDelta):
            span_v = utils.find_span(self._mDegreeV, tuple(self._mKnotVectorV),
                                     self._mCtrlPts_sizeV, v)
            basis_v = utils.basis_functions(self._mDegreeV,
                                            tuple(self._mKnotVectorV), span_v,
                                            v)
            for u in utils.frange(0, 1, self._mDelta):
                span_u = utils.find_span(self._mDegreeU,
                                         tuple(self._mKnotVectorU),
                                         self._mCtrlPts_sizeU, u)
                basis_u = utils.basis_functions(self._mDegreeU,
                                                tuple(self._mKnotVectorU),
                                                span_u, u)
                idx_u = span_u - self._mDegreeU
                surfptw = [0.0, 0.0, 0.0, 0.0]
                for l in range(0, self._mDegreeV + 1):
                    temp = [0.0, 0.0, 0.0, 0.0]
                    idx_v = span_v - self._mDegreeV + l
                    for k in range(0, self._mDegreeU + 1):
                        temp[0] += (basis_u[k] * ctrlptsw[idx_u + k][idx_v][0])
                        temp[1] += (basis_u[k] * ctrlptsw[idx_u + k][idx_v][1])
                        temp[2] += (basis_u[k] * ctrlptsw[idx_u + k][idx_v][2])
                        temp[3] += (basis_u[k] * ctrlptsw[idx_u + k][idx_v][3])
                    surfptw[0] += (basis_v[l] * temp[0])
                    surfptw[1] += (basis_v[l] * temp[1])
                    surfptw[2] += (basis_v[l] * temp[2])
                    surfptw[3] += (basis_v[l] * temp[3])
                # Divide by weight to obtain 3D surface points
                surfpt = [
                    surfptw[0] / surfptw[3], surfptw[1] / surfptw[3],
                    surfptw[2] / surfptw[3]
                ]
                self._mSurfPts.append(surfpt)