Skip to content

run NURBS Surface example but "ZeroDivisionError" #146

Open
@goldengrape

Description

Describe the bug
run NURBS Surface example
https://nurbs-python.readthedocs.io/en/5.x/module_nurbs.html#nurbs-surface

but failed.

To Reproduce
Steps to reproduce the behavior:

from geomdl import NURBS

# Create a NURBS surface instance
surf = NURBS.Surface()

# Set degrees
surf.degree_u = 3
surf.degree_v = 2

# Set control points (weights vector will be 1 by default)
# Use curve.ctrlptsw is if you are using homogeneous points as Pw
control_points = [[0, 0, 0], [0, 4, 0], [0, 8, -3],
                  [2, 0, 6], [2, 4, 0], [2, 8, 0],
                  [4, 0, 0], [4, 4, 0], [4, 8, 3],
                  [6, 0, 0], [6, 4, -3], [6, 8, 0]]
surf.set_ctrlpts(control_points, 4, 3)

# Set knot vectors
surf.knotvector_u = [0, 0, 0, 0, 1, 1, 1, 1]
surf.knotvector_v = [0, 0, 0, 1, 1, 1]

# Set evaluation delta (control the number of surface points)
surf.delta = 0.05

# Get surface points (the surface will be automatically evaluated)
surface_points = surf.evalpts

The error message:

ZeroDivisionError                         Traceback (most recent call last)
..\AppData\Local\Temp/ipykernel_21148/3509177292.py in <module>
     24 
     25 # Get surface points (the surface will be automatically evaluated)
---> 26 surface_points = surf.evalpts

~\miniconda3\lib\site-packages\geomdl\abstract.py in evalpts(self)
    263         """
    264         if self._eval_points is None or len(self._eval_points) == 0:
--> 265             self.evaluate()
    266         return self._eval_points
    267 

~\miniconda3\lib\site-packages\geomdl\BSpline.py in evaluate(self, **kwargs)
    614 
    615         # Evaluate and cache
--> 616         self._eval_points = self._evaluator.evaluate(self.data,
    617                                                      start=(start_u, start_v),
    618                                                      stop=(stop_u, stop_v))

~\miniconda3\lib\site-packages\geomdl\evaluators.py in evaluate(self, datadict, **kwargs)
    395         eval_points = []
    396         for pt in cptw:
--> 397             cpt = [float(c / pt[-1]) for c in pt[0:(dimension - 1)]]
    398             eval_points.append(cpt)
    399 

~\miniconda3\lib\site-packages\geomdl\evaluators.py in <listcomp>(.0)
    395         eval_points = []
    396         for pt in cptw:
--> 397             cpt = [float(c / pt[-1]) for c in pt[0:(dimension - 1)]]
    398             eval_points.append(cpt)
    399 

ZeroDivisionError: float division by zero

Expected Behavior
I had tried to reduce surf.delta to 0.01, 0.005, also got ZeroDivisionError

Configuration:

  • OS: [Win11]
  • Python distribution: [Anaconda]
  • Python version: python 3.9.5
  • geomdl install source: Anaconda
  • geomdl version/branch: 5.3.1

Metadata

Assignees

No one assigned

    Labels

    bugThere is a problem with the coding or algorithms

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions