def surfpt(self, u=-1, v=-1, check_vars=True, get_ctrlpts=False): """ Evaluates the NURBS surface at the given (u,v) parameters. :param u: parameter in the U direction :type u: float :param v: parameter in the V direction :type v: float :param check_vars: flag to disable variable checking (only for internal eval functions) :type check_vars: bool :param get_ctrlpts: flag to add a list of control points associated with the surface evaluation to the return value :param get_ctrlpts: bool :return: evaluated surface point at the given knot values :rtype: list """ if check_vars: # Check all parameters are set before the surface evaluation self._check_variables() # Check u and v parameters are correct utils.check_uv(u, v) # Initialize an empty list which will contain the list of associated control points ctrlpts = [] # Algorithm A4.3 span_v = utils.find_span(self._degree_v, tuple(self._knot_vector_v), self._control_points_size_v, v) basis_v = utils.basis_functions(self._degree_v, tuple(self._knot_vector_v), span_v, v) span_u = utils.find_span(self._degree_u, tuple(self._knot_vector_u), self._control_points_size_u, u) basis_u = utils.basis_functions(self._degree_u, tuple(self._knot_vector_u), span_u, u) idx_u = span_u - self._degree_u sptw = [0.0 for x in range(self._dimension)] for l in range(0, self._degree_v + 1): temp = [0.0 for x in range(self._dimension)] idx_v = span_v - self._degree_v + l for k in range(0, self._degree_u + 1): temp[:] = [ tmp + (basis_u[k] * cp) for tmp, cp in zip( temp, self._control_points2D[idx_u + k][idx_v]) ] if get_ctrlpts: ctrlpts.append(self._control_points2D[idx_u + k][idx_v]) sptw[:] = [ ptw + (basis_v[l] * tmp) for ptw, tmp in zip(sptw, temp) ] # Divide by weight spt = [] for idx in range(self._dimension - 1): spt.append(float(sptw[idx] / sptw[-1])) if get_ctrlpts: return spt, ctrlpts return spt
def test_check_uv4(): with pytest.raises(ValueError): v = 2 u = 0.1 utilities.check_uv(u, v)
def test_check_uv2(): with pytest.raises(ValueError): u = 2 v = 0.1 utilities.check_uv(u, v)