NURBS-Python icon indicating copy to clipboard operation
NURBS-Python copied to clipboard

Problem with insert_knot function when splitting surface

Open Julien-Livet opened this issue 1 year ago • 0 comments

Describe the bug When I call the "split_surface_u" function with the value of 0.1 for the param, I get a ValueError exception about the knot vector for the u-direction.

To Reproduce Steps to reproduce the behavior:

  1. Here is the sample code to reproduce the error.

from geomdl import NURBS from geomdl import operations import matplotlib.pyplot as plt

surf = NURBS.Surface() surf.degree_u = 4 surf.degree_v = 4 surf.set_ctrlpts([[0.0, 0.0, 0.0, 1], [2.0, 0.0, 0.0, 1], [4.0, 0.0, 0.0, 1], [6.0, 0.0, 0.0, 1], [8.0, 0.0, 0.0, 1], [10.0, 0.0, 0.0, 1], [0.0, 2.0, 0.0, 1], [2.0, 2.0, -1.0, 1], [4.0, 2.0, -1.0, 1], [6.0, 2.0, -1.0, 1], [8.0, 2.0, -1.0, 1], [10.0, 2.0, 0.0, 1], [0.0, 4.0, 0.0, 1], [2.0, 4.0, -1.0, 1], [4.0, 4.0, 1.0, 1], [6.0, 4.0, 1.0, 1], [8.0, 4.0, -1.0, 1], [10.0, 4.0, 0.0, 1], [0.0, 6.0, 0.0, 1], [2.0, 6.0, -1.0, 1], [4.0, 6.0, 1.0, 1], [6.0, 6.0, 1.0, 1], [8.0, 6.0, -1.0, 1], [10.0, 6.0, 0.0, 1], [0.0, 8.0, 0.0, 1], [2.0, 8.0, -1.0, 1], [4.0, 8.0, -1.0, 1], [6.0, 8.0, -1.0, 1], [8.0, 8.0, -1.0, 1], [10.0, 8.0, 0.0, 1], [0.0, 10.0, 0.0, 1], [2.0, 10.0, 0.0, 1], [4.0, 10.0, 0.0, 1], [6.0, 10.0, 0.0, 1], [8.0, 10.0, 0.0, 1], [10.0, 10.0, 0.0, 1]], 6, 6) surf.knotvector_u = [0.0, 0.0, 0.0, 0.0, 1.0 / 4.0, 1.0 / 2.0, 3.0 / 4.0, 1.0, 1.0, 1.0, 1.0] surf.knotvector_v = [0.0, 0.0, 0.0, 0.0, 1.0 / 4.0, 1.0 / 2.0, 3.0 / 4.0, 1.0, 1.0, 1.0, 1.0]

s1, s2 = operations.split_surface_u(surf, 0.1)

eps = 1.0e-6

#Plot the NURBS surface x = [] y = [] z = []

du = 0.025 dv = 0.025 start_u = 0 start_v = 0 finish_u = 1 finish_v = 1

u = start_u

while (u < finish_u + eps): v = start_v

while (v < finish_v + eps): point = surf.evaluate_single((max(0, min(u, 1)), max(0, min(v, 1)))) x.append(point[0]) y.append(point[1]) z.append(point[2]) v += dv

u += du

fig = plt.figure() ax = fig.add_subplot(projection='3d') ax.set_aspect('equal') ax.scatter(x, y, z, marker="o")

  1. The error output should be: File "d:\tmp\test_nurbs_surface.py", line 19, in s1, s2 = operations.split_surface_u(surf, 0.1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Programmes\Python\Python312\Lib\site-packages\geomdl\operations.py", line 1115, in split_surface_u insert_knot_func(temp_obj, [param, None], num=[r, 0], check_num=False) File "D:\Programmes\Python\Python312\Lib\site-packages\geomdl\operations.py", line 126, in insert_knot obj.knotvector_u = kv_u ^^^^^^^^^^^^^^^^ File "D:\Programmes\Python\Python312\Lib\site-packages\geomdl\abstract.py", line 1375, in knotvector_u raise ValueError("Input is not a valid knot vector for the u-direction") ValueError: Input is not a valid knot vector for the u-direction

Expected Behavior What I expected to happen is no bug and two splitted surfaces.

Configuration:

  • OS: Windows 10
  • Python distribution: python.org
  • Python version: 3.12.4
  • geomdl install source: PyPI
  • geomdl version: 5.3.1

Screenshots Here is the surface that I want to split at u=0.1. image

Julien-Livet avatar Oct 27 '24 13:10 Julien-Livet