Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with insert_knot function when splitting surface #179

Open
Julien-Livet opened this issue Oct 27, 2024 · 0 comments
Open

Problem with insert_knot function when splitting surface #179

Julien-Livet opened this issue Oct 27, 2024 · 0 comments
Labels
bug There is a problem with the coding or algorithms

Comments

@Julien-Livet
Copy link

Julien-Livet commented Oct 27, 2024

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/branch: 5.x

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

@Julien-Livet Julien-Livet added the bug There is a problem with the coding or algorithms label Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug There is a problem with the coding or algorithms
Projects
None yet
Development

No branches or pull requests

1 participant