NURBSPython v5 DocumentationÂ¶
Note
These documentation pages are for v5 release of NURBSPython (geomdl) library. Please see NURBSPython 4.x documentation for the previous stable release.
Welcome to the NURBSPython (geomdl) v5.x documentation! NURBSPython is a pure Python, objectoriented BSpline and NURBS library. It is compatible with Python versions 2.7.x, 3.4.x and later. It supports rational and nonrational curves, surfaces and volumes.
NURBSPython also provides a convenient and easytouse data structures for storing parametric shape descriptions. These are documented under Modules.
This documentation is organized into a couple sections:
MotivationÂ¶
NURBSPython (geomdl) is a selfcontained, objectoriented pure Python BSpline and NURBS library with implementations of curve, surface and volume generation and evaluation algorithms. It also provides convenient and easytouse data structures for storing curve, surface and volume descriptions.
Some significant features of NURBSPython are:
 Selfcontained, objectoriented, extensible and highly customizable API
 Convenient data structures for storing curve, surface and volume descriptions
 Surface and curve fitting with interpolation and least squares approximation
 Knot vector and surface grid generators
 Customizable visualization and animation options with Matplotlib, Plotly and VTK modules
 Exporting curve, surface and volume data into various file formats, such as JSON, YAML, Libconfig, STL, OBJ and VTK
 Support for common algorithms: tessellation, voxelization, ray intersection, etc.
 Shapes component for generation common surfaces and curves
 Pure Python, no external C/C++ or FORTRAN library dependencies
 Python compatibility: 2.7.x, 3.4.x and later
 No compilation steps are necessary, everything is implemented in pure Python
 For higher performance, optional Compile with Cython options are also available via
setup.py
 Easy to install via pip:
pip install geomdl
or conda:conda install c orbingol geomdl
 Docker images are available
ReferencesÂ¶
 Piegl, Les, and Wayne Tiller. The NURBS book. Springer Science & Business Media, 2012.
 Berg, Mark de, et al. Computational Geometry: Algorithms and Applications. SpringerVerlag TELOS, 2008.
 Hughes, John F., et al. Computer Graphics: Principles and Practice. Pearson Education, 2014.
 Dunn, Fletcher, and Ian Parberry. 3D Math Primer for Graphics and Game Development. CRC Press, 2015.
 Kreyszig, Erwin. Advanced Engineering Mathematics. John Wiley & Sons, 2010.
 Gamma, Erich. Design Patterns: Elements of Reusable ObjectOriented Software. Pearson Education India, 1995.
AuthorÂ¶
Onur Rauf Bingol
 Email: contact@onurbingol.net
 Twitter: https://twitter.com/orbingol
 LinkedIn: https://www.linkedin.com/in/onurraufbingol/
AcknowledgmentsÂ¶
I would like to thank my PhD adviser, Dr. Adarsh Krishnamurthy, for his guidance and supervision throughout the course of this project.
Citing NURBSPythonÂ¶
ArticleÂ¶
We have published an article outlining the design and features of NURBSPython (geomdl) on an openaccess Elsevier journal SoftwareX in the JanuaryJune 2019 issue.
Please refer to the following DOI link to access the article: https://doi.org/10.1016/j.softx.2018.12.005
BibTexÂ¶
You can use the following BibTeX entry to cite the NURBSPython paper:
@article{bingol2019geomdl,
title={{NURBSPython}: An opensource objectoriented {NURBS} modeling framework in {Python}},
author={Bingol, Onur Rauf and Krishnamurthy, Adarsh},
journal={{SoftwareX}},
volume={9},
pages={8594},
year={2019},
publisher={Elsevier}
}
Questions and AnswersÂ¶
What is NURBS?Â¶
NURBS is an acronym for NonUniform Rational Basis Spline and it represents a mathematical model for generation of curves and surfaces in a flexible way. It is a wellaccepted industry standard and used as a basis for nearly all of the 3D modeling and CAD/CAM software packages as well as modeling and visualization frameworks.
Please see the related Wikipedia article or The NURBS Book, a very nice and informative book written by Les A. Piegl and Wayne Tiller.
Why NURBSPython?Â¶
NURBSPython started as a term project for M E 625 Surface Modeling course offered in 2016 Spring semester at Iowa State University. The main purpose of the project was development of an opensource, objectoriented, pure Python NURBS library and releasing on the public domain. As an added challenge to the project, everything was developed using Python Standard Library but no other external modules. This challenge was specifically added as we were struggling with installing & compiling external modules for embedded Python distributions.
In years, NURBSPython has grown up to a selfcontained and extensible generalpurpose pure Python spline library with support for various computational geometry and linear algebra algorithms. Apart from the computational side, user experience was also improved by introduction of visualization and CAD exchange modules.
NURBSPython is not an another NURBS library but it is mostly considered as one of its kind. Please see the Motivation page for more details.
Why two packages on PyPI?Â¶
Prior to NURBSPython v4.0.0, the PyPI project name was NURBSPython. The latest version of this package is v3.9.0 which is an alias for the geomdl package. To get the latest features and bug fixes, please use geomdl package and update whenever a new version is released. The simplest way to check if you are using the latest version is
$ pip list outdated
Minimum RequirementsÂ¶
NURBSPython is tested on Python versions 2.7.x and 3.4.x+. The core library does not depend on any additional packages or require any compilation steps; therefore, you can run it on a plain python installation as well as on a distribution, such as Anaconda.
Help and SupportÂ¶
Please join the email list on Google Groups. It is open for NURBSPython users to ask questions, request new features and submit any other comments you may have.
Issues and ReportingÂ¶
Contributions to NURBSPythonÂ¶
All contributions to NURBSPython are welcomed and I appreciate your time and efforts in advance. I have posted some guidelines for contributing and I would be really happy if you could follow these guidelines if you would like to contribute to NURBSPython.
Bugs and IssuesÂ¶
Please use the issue tracker on GitHub for reporting bugs and other related issues.
I would be glad if you could provide as much detail as you can for pinpointing the problem. You donâ€™t have to provide a solution for the problem that you encountered but it would be good if you would provide steps (preferably, as a list) to reproduce it. You may directly upload any data files required for testing to the issue tracker or email me if you feel that is more convenient for you.
Comments, Questions and Feature RequestsÂ¶
You are encouraged to use the issue tracker on GitHub
for your questions and comments. I would be glad if you could use the appropriate label
(comment
, question
or feature request
) to label your questions or comments on the issue tracker.
API ChangesÂ¶
I try to keep the API (name and location of the functions, class fields and member functions) backwardcompatible during minor version upgrades. During major version upgrades, the API change might not be backwardcompatible. However, these changes will be kept minor and therefore, the users can update their code to the new version without much hassle. All of these changes, regardless of minor or major version upgrades, will be announced on the CHANGELOG file.
Installation Issues on Mac OSÂ¶
Installation of six
package from PyPI might cause some issues on some Mac OS versions. Six is a Python 2 to 3
compatibility library and allows NURBSPython to run under both Python 2 and Python 3. If you are having issues regarding
to installation of six
package on Mac OS, please use the following command to install NURBSPython (geomdl):
$ pip install geomdl ignoreinstalled six
and to upgrade NURBSPython (geomdl):
$ pip install geomdl upgrade ignoreinstalled six
or alternatively, you can use conda.
Please refer to the following issue on pip issue tracker for more details: https://github.com/pypa/pip/issues/3165
Installation and TestingÂ¶
Installation via pip or conda is the recommended method for all users. Manual method is only recommended for advanced users. Please note that if you have used any of these methods to install NURBSPython, please use the same method to upgrade to the latest version.
Install via PipÂ¶
The easiest method to install/upgrade NURBSPython is using pip. The following commands will download and install NURBSPython from Python Package Index.
$ pip install geomdl
Upgrading to the latest version:
$ pip install geomdl upgrade
Install via CondaÂ¶
NURBSPython can also be installed/upgraded via conda package manager from the Anaconda Cloud repository.
To install:
$ conda install c orbingol geomdl
To upgrade:
$ conda upgrade c orbingol geomdl
If you are experiencing problems with this method, you can try to upgrade conda
package itself before
installing the NURBSPython library.
Manual InstallÂ¶
The initial step of the manual install is cloning the repository via git
or downloading the ZIP archive from the
repository page on GitHub. The package includes a setup.py script
which will take care of the installation and automatically copy/link the required files to your Python distributionâ€™s
sitepackages directory.
To install NURBSPython manually
$ python setup.py install
To upgrade, please pull the latest commits from the repository via git pull rebase
and then execute the above
command.
Development ModeÂ¶
The following command enables development mode by creating a link from the directory where you cloned NURBSPython repository to your Python distributionâ€™s sitepackages directory:
$ python setup.py develop
Since this command only generates a link to the library directory, pulling the latest commits from the repository would be enough to update the library to the latest version.
To disable development mode:
$ python setup.py develop uninstall
Checking InstallationÂ¶
If you would like to check if you have installed the package correctly, you may try to print geomdl.__version__
variable after import. The following example illustrates installation check on a Windows PowerShell instance:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\> python
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import geomdl
>>> geomdl.__version__
'4.0.2'
>>>
TestingÂ¶
The package includes tests/
directory which contains all the automated testing scripts.
These scripts require pytest installed on your Python distribution.
After installing the required packages, you may execute the following from your favorite IDE or from the command line:
pytest
or py.test
pytest will automatically find the tests under tests/
directory, execute them and show the results.
Compile with CythonÂ¶
To improve performance, the Core Library of NURBSPython can be compiled and installed using the following command along with the pure Python version.
$ pip install . installoption="usecython"
This command will generate .c files (i.e. cythonization) and compile the .c files into binary Python modules.
The following command can be used to directly compile and install from the existing .c files, skipping the cythonization step:
$ pip install . installoption="usesource"
To update the compiled module with the latest changes, you need to recythonize the code.
To enable Cythoncompiled module in development mode;
$ python setup.py build_ext usecython inplace
After the successful execution of the command, the you can import and use the compiled library as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  # Importing NURBS module
from geomdl.core import NURBS
# Importing visualization module
from geomdl.visualization import VisMPL as vis
# Creating a curve instance
crv = NURBS.Curve()
# Make a quadratic curve
crv.degree = 2
#######################################################
# Skipping control points and knot vector assignments #
#######################################################
# Set the visualization component and render the curve
crv.vis = vis.VisCurve3D()
crv.render()

Before Cython compilation, please make sure that you have Cython module and a valid compiler installed for your operating system.
Docker ContainersÂ¶
A collection of Docker containers is provided on Docker Hub containing NURBSPython, Cythoncompiled core and the commandline application. To get started, first install Docker and then run the following on the Docker command prompt to pull the image prepared with Python v3.5:
$ docker pull idealabisu/nurbspython:py35
On the Docker Repository page, you can find containers tagged for
Python versions and Debian (no suffix) and Alpine Linux
(alpine
suffix) operating systems. Please change the tag of the pull command above for downloading your preferred
image.
After pulling your preferred image, run the following command:
$ docker run rm it name geomdl p 8000:8000 idealabisu/nurbspython:py35
In all images, Matplotlib is set to use webagg
backend by default. Please follow the instructions on the command
line to view your figures.
Please refer to the Docker documentation for details on using Docker.
Examples RepositoryÂ¶
Although using NURBSPython is straightforward, it is always confusing to do the initial start with a new library. To give you a headstart on working with NURBSPython, an Examples repository over 50 example scripts which describe usage scenarios of the library and its modules is provided. You can run the scripts from the command line, inside from favorite IDE or copy them to a Jupyter notebook.
The Examples repository contains examples on
 BÃ©zier curves and surfaces
 BSpline & NURBS curves, surfaces and volumes
 Spline algorithms, e.g. knot insertion and removal, degree elevation and reduction
 Curve & surface splitting and BÃ©zier decomposition (info)
 Surface and curve fitting using interpolation and least squares approximation (docs)
 Geometrical operations, e.g. tangent, normal, binormal (docs)
 Importing & exporting BSpline and NURBS shapes (docs)
 Compatibility module for converting control points into various structures (docs)
 Surface grid generators (info and docs)
 Shape containers (docs)
 Automatic uniform knot vector generation via
utilities.generate_knot_vector()
 Visualization components (info, Matplotlib, Plotly and VTK)
 Ray operations (docs)
 Voxelization (docs)
Matplotlib and Plotly visualization modules are compatible with Jupyter notebooks but VTK visualization module is not. Please refer to the NURBSPython wiki for more details on using NURBSPython Matplotlib and Plotly visualization modules with Jupyter notebooks.
Commandline ApplicationÂ¶
You can use geomdl with the commandline application geomdlcli. The commandline application is designed for automation and input files are highly customizable using Jinja2 templates. It is also extremely easy to extend the commandline application by adding your own commands and integrating custom libraries with the configuration file.
Please refer to the following links for more details:
 PyPI: https://pypi.org/project/geomdl.cli
 Documentation: https://geomdlcli.readthedocs.io
 Development: https://github.com/orbingol/geomdlcli
Loading and Saving DataÂ¶
NURBSPython provides the following methods for loading curve and surface data from a file:
Additionally, save functionality is provided via the following methods:
These functions implement Pythonâ€™s pickle
module to serialize the degree, knot vector and the control points data.
The idea behind this system is only to provide users a basic data persistence capability, not to introduce a new
file type. Since the data is pickled, it can be loaded with any compatible Python version even without using
any special library.
The following example demonstrates the save functionality on a curve:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  from geomdl import BSpline
from geomdl import utilities
from geomdl import exchange
# Create a BSpline curve instance
curve = BSpline.Curve()
# Set the degree
curve.degree = 3
# Load control points from a text file
curve.ctrlpts = exchange.import_txt("control_points.txt")
# Autogenerate the knot vector
curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts))
# Save the curve
curve.save("mycurve.pickle")

The saved curve can be loaded from the file with the following simple code segment:
1 2 3 4 5 6 7  from geomdl import BSpline
# Create a BSpline curve instance
curve2 = BSpline.Curve()
# Load the saved curve from a file
curve2.load("mycurve.pickle")

Since the loadsave functionality implements Pythonâ€™s pickle
module, the saved file can also be loaded directly
without using the NURBSPython library.
1 2 3 4  import pickle
# "data" variable will be a dictionary containing the curve information
data = pickle.load(open("mycurve.pickle"), "rb")

The pickle
module has its own limitations by its design. Please see the Python documentation for more details.
Supported File FormatsÂ¶
NURBSPython supports several input and output formats for importing and exporting BSpline/NURBS curves and surfaces. Please note that NURBSPython uses righthanded notation on input and output files.
Text FilesÂ¶
NURBSPython provides a simple way to import and export the control points and the evaluated control points as ASCII text files. The details of the file format for curves and surfaces is described below:
NURBSPython Custom FormatÂ¶
NURBSPython provides import_txt()
function for reading control points of curves and surfaces from a
text file. For saving the control points export_txt()
function may be used.
The format of the text file depends on the type of the geometric element, i.e. curve or surface. The following sections explain this custom format.
2D CurvesÂ¶
To generate a 2D BSpline Curve, you need a list of (x, y) coordinates representing the control points (P), where
 x: value representing the xcoordinate
 y: value representing the ycoordinate
The format of the control points file for generating 2D BSpline curves is as follows:
x  y 

x_{1}  y_{1} 
x_{2}  y_{2} 
x_{3}  y_{3} 
The control points file format of the NURBS curves are very similar to BSpline ones with the difference of weights. To generate a 2D NURBS curve, you need a list of (x*w, y*w, w) coordinates representing the weighted control points (P_{w}) where,
 x: value representing the xcoordinate
 y: value representing the ycoordinate
 w: value representing the weight
The format of the control points file for generating 2D NURBS curves is as follows:
x*w  y*w  w 

x_{1}*w_{1}  y_{1}*w_{1}  w_{1} 
x_{2}*w_{2}  y_{2}*w_{2}  w_{2} 
x_{3}*w_{3}  y_{3}*w_{3}  w_{3} 
Note
compatibility module provides several functions to manipulate & convert control point arrays into NURBSPython compatible ones and more.
3D CurvesÂ¶
To generate a 3D BSpline curve, you need a list of (x, y, z) coordinates representing the control points (P), where
 x: value representing the xcoordinate
 y: value representing the ycoordinate
 z: value representing the zcoordinate
The format of the control points file for generating 3D BSpline curves is as follows:
x  y  z 

x_{1}  y_{1}  z_{1} 
x_{2}  y_{2}  z_{2} 
x_{3}  y_{3}  z_{3} 
To generate a 3D NURBS curve, you need a list of (x*w, y*w, z*w, w) coordinates representing the weighted control points (P_{w}) where,
 x: value representing the xcoordinate
 y: value representing the ycoordinate
 z: value representing the zcoordinate
 w: value representing the weight
The format of the control points file for generating 3D NURBS curves is as follows:
x*w  y*w  z*w  w 

x_{1}*w_{1}  y_{1}*w_{1}  z_{1}*w_{1}  w_{1} 
x_{2}*w_{2}  y_{2}*w_{2}  z_{2}*w_{2}  w_{2} 
x_{3}*w_{3}  y_{3}*w_{3}  z_{3}*w_{3}  w_{3} 
Note
compatibility module provides several functions to manipulate & convert control point arrays into NURBSPython compatible ones and more.
SurfacesÂ¶
Control points file for generating BSpline and NURBS has 2 options:
First option is very similar to the curve control points files with one noticeable difference to process u and v indices. In this list, the v index varies first. That is, a row of v control points for the first u value is found first. Then, the row of v control points for the next u value.
The second option sets the rows as v and columns as u. To generate a BSpline surface using this option, you need a list of (x, y, z) coordinates representing the control points (P) where,
 x: value representing the xcoordinate
 y: value representing the ycoordinate
 z: value representing the zcoordinate
The format of the control points file for generating BSpline surfaces is as follows:
v0  v1  v2  v3  v4  

u0  (x, y, z)  (x, y, z)  (x, y, z)  (x, y, z)  (x, y, z) 
u1  (x, y, z)  (x, y, z)  (x, y, z)  (x, y, z)  (x, y, z) 
u2  (x, y, z)  (x, y, z)  (x, y, z)  (x, y, z)  (x, y, z) 
To generate a NURBS surface using the 2nd option, you need a list of (x*w, y*w, z*w, w) coordinates representing the weighted control points (P_{w}) where,
 x: value representing the xcoordinate
 y: value representing the ycoordinate
 z: value representing the zcoordinate
 w: value representing the weight
The format of the control points file for generating NURBS surfaces is as follows:
v0  v1  v2  v3  

u0  (x*w, y*w, z*w, w)  (x*w, y*w, z*w, w)  (x*w, y*w, z*w, w)  (x*w, y*w, z*w, w) 
u1  (x*w, y*w, z*w, w)  (x*w, y*w, z*w, w)  (x*w, y*w, z*w, w)  (x*w, y*w, z*w, w) 
u2  (x*w, y*w, z*w, w)  (x*w, y*w, z*w, w)  (x*w, y*w, z*w, w)  (x*w, y*w, z*w, w) 
Note
compatibility module provides several functions to manipulate & convert control point arrays into NURBSPython compatible ones and more.
VolumesÂ¶
Parametric volumes can be considered as a stacked surfaces, which means that wparametric axis comes the first and then other parametric axes come.
CommaSeparated (CSV)Â¶
You may use export_csv()
and import_csv()
functions to save/load control points and/or evaluated
points as a CSV file. This function works with both curves and surfaces.
OBJ FormatÂ¶
You may use export_obj()
function to export a NURBS surface as a Wavefront .obj file.
Example 1Â¶
The following example demonstrates saving surfaces as .obj files:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  # ex_bezier_surface.py
from geomdl import BSpline
from geomdl import utilities
from geomdl import exchange
# Create a BSpline surface instance
surf = BSpline.Surface()
# Set evaluation delta
surf.delta = 0.01
# Set up the surface
surf.degree_u = 3
surf.degree_v = 2
control_points = [[0, 0, 0], [0, 1, 0], [0, 2, 3],
[1, 0, 6], [1, 1, 0], [1, 2, 0],
[2, 0, 0], [2, 1, 0], [2, 2, 3],
[3, 0, 0], [3, 1, 3], [3, 2, 0]]
surf.set_ctrlpts(control_points, 4, 3)
surf.knotvector_u = utilities.generate_knot_vector(surf.degree_u, 4)
surf.knotvector_v = utilities.generate_knot_vector(surf.degree_v, 3)
# Evaluate surface
surf.evaluate()
# Save surface as a .obj file
exchange.export_obj(surf, "bezier_surf.obj")

Example 2Â¶
The following example combines shapes
module together with exchange
module:
1 2 3 4 5 6 7 8 9 10 11 12 13 14  from geomdl.shapes import surface
from geomdl import exchange
# Generate cylindirical surface
surf = surface.cylinder(radius=5, height=12.5)
# Set evaluation delta
surf.delta = 0.01
# Evaluate the surface
surf.evaluate()
# Save surface as a .obj file
exchange.export_obj(surf, "cylindirical_surf.obj")

STL FormatÂ¶
Exporting to STL files works in the same way explained in OBJ Files section. To export a NURBS surface as a .stl file,
you may use export_stl()
function. This function saves in binary format by default but there is an option to
change the save file format to plain text. Please see the documentation for details.
Object File Format (OFF)Â¶
Very similar to exporting as OBJ and STL formats, you may use export_off()
function to export a NURBS surface
as a .off file.
Custom Formats (libconfig, YAML, JSON)Â¶
NURBSPython provides several custom formats, such as libconfig, YAML and JSON, for importing and exporting complete NURBS shapes (i.e. degrees, knot vectors and control points of single and multi curves/surfaces).
libconfigÂ¶
libconfig is a lightweight library for processing configuration files and
it is often used on C/C++ projects. The library doesnâ€™t define a format but it defines a syntax for the files it can
process. NURBSPython uses export_cfg()
and import_cfg()
functions to exporting and importing
shape data which can be processed by libconfigcompatible libraries. Although exporting does not require any external
libraries, importing functionality depends on libconf module, which is a pure
Python library for parsing libconfigformatted files.
YAMLÂ¶
YAML is a data serialization format and it is supported by the major programming languages.
NURBSPython uses ruamel.yaml package as an external dependency for its YAML
support since the package is wellmaintained and compatible with the latest YAML standards.
NURBSPython supports exporting and importing NURBS data to YAML format with the functions export_yaml()
and import_yaml()
, respectively.
JSONÂ¶
JSON is also a serialization and data interchange format and it is natively supported
by Python via json
module. NURBSPython supports exporting and importing NURBS data to JSON format with the
functions export_json()
and import_json()
, respectively.
Format DefinitionÂ¶
CurveÂ¶
The following example illustrates a 2dimensional NURBS curve. 3dimensional NURBS curves are also supported and they can be generated by updating the control points.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  shape:
type: curve
data:
 degree: 2
knotvector: [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]
control_points:
points: # cartesian coordinates of the control points
 [0.0, 1.0] # each control point is defined as a list
 [1.0, 1.0]
 [1.0, 0.0]
 [1.0, 1.0]
 [0.0, 1.0]
 [1.0, 1.0]
 [1.0, 0.0]
 [1.0, 1.0]
 [0.0, 1.0]
weights: # weights vector
 1.0
 0.707
 1.0
 0.707
 1.0
 0.707
 1.0
 0.707
 1.0
delta: 0.01 # evaluation delta

 Shape section: This section contains the single or multi NURBS data.
type
anddata
sections are mandatory.  Type section: This section defines the type of the NURBS shape. For NURBS curves, it should be set to curve.
 Data section: This section defines the NURBS data, i.e. degrees, knot vectors and control_points.
weights
anddelta
sections are optional.
SurfaceÂ¶
The following examples illustrates a NURBS surface:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51  shape:
type: surface # define shape type
data:
 degree_u: 1 # degree of the udirection
degree_v: 2 # degree of the vdirection
knotvector_u: [0.0, 0.0, 1.0, 1.0]
knotvector_v: [0.0, 0.0, 0.0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1.0, 1.0, 1.0]
size_u: 2 # number of control points on the udirection
size_v: 9 # number of control points on the vdirection
control_points:
points: # cartesian coordinates (x, y, z) of the control points
 [1.0, 0.0, 0.0] # each control point is defined as a list
 [1.0, 1.0, 0.0]
 [0.0, 1.0, 0.0]
 [1.0, 1.0, 0.0]
 [1.0, 0.0, 0.0]
 [1.0, 1.0, 0.0]
 [0.0, 1.0, 0.0]
 [1.0, 1.0, 0.0]
 [1.0, 0.0, 0.0]
 [1.0, 0.0, 1.0]
 [1.0, 1.0, 1.0]
 [0.0, 1.0, 1.0]
 [1.0, 1.0, 1.0]
 [1.0, 0.0, 1.0]
 [1.0, 1.0, 1.0]
 [0.0, 1.0, 1.0]
 [1.0, 1.0, 1.0]
 [1.0, 0.0, 1.0]
weights: # weights vector
 1.0
 0.7071
 1.0
 0.7071
 1.0
 0.7071
 1.0
 0.7071
 1.0
 1.0
 0.7071
 1.0
 0.7071
 1.0
 0.7071
 1.0
 0.7071
 1.0
delta:
 0.05 # evaluation delta of the udirection
 0.05 # evaluation delta of the vdirection

 Shape section: This section contains the single or multi NURBS data.
type
anddata
sections are mandatory.  Type section: This section defines the type of the NURBS shape. For NURBS curves, it should be set to surface.
 Data section: This section defines the NURBS data, i.e. degrees, knot vectors and control_points.
weights
anddelta
sections are optional.
Example: Reading .cfg Files with libconfÂ¶
The following example illustrates reading the exported .cfg file with libconf module as a reference for libconfigbased systems in different programming languages.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  # Assuming that you have already installed 'libconf'
import libconf
# Skipping export steps and assuming that we have already exported the data as 'my_nurbs.cfg'
with open("my_nurbs.cfg", "r") as fp:
# Open the file and parse using libconf module
ns = libconf.load(fp)
# 'count' shows the number of shapes loaded from the file
print(ns['shape']['count']
# Traverse through the loaded shapes
for n in ns['shape']['data']:
# As an example, we get the control points
ctrlpts = n['control_points']['points']

NURBSPython exports data in the way that allows processing any number of curves or surfaces with a simple for loop. This approach simplifies implementation of file reading routines for different systems and programming languages.
Using TemplatesÂ¶
NURBSPython v5.x supports Jinja2 templates with the following functions:
To import files formatted as Jinja2 templates, an additional jinja2=True
keyword argument should be passed to the
functions. For instance:
1 2 3 4  from geomdl import exchange
# Importing a .yaml file formatted as a Jinja2 template
data = exchange.import_yaml("surface.yaml", jinja2=True)

NURBSPython also provides some custom Jinja2 template functions for user convenience. These are:
knot_vector(d, np)
: generates a uniform knot vector. d: degree, np: number of control pointssqrt(x)
: square root of xcubert(x)
: cube root of xpow(x, y)
: x to the power of y
Please see ex_cylinder_tmpl.py
and ex_cylinder_tmpl.cptw
files in the Examples repository
for details on using Jinja2 templates with control point text files.
CompatibilityÂ¶
Most of the time, users experience problems in converting data between different software packages. To aid this problem a little bit, NURBSPython provides a compatibility module for converting control points sets into NURBSPython compatible ones.
The following example illustrates the usage of compatibility module:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64  from geomdl import NURBS
from geomdl import utilities as utils
from geomdl import compatibility as compat
from geomdl.visualization import VisMPL
#
# Surface exported from your CAD software
#
# Dimensions of the control points grid
p_size_u = 4
p_size_v = 3
# Control points in urow order
p_ctrlpts = [[0, 0, 0], [1, 0, 6], [2, 0, 0], [3, 0, 0],
[0, 1, 0], [1, 1, 0], [2, 1, 0], [3, 1, 3],
[0, 2, 3], [1, 2, 0], [2, 2, 3], [3, 2, 0]]
# Weights vector
p_weights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
# Degrees
p_degree_u = 3
p_degree_v = 2
#
# Prepare data for import
#
# Combine weights vector with the control points list
t_ctrlptsw = compat.combine_ctrlpts_weights(p_ctrlpts, p_weights)
# Since NURBSPython uses vrow order, we need to convert the exported ones
n_ctrlptsw = compat.flip_ctrlpts_u(t_ctrlptsw, p_size_u, p_size_v)
# Since we have no information on knot vectors, let's autogenerate them
n_knotvector_u = utils.generate_knot_vector(p_degree_u, p_size_u)
n_knotvector_v = utils.generate_knot_vector(p_degree_v, p_size_v)
#
# Import surface to NURBSPython
#
# Create a NURBS surface instance
surf = NURBS.Surface()
# Fill the surface object
surf.degree_u = p_degree_u
surf.degree_v = p_degree_v
surf_set_ctrlpts(n_ctrlptsw, p_size_u, p_size_v)
surf.knotvector_u = n_knotvector_u
surf.knotvector_v = n_knotvector_v
# Set evaluation delta
surf.delta = 0.05
# Set visualization component
vis_comp = VisMPL.VisSurface()
surf.vis = vis_comp
# Render the surface
surf.render()

Please see Compatibility Module Documentation for more details on manipulating and exporting control points.
NURBSPython has some other options for exporting and importing data. Please see File Formats page for details.
Surface GeneratorÂ¶
NURBSPython comes with a simple surface generator which is designed to generate a control points grid to be used as
a randomized input to BSpline.Surface
and NURBS.Surface
. It is capable of generating
customsized surfaces with arbitrary divisions and generating hills (or bumps) on the surface. It is also possible to
export the surface as a text file in the format described under File Formats documentation.
The classes CPGen.Grid
and CPGen.GridWeighted
are responsible for generating surfaces and
they are documented under Core Libraries.
The following example illustrates a sample usage of the BSpline surface generator:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40  from geomdl import CPGen
from geomdl import BSpline
from geomdl import utilities
from geomdl.visualization import VisPlotly
# Generate a plane with the dimensions 50x100
surfgrid = CPGen.Grid(50, 100)
# Generate a grid of 25x30
surfgrid.generate(25, 30)
# Generate bumps on the grid
surfgrid.bumps(num_bumps=5, bump_height=20, base_extent=4)
# Create a BSpline surface instance
surf = BSpline.Surface()
# Set degrees
surf.degree_u = 3
surf.degree_v = 3
# Get the control points from the generated grid
surf.ctrlpts2d = surfgrid.grid
# Set knot vectors
surf.knotvector_u = utilities.generate_knot_vector(surf.degree_u, surf.ctrlpts_size_u)
surf.knotvector_v = utilities.generate_knot_vector(surf.degree_v, surf.ctrlpts_size_v)
# Set sample size
surf.sample_size = 30
# Generate the visualization component and its configuration
vis_config = VisPlotly.VisConfig(ctrlpts=False, legend=False)
vis_comp = VisPlotly.VisSurface(vis_config)
# Set visualization component
surf.vis = vis_comp
# Plot the surface
surf.render()

CPGen.Grid.bumps()
method takes the following keyword arguments:
num_bumps
: Number of hills to be generatedbump_height
: Defines the peak height of the generated hillsbase_extent
: Due to the structure of the grid, the hill base can be defined as a square with the edge length of a.base_extent
is defined by the value of a/2.base_adjust
: Defines the padding of the area where the hills are generated. It accepts positive and negative values. A negative value means a padding to the inside of the grid and a positive value means padding to the outside of the grid.
VisualizationÂ¶
NURBSPython comes with the following visualization modules for direct plotting evaluated curves and surfaces:
Examples repository contains over 40 examples on how to use the visualization components in various ways. Please see Visualization Modules Documentation for more details.
ExamplesÂ¶
The following figures illustrate some example NURBS and Bspline shapes that can be generated and directly visualized via NURBSPython.
Advanced Visualization ExamplesÂ¶
The following example scripts can be found in Examples repository under the visualization
directory.
mpl_curve2d_tangents.pyÂ¶
This example illustrates a more advanced visualization option for plotting the 2D curve tangents alongside with the control points grid and the evaluated curve.
mpl_curve3d_tangents.pyÂ¶
This example illustrates a more advanced visualization option for plotting the 3D curve tangents alongside with the control points grid and the evaluated curve.
mpl_curve3d_vectors.pyÂ¶
This example illustrates a visualization option for plotting the 3D curve tangent, normal and binormal vectors alongside with the control points grid and the evaluated curve.
mpl_trisurf_vectors.pyÂ¶
The following figure illustrates tangent and normal vectors on ex_surface02.py
example.
Splitting and DecompositionÂ¶
NURBSPython is also capable of splitting the curves and the surfaces, as well as applying BÃ©zier decomposition.
Splitting of curves can be achieved via operations.split_curve()
method.
For the surfaces, there are 2 different splitting methods, operations.split_surface_u()
for splitting
the surface on the udirection and operations.split_surface_v()
for splitting on the vdirection.
BÃ©zier decomposition can be applied via operations.decompose_curve()
and
operations.decompose_surface()
methods for curves and surfaces, respectively.
The following figures are generated from the examples provided in the Examples repository.
SplittingÂ¶
The following 2D curve is split at u = 0.6
and applied translation by the tangent vector using
operations.translate()
method.
Splitting can also be applied to 3D curves (split at u = 0.3
) without any translation.
Surface splitting is also possible. The following figure compares splitting at u = 0.5
and v = 0.5
.
Surfaces can also be translated too before or after splitting operation. The following figure illustrates translation
after splitting the surface at u = 0.5
.
Multiple splitting is also possible for all curves and surfaces. The following figure describes multi splitting in
surfaces. The initial surface is split at u = 0.25
and then, one of the resultant surfaces is split at v = 0.75
,
finally resulting 3 surfaces.
BÃ©zier DecompositionÂ¶
The following figures illustrate BÃ©zier cecomposition capabilities of NURBSPython. Letâ€™s start with the most obvious
one, a full circle with 9 control points. It also is possible to directly generate this shape via geomdl.shapes
module.
The following is a circular curve generated with 7 control points as illustrated on page 301 of The NURBS Book
(2nd Edition) by Piegl and Tiller. There is also an option to generate this shape via geomdl.shapes
module.
The following figures illustrate the possibility of BÃ©zier decomposition in BSpline and NURBS surfaces.
The colors are randomly generated via utilities.color_generator()
function.
Exporting Plots as Image FilesÂ¶
The render()
method allows users to directly plot the curves and surfaces using predefined visualization classes.
This method takes some keyword arguments to control plot properties at runtime. Please see the class documentation on
description of these keywords. The render()
method also allows users to save the plots directly as a file and
to control the plot window visibility. The keyword arguments that control these features are filename
and plot
,
respectively.
The following example script illustrates creating a 3dimensional BÃ©zier curve and saving the plot as
beziercurve3d.pdf
without popping up the Matplotlib plot window. filename
argument is a string value defining
the name of the file to be saved and plot
flag controls the visibility of the plot window.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  from geomdl import BSpline
from geomdl import utilities
from geomdl.visualization import VisMPL
# Create a 3D BSpline curve instance (Bezier Curve)
curve = BSpline.Curve()
# Set up the Bezier curve
curve.degree = 3
curve.ctrlpts = [[10, 5, 10], [10, 20, 30], [40, 10, 25], [10, 5, 0]]
# Autogenerate knot vector
curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts))
# Set sample size
curve.sample_size = 40
# Evaluate curve
curve.evaluate()
# Plot the control point polygon and the evaluated curve
vis_comp = VisMPL.VisCurve3D()
curve.vis = vis_comp
# Don't pop up the plot window, instead save it as a PDF file
curve.render(filename="beziercurve3d.pdf", plot=False)

This functionality strongly depends on the plotting library used. Please see the documentation of the plotting library that you are using for more details on its figure exporting capabilities.
Core ModulesÂ¶
The following modules are included in the core library:
Geometry Abstract BaseÂ¶
abstract
module provides base classes for parametric curves, surfaces and volumes contained in this library and
therefore, it provides an easy way to extend the library in the most proper way.
Inheritance DiagramÂ¶
Abstract CurveÂ¶

class
geomdl.abstract.
Curve
(**kwargs)Â¶ Bases:
geomdl.abstract.SplineGeometry
Abstract base class for defining spline curves.
Curve ABC is inherited from abc.ABCMeta class which is included in Python standard library by default. Due to differences between Python 2 and 3 on defining a metaclass, the compatibility module
six
is employed. Usingsix
to set metaclass allows users to use the abstract classes in a correct way.The abstract base classes in this module are implemented using a feature called Python Properties. This feature allows users to use some of the functions as if they are class fields. You can also consider properties as a pythonic way to set getters and setters. You will see â€œgetterâ€ and â€œsetterâ€ descriptions on the documentation of these properties.
The Curve ABC allows users to set the FindSpan function to be used in evaluations with
find_span_func
keyword as an input to the class constructor. NURBSPython includes a binary and a linear search variation of the FindSpan function in thehelpers
module. You may also implement and use your own FindSpan function. Please see thehelpers
module for details.Code segment below illustrates a possible implementation of Curve abstract base class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
from geomdl import abstract class MyCurveClass(abstract.Curve): def __init__(self, **kwargs): super(MyCurveClass, self).__init__(**kwargs) # Add your constructor code here def evaluate(self, **kwargs): # Implement this function pass def evaluate_single(self, uv): # Implement this function pass def evaluate_list(self, uv_list): # Implement this function pass def derivatives(self, u, v, order, **kwargs): # Implement this function pass
The properties and functions defined in the abstract base class will be automatically available in the subclasses.

bbox
Â¶ Bounding box.
Evaluates the bounding box and returns the minimum and maximum coordinates.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box Type: tuple

ctrlpts
Â¶ Control points.
Please refer to the wiki for details on using this class member.
Getter: Gets the control points Setter: Sets the control points Type: list

ctrlpts_size
Â¶ Total number of control points.
Getter: Gets the total number of control points Type: int

data
Â¶ Returns a dictionary containing all shape data.
Please refer to the wiki for details on using this class member.

degree
Â¶ Degree.
Please refer to the wiki for details on using this class member.
Getter: Gets the degree Setter: Sets the degree Type: int

delta
Â¶ Evaluation delta.
Evaluation delta corresponds to the step size while
evaluate
function iterates on the knot vector to generate curve points. Decreasing step size results in generation of more curve points. Therefore; smaller the delta value, smoother the curve.The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets the delta value Setter: Sets the delta value Type: float

derivatives
(u, order, **kwargs)Â¶ Evaluates the derivatives of the curve at parameter u.
Note
This is an abstract method and it must be implemented in the subclass.
Parameters:  u (float) â€“ parameter (u)
 order (int) â€“ derivative order

dimension
Â¶ Spatial dimension.
Spatial dimension will be automatically estimated from the first element of the control points array.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

domain
Â¶ Domain.
Domain is determined using the knot vector(s).
Getter: Gets the domain

evalpts
Â¶ Evaluated points.
Please refer to the wiki for details on using this class member.
Getter: Gets the coordinates of the evaluated points Type: list

evaluate
(**kwargs)Â¶ Evaluates the curve.
Note
This is an abstract method and it must be implemented in the subclass.

evaluate_list
(param_list)Â¶ Evaluates the curve for an input range of parameters.
Note
This is an abstract method and it must be implemented in the subclass.
Parameters: param_list â€“ array of parameters

evaluate_single
(param)Â¶ Evaluates the curve at the given parameter.
Note
This is an abstract method and it must be implemented in the subclass.
Parameters: param â€“ parameter (u)

evaluator
Â¶ Evaluator instance.
Evaluators allow users to use different algorithms for BSpline and NURBS evaluations. Please see the documentation on
Evaluator
classes.Please refer to the wiki for details on using this class member.
Getter: Gets the current Evaluator instance Setter: Sets the Evaluator instance Type: evaluators.AbstractEvaluator

knotvector
Â¶ Knot vector.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets the knot vector Setter: Sets the knot vector Type: list

name
Â¶ Descriptor field for storing the shape identification data, such as names, ID numbers, etc.
Please refer to the wiki for details on using this class member.
Getter: Gets the descriptor Setter: Sets the descriptor Type: str

order
Â¶ Order.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the order Setter: Sets the order Type: int

pdimension
Â¶ Parametric dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the parametric dimension Type: int

range
Â¶ Domain range.
Getter: Gets the range

rational
Â¶ Defines the rational and nonrational Bspline shapes.
Rational shapes use homogeneous coordinates which includes a weight alongside with the Cartesian coordinates. Rational Bsplines are also named as NURBS (Nonuniform rational basis spline) and nonrational Bsplines are sometimes named as NUBS (Nonuniform basis spline) or directly as Bsplines.
Please refer to the wiki for details on using this class member.
Getter: Returns True is the Bspline object is rational (NURBS) Type: bool

render
(**kwargs)Â¶ Renders the curve using the visualization component
The visualization component must be set using
vis
property before calling this method. Keyword Arguments:
cpcolor
: sets the color of the control points polygonevalcolor
: sets the color of the curvebboxcolor
: sets the color of the bounding boxfilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falseextras
: adds line plots to the figure. Default: None
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.extras
argument can be used to add extra line plots to the figure. This argument expects a list of dicts in the format described below:1 2 3 4 5 6 7 8 9 10 11 12 13 14
[ dict( # line plot 1 points=[[1, 2, 3], [4, 5, 6]], # list of points name="My line Plot 1", # name displayed on the legend color="red", # color of the line plot size=6.5 # size of the line plot ), dict( # line plot 2 points=[[7, 8, 9], [10, 11, 12]], # list of points name="My line Plot 2", # name displayed on the legend color="navy", # color of the line plot size=12.5 # size of the line plot ) ]

reset
(**kwargs)Â¶ Resets control points and/or evaluated points.
 Keyword Arguments:
evalpts
: if True, then resets evaluated pointsctrlpts
if True, then resets control points

sample_size
Â¶ Sample size.
Sample size defines the number of evaluated points to generate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size Setter: Sets sample size Type: int

set_ctrlpts
(ctrlpts, *args, **kwargs)Â¶ Sets control points and checks if the data is consistent.
This method is designed to provide a consistent way to set control points whether they are weighted or not. It directly sets the control points member of the class, and therefore it doesnâ€™t return any values. The input will be an array of coordinates. If you are working in the 3dimensional space, then your coordinates will be an array of 3 elements representing (x, y, z) coordinates.
Parameters: ctrlpts (list) â€“ input control points as a list of coordinates

Abstract SurfaceÂ¶

class
geomdl.abstract.
Surface
(**kwargs)Â¶ Bases:
geomdl.abstract.SplineGeometry
Abstract base class for defining spline surfaces.
Surface ABC is inherited from abc.ABCMeta class which is included in Python standard library by default. Due to differences between Python 2 and 3 on defining a metaclass, the compatibility module
six
is employed. Usingsix
to set metaclass allows users to use the abstract classes in a correct way.The abstract base classes in this module are implemented using a feature called Python Properties. This feature allows users to use some of the functions as if they are class fields. You can also consider properties as a pythonic way to set getters and setters. You will see â€œgetterâ€ and â€œsetterâ€ descriptions on the documentation of these properties.
The Surface ABC allows users to set the FindSpan function to be used in evaluations with
find_span_func
keyword as an input to the class constructor. NURBSPython includes a binary and a linear search variation of the FindSpan function in thehelpers
module. You may also implement and use your own FindSpan function. Please see thehelpers
module for details.Code segment below illustrates a possible implementation of Surface abstract base class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
from geomdl import abstract class MySurfaceClass(abstract.Surface): def __init__(self, **kwargs): super(MySurfaceClass, self).__init__(**kwargs) # Add your constructor code here def evaluate(self, **kwargs): # Implement this function pass def evaluate_single(self, uv): # Implement this function pass def evaluate_list(self, uv_list): # Implement this function pass def derivatives(self, u, v, order, **kwargs): # Implement this function pass
The properties and functions defined in the abstract base class will be automatically available in the subclasses.

bbox
Â¶ Bounding box.
Evaluates the bounding box and returns the minimum and maximum coordinates.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box Type: tuple

ctrlpts
Â¶ 1dimensional array of control points.
Note
The v index varies first. That is, a row of v control points for the first u value is found first. Then, the row of v control points for the next u value.
Please refer to the wiki for details on using this class member.
Getter: Gets the control points Setter: Sets the control points Type: list

ctrlpts_size
Â¶ Total number of control points.
Getter: Gets the total number of control points Type: int

ctrlpts_size_u
Â¶ Number of control points for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the udirection Setter: Sets number of control points for the udirection

ctrlpts_size_v
Â¶ Number of control points for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points on the vdirection Setter: Sets number of control points on the vdirection

data
Â¶ Returns a dictionary containing all shape data.
Please refer to the wiki for details on using this class member.

degree
Â¶ Degree for u and vdirections
Getter: Gets the degree Setter: Sets the degree Type: list

degree_u
Â¶ Degree for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the udirection Setter: Sets degree for the udirection Type: int

degree_v
Â¶ Degree for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the vdirection Setter: Sets degree for the vdirection Type: int

delta
Â¶ Evaluation delta for both u and vdirections.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta
andsample_size
properties correspond to the same variable with different descriptions. Therefore, settingdelta
will also setsample_size
.The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta as a tuple of values corresponding to u and vdirections Setter: Sets evaluation delta for both u and vdirections Type: float

delta_u
Â¶ Evaluation delta for the udirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_u
andsample_size_u
properties correspond to the same variable with different descriptions. Therefore, settingdelta_u
will also setsample_size_u
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the udirection Setter: Sets evaluation delta for the udirection Type: float

delta_v
Â¶ Evaluation delta for the vdirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_v
andsample_size_v
properties correspond to the same variable with different descriptions. Therefore, settingdelta_v
will also setsample_size_v
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the vdirection Setter: Sets evaluation delta for the vdirection Type: float

derivatives
(u, v, order, **kwargs)Â¶ Evaluates the derivatives of the parametric surface at parameter (u, v).
Note
This is an abstract method and it must be implemented in the subclass.
Parameters:  u (float) â€“ parameter on the udirection
 v (float) â€“ parameter on the vdirection
 order (int) â€“ derivative order

dimension
Â¶ Spatial dimension.
Spatial dimension will be automatically estimated from the first element of the control points array.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

domain
Â¶ Domain.
Domain is determined using the knot vector(s).
Getter: Gets the domain

evalpts
Â¶ Evaluated points.
Please refer to the wiki for details on using this class member.
Getter: Gets the coordinates of the evaluated points Type: list

evaluate
(**kwargs)Â¶ Evaluates the parametric surface.
Note
This is an abstract method and it must be implemented in the subclass.

evaluate_list
(param_list)Â¶ Evaluates the parametric surface for an input range of (u, v) parameters.
Note
This is an abstract method and it must be implemented in the subclass.
Parameters: param_list â€“ array of parameters (u, v)

evaluate_single
(param)Â¶ Evaluates the parametric surface at the given (u, v) parameter.
Note
This is an abstract method and it must be implemented in the subclass.
Parameters: param â€“ parameter (u, v)

evaluator
Â¶ Evaluator instance.
Evaluators allow users to use different algorithms for BSpline and NURBS evaluations. Please see the documentation on
Evaluator
classes.Please refer to the wiki for details on using this class member.
Getter: Gets the current Evaluator instance Setter: Sets the Evaluator instance Type: evaluators.AbstractEvaluator

knotvector
Â¶ Knot vector for u and vdirections
Getter: Gets the knot vector Setter: Sets the knot vector Type: list

knotvector_u
Â¶ Knot vector for the udirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the udirection Setter: Sets knot vector for the udirection Type: list

knotvector_v
Â¶ Knot vector for the vdirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the vdirection Setter: Sets knot vector for the vdirection Type: list

name
Â¶ Descriptor field for storing the shape identification data, such as names, ID numbers, etc.
Please refer to the wiki for details on using this class member.
Getter: Gets the descriptor Setter: Sets the descriptor Type: str

order_u
Â¶ Order for the udirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets order for the udirection Setter: Sets order for the udirection Type: int

order_v
Â¶ Order for the vdirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets surface order for the vdirection Setter: Sets surface order for the vdirection Type: int

pdimension
Â¶ Parametric dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the parametric dimension Type: int

range
Â¶ Domain range.
Getter: Gets the range

rational
Â¶ Defines the rational and nonrational Bspline shapes.
Rational shapes use homogeneous coordinates which includes a weight alongside with the Cartesian coordinates. Rational Bsplines are also named as NURBS (Nonuniform rational basis spline) and nonrational Bsplines are sometimes named as NUBS (Nonuniform basis spline) or directly as Bsplines.
Please refer to the wiki for details on using this class member.
Getter: Returns True is the Bspline object is rational (NURBS) Type: bool

render
(**kwargs)Â¶ Renders the surface using the visualization component.
The visualization component must be set using
vis
property before calling this method. Keyword Arguments:
cpcolor
: sets the color of the control points gridevalcolor
: sets the color of the surfacetrimcolor
: sets the color of the trim curvesfilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falseextras
: adds line plots to the figure. Default: Nonecolormap
: sets the colormap of the surface
The
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.extras
argument can be used to add extra line plots to the figure. This argument expects a list of dicts in the format described below:1 2 3 4 5 6 7 8 9 10 11 12 13 14
[ dict( # line plot 1 points=[[1, 2, 3], [4, 5, 6]], # list of points name="My line Plot 1", # name displayed on the legend color="red", # color of the line plot size=6.5 # size of the line plot ), dict( # line plot 2 points=[[7, 8, 9], [10, 11, 12]], # list of points name="My line Plot 2", # name displayed on the legend color="navy", # color of the line plot size=12.5 # size of the line plot ) ]
Please note that
colormap
argument can only work with visualization classes that support colormaps. As an example, please seeVisMPL.VisSurfTriangle()
class documentation. This method expects a single colormap input.

reset
(**kwargs)Â¶ Resets control points and/or evaluated points.
 Keyword Arguments:
evalpts
: if True, then resets evaluated pointsctrlpts
if True, then resets control points

sample_size
Â¶ Sample size for both u and vdirections.
Sample size defines the number of surface points to generate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size as a tuple of values corresponding to u and vdirections Setter: Sets sample size for both u and vdirections Type: int

sample_size_u
Â¶ Sample size for the udirection.
Sample size defines the number of surface points to generate. It also sets the
delta_u
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the udirection Setter: Sets sample size for the udirection Type: int

sample_size_v
Â¶ Sample size for the vdirection.
Sample size defines the number of surface points to generate. It also sets the
delta_v
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the vdirection Setter: Sets sample size for the vdirection Type: int

set_ctrlpts
(ctrlpts, *args, **kwargs)Â¶ Sets the control points and checks if the data is consistent.
This method is designed to provide a consistent way to set control points whether they are weighted or not. It directly sets the control points member of the class, and therefore it doesnâ€™t return any values. The input will be an array of coordinates. If you are working in the 3dimensional space, then your coordinates will be an array of 3 elements representing (x, y, z) coordinates.
Note
The v index varies first. That is, a row of v control points for the first u value is found first. Then, the row of v control points for the next u value.
Parameters:  ctrlpts (list) â€“ input control points as a list of coordinates
 args (tuple[int, int]) â€“ number of control points corresponding to each parametric dimension

tessellate
(**kwargs)Â¶ Tessellates the surface.
Keyword arguments are directly passed to the tessellation component.

tessellator
Â¶ Tessellation component.
Please refer to the wiki for details on using this class member.
Getter: Gets the tessellation component Setter: Sets the tessellation component

trims
Â¶ Trim curves.
Trim curves are introduced to the surfaces on the parametric space. It should be an array (or list, tuple, etc.) and they are integrated to the existing visualization system.
Please refer to the wiki for details on using this class member.
Getter: Gets the array of trim curves Setter: Sets the array of trim curves

Abstract VolumeÂ¶

class
geomdl.abstract.
Volume
(**kwargs)Â¶ Bases:
geomdl.abstract.SplineGeometry
Abstract base class for defining spline volumes.
Volume ABC is inherited from abc.ABCMeta class which is included in Python standard library by default. Due to differences between Python 2 and 3 on defining a metaclass, the compatibility module
six
is employed. Usingsix
to set metaclass allows users to use the abstract classes in a correct way.The abstract base classes in this module are implemented using a feature called Python Properties. This feature allows users to use some of the functions as if they are class fields. You can also consider properties as a pythonic way to set getters and setters. You will see â€œgetterâ€ and â€œsetterâ€ descriptions on the documentation of these properties.
The Volume ABC allows users to set the FindSpan function to be used in evaluations with
find_span_func
keyword as an input to the class constructor. NURBSPython includes a binary and a linear search variation of the FindSpan function in thehelpers
module. You may also implement and use your own FindSpan function. Please see thehelpers
module for details.Code segment below illustrates a possible implementation of Volume abstract base class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
from geomdl import abstract class MyVolumeClass(abstract.Volume): def __init__(self, **kwargs): super(MyVolumeClass, self).__init__(**kwargs) # Add your constructor code here def evaluate(self, **kwargs): # Implement this function pass def evaluate_single(self, uvw): # Implement this function pass def evaluate_list(self, uvw_list): # Implement this function pass
The properties and functions defined in the abstract base class will be automatically available in the subclasses.

bbox
Â¶ Bounding box.
Evaluates the bounding box and returns the minimum and maximum coordinates.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box Type: tuple

ctrlpts
Â¶ 1dimensional array of control points.
Please refer to the wiki for details on using this class member.
Getter: Gets the control points Setter: Sets the control points Type: list

ctrlpts_size
Â¶ Total number of control points.
Getter: Gets the total number of control points Type: int

ctrlpts_size_u
Â¶ Number of control points for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the udirection Setter: Sets number of control points for the udirection

ctrlpts_size_v
Â¶ Number of control points for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the vdirection Setter: Sets number of control points for the vdirection

ctrlpts_size_w
Â¶ Number of control points for the wdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the wdirection Setter: Sets number of control points for the wdirection

data
Â¶ Returns a dictionary containing all shape data.
Please refer to the wiki for details on using this class member.

degree
Â¶ Degree for u, v and wdirections
Getter: Gets the degree Setter: Sets the degree Type: list

degree_u
Â¶ Degree for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the udirection Setter: Sets degree for the udirection Type: int

degree_v
Â¶ Degree for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the vdirection Setter: Sets degree for the vdirection Type: int

degree_w
Â¶ Degree for the wdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the wdirection Setter: Sets degree for the wdirection Type: int

delta
Â¶ Evaluation delta for u, v and wdirections.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta
andsample_size
properties correspond to the same variable with different descriptions. Therefore, settingdelta
will also setsample_size
.The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta as a tuple of values corresponding to u, v and wdirections Setter: Sets evaluation delta for u, v and wdirections Type: float

delta_u
Â¶ Evaluation delta for the udirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_u
andsample_size_u
properties correspond to the same variable with different descriptions. Therefore, settingdelta_u
will also setsample_size_u
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the udirection Setter: Sets evaluation delta for the udirection Type: float

delta_v
Â¶ Evaluation delta for the vdirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_v
andsample_size_v
properties correspond to the same variable with different descriptions. Therefore, settingdelta_v
will also setsample_size_v
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the vdirection Setter: Sets evaluation delta for the vdirection Type: float

delta_w
Â¶ Evaluation delta for the wdirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_w
andsample_size_w
properties correspond to the same variable with different descriptions. Therefore, settingdelta_w
will also setsample_size_w
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the wdirection Setter: Sets evaluation delta for the wdirection Type: float

dimension
Â¶ Spatial dimension.
Spatial dimension will be automatically estimated from the first element of the control points array.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

domain
Â¶ Domain.
Domain is determined using the knot vector(s).
Getter: Gets the domain

evalpts
Â¶ Evaluated points.
Please refer to the wiki for details on using this class member.
Getter: Gets the coordinates of the evaluated points Type: list

evaluate
(**kwargs)Â¶ Evaluates the parametric volume.
Note
This is an abstract method and it must be implemented in the subclass.

evaluate_list
(param_list)Â¶ Evaluates the parametric volume for an input range of (u, v, w) parameter pairs.
Note
This is an abstract method and it must be implemented in the subclass.
Parameters: param_list â€“ array of parameter pairs (u, v, w)

evaluate_single
(param)Â¶ Evaluates the parametric surface at the given (u, v, w) parameter.
Note
This is an abstract method and it must be implemented in the subclass.
Parameters: param â€“ parameter pair (u, v, w)

evaluator
Â¶ Evaluator instance.
Evaluators allow users to use different algorithms for BSpline and NURBS evaluations. Please see the documentation on
Evaluator
classes.Please refer to the wiki for details on using this class member.
Getter: Gets the current Evaluator instance Setter: Sets the Evaluator instance Type: evaluators.AbstractEvaluator

knotvector
Â¶ Knot vector for u, v and wdirections
Getter: Gets the knot vector Setter: Sets the knot vector Type: list

knotvector_u
Â¶ Knot vector for the udirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the udirection Setter: Sets knot vector for the udirection Type: list

knotvector_v
Â¶ Knot vector for the vdirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the vdirection Setter: Sets knot vector for the vdirection Type: list

knotvector_w
Â¶ Knot vector for the wdirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the wdirection Setter: Sets knot vector for the wdirection Type: list

name
Â¶ Descriptor field for storing the shape identification data, such as names, ID numbers, etc.
Please refer to the wiki for details on using this class member.
Getter: Gets the descriptor Setter: Sets the descriptor Type: str

order_u
Â¶ Order for the udirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the surface order for udirection Setter: Sets the surface order for udirection Type: int

order_v
Â¶ Order for the vdirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the surface order for vdirection Setter: Sets the surface order for vdirection Type: int

order_w
Â¶ Order for the wdirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the surface order for vdirection Setter: Sets the surface order for vdirection Type: int

pdimension
Â¶ Parametric dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the parametric dimension Type: int

range
Â¶ Domain range.
Getter: Gets the range

rational
Â¶ Defines the rational and nonrational Bspline shapes.
Rational shapes use homogeneous coordinates which includes a weight alongside with the Cartesian coordinates. Rational Bsplines are also named as NURBS (Nonuniform rational basis spline) and nonrational Bsplines are sometimes named as NUBS (Nonuniform basis spline) or directly as Bsplines.
Please refer to the wiki for details on using this class member.
Getter: Returns True is the Bspline object is rational (NURBS) Type: bool

render
(**kwargs)Â¶ Renders the volume using the visualization component.
The visualization component must be set using
vis
property before calling this method. Keyword Arguments:
cpcolor
: sets the color of the control pointsevalcolor
: sets the color of the volumefilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falsegrid_size
: grid size for voxelization. Default: (16, 16, 16)use_mp
: flag to activate multithreaded voxelization. Default: Falsenum_procs
: number of concurrent processes for multithreaded voxelization. Default: 4
The
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.extras
argument can be used to add extra line plots to the figure. This argument expects a list of dicts in the format described below:1 2 3 4 5 6 7 8 9 10 11 12 13 14
[ dict( # line plot 1 points=[[1, 2, 3], [4, 5, 6]], # list of points name="My line Plot 1", # name displayed on the legend color="red", # color of the line plot size=6.5 # size of the line plot ), dict( # line plot 2 points=[[7, 8, 9], [10, 11, 12]], # list of points name="My line Plot 2", # name displayed on the legend color="navy", # color of the line plot size=12.5 # size of the line plot ) ]

reset
(**kwargs)Â¶ Resets control points and/or evaluated points.
 Keyword Arguments:
evalpts
: if True, then resets evaluated pointsctrlpts
if True, then resets control points

sample_size
Â¶ Sample size for both u and vdirections.
Sample size defines the number of surface points to generate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size as a tuple of values corresponding to u, v and wdirections Setter: Sets sample size value for both u, v and wdirections Type: int

sample_size_u
Â¶ Sample size for the udirection.
Sample size defines the number of evaluated points to generate. It also sets the
delta_u
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the udirection Setter: Sets sample size for the udirection Type: int

sample_size_v
Â¶ Sample size for the vdirection.
Sample size defines the number of evaluated points to generate. It also sets the
delta_v
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the vdirection Setter: Sets sample size for the vdirection Type: int

sample_size_w
Â¶ Sample size for the wdirection.
Sample size defines the number of evaluated points to generate. It also sets the
delta_w
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the wdirection Setter: Sets sample size for the wdirection Type: int

set_ctrlpts
(ctrlpts, *args, **kwargs)Â¶ Sets the control points and checks if the data is consistent.
This method is designed to provide a consistent way to set control points whether they are weighted or not. It directly sets the control points member of the class, and therefore it doesnâ€™t return any values. The input will be an array of coordinates. If you are working in the 3dimensional space, then your coordinates will be an array of 3 elements representing (x, y, z) coordinates.
Parameters:  ctrlpts (list) â€“ input control points as a list of coordinates
 args (tuple[int, int, int]) â€“ number of control points corresponding to each parametric dimension

Low Level APIÂ¶
The following classes provide the low level API for the geometry abstract base.
Geometry
abstract base class can be used for implementation of any geometry object, whereas
SplineGeometry
abstract base class is designed specifically for spline geometries, including basis splines.

class
geomdl.abstract.
Geometry
(**kwargs)Â¶ Bases:
object
Abstract base class for defining geometry elements.
 Keyword Arguments:
precision
: number of decimal places to round to
This class provides the following properties:

evalpts
Â¶ Evaluated points.
Please refer to the wiki for details on using this class member.
Getter: Gets the coordinates of the evaluated points Type: list

evaluate
(**kwargs)Â¶ Abstract method for the implementation of evaluation algorithm.
Note
This is an abstract method and it must be implemented in the subclass.

class
geomdl.abstract.
SplineGeometry
(**kwargs)Â¶ Bases:
geomdl.abstract.Geometry
Abstract base class for defining spline geometries.
 Keyword Arguments:
precision
: number of decimal places to round to
This class provides the following properties:
name
rational
dimension
pdimension
degree
knotvector
ctrlpts
ctrlpts_size
weights
(for completeness with the rational spline implementations)evalpts
bbox
evaluator
vis

bbox
Â¶ Bounding box.
Evaluates the bounding box and returns the minimum and maximum coordinates.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box Type: tuple

ctrlpts
Â¶ Control points.
Please refer to the wiki for details on using this class member.
Getter: Gets the control points Setter: Sets the control points Type: list

ctrlpts_size
Â¶ Total number of control points.
Getter: Gets the total number of control points Type: int

degree
Â¶ Degree
Getter: Gets the degree Setter: Sets the degree Type: list

dimension
Â¶ Spatial dimension.
Spatial dimension will be automatically estimated from the first element of the control points array.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

domain
Â¶ Domain.
Domain is determined using the knot vector(s).
Getter: Gets the domain

evalpts
Â¶ Evaluated points.
Please refer to the wiki for details on using this class member.
Getter: Gets the coordinates of the evaluated points Type: list

evaluate
(**kwargs)Â¶ Abstract method for the implementation of evaluation algorithm.
Note
This is an abstract method and it must be implemented in the subclass.

evaluator
Â¶ Evaluator instance.
Evaluators allow users to use different algorithms for BSpline and NURBS evaluations. Please see the documentation on
Evaluator
classes.Please refer to the wiki for details on using this class member.
Getter: Gets the current Evaluator instance Setter: Sets the Evaluator instance Type: evaluators.AbstractEvaluator

knotvector
Â¶ Knot vector
Getter: Gets the knot vector Setter: Sets the knot vector Type: list

name
Â¶ Descriptor field for storing the shape identification data, such as names, ID numbers, etc.
Please refer to the wiki for details on using this class member.
Getter: Gets the descriptor Setter: Sets the descriptor Type: str

pdimension
Â¶ Parametric dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the parametric dimension Type: int

range
Â¶ Domain range.
Getter: Gets the range

rational
Â¶ Defines the rational and nonrational Bspline shapes.
Rational shapes use homogeneous coordinates which includes a weight alongside with the Cartesian coordinates. Rational Bsplines are also named as NURBS (Nonuniform rational basis spline) and nonrational Bsplines are sometimes named as NUBS (Nonuniform basis spline) or directly as Bsplines.
Please refer to the wiki for details on using this class member.
Getter: Returns True is the Bspline object is rational (NURBS) Type: bool

render
(**kwargs)Â¶ Abstract method for spline rendering and visualization.
Note
This is an abstract method and it must be implemented in the subclass.

set_ctrlpts
(ctrlpts, *args, **kwargs)Â¶ Sets control points and checks if the data is consistent.
This method is designed to provide a consistent way to set control points whether they are weighted or not. It directly sets the control points member of the class, and therefore it doesnâ€™t return any values. The input will be an array of coordinates. If you are working in the 3dimensional space, then your coordinates will be an array of 3 elements representing (x, y, z) coordinates.
 Keyword Arguments:
array_init
: initializes the control points array in the instancearray_check_for
: defines the types for input validationcallback
: defines the callback function for processing input pointsdimension
: defines the spatial dimension of the input points
Parameters:  ctrlpts (list) â€“ input control points as a list of coordinates
 args (tuple) â€“ number of control points corresponding to each parametric dimension
BSpline GeometryÂ¶
BSpline
module provides data storage and evaluation functions for nonrational spline geometries.
Inheritance DiagramÂ¶
BSpline CurveÂ¶

class
geomdl.BSpline.
Curve
(**kwargs)Â¶ Bases:
geomdl.abstract.Curve
Data storage and evaluation class for nvariate Bspline (nonrational) curves.
This class provides the following properties:
 Notes:
 Please see the
abstract.Curve()
documentation for details.  This class sets the FindSpan implementation to Linear Search by default.
 Please see the
The following code segment illustrates the usage of Curve class:
from geomdl import BSpline # Create a 3dimensional Bspline Curve curve = BSpline.Curve() # Set degree curve.degree = 3 # Set knot points curve.ctrlpts = [[10, 5, 10], [10, 20, 30], [40, 10, 25], [10, 5, 0]] # Set knot vector curve.knotvector = [0, 0, 0, 0, 1, 1, 1, 1] # Set evaluation delta (control the number of curve points) curve.delta = 0.05 # Get curve points (the curve will be automatically evaluated) curve_points = curve.evalpts

bbox
Â¶ Bounding box.
Evaluates the bounding box and returns the minimum and maximum coordinates.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box Type: tuple

binormal
(parpos, **kwargs)Â¶ Evaluates the binormal vector of the curve at the given parametric position(s).
The
param
argument can be a float value for evaluation at a single parametric position
 a list of float values for evaluation at the multiple parametric positions
The return value will be in the order of the input parametric position list.
This method accepts the following keyword arguments:
normalize
: normalizes the output vector. Default value is True.
Parameters: parpos (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: an array containing â€œpointâ€ and â€œvectorâ€ pairs Return type: tuple

ctrlpts
Â¶ Control points.
Please refer to the wiki for details on using this class member.
Getter: Gets the control points Setter: Sets the control points Type: list

ctrlpts_size
Â¶ Total number of control points.
Getter: Gets the total number of control points Type: int

data
Â¶ Returns a dictionary containing all shape data.
Please refer to the wiki for details on using this class member.

degree
Â¶ Degree.
Please refer to the wiki for details on using this class member.
Getter: Gets the degree Setter: Sets the degree Type: int

delta
Â¶ Evaluation delta.
Evaluation delta corresponds to the step size while
evaluate
function iterates on the knot vector to generate curve points. Decreasing step size results in generation of more curve points. Therefore; smaller the delta value, smoother the curve.The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets the delta value Setter: Sets the delta value Type: float

derivatives
(u, order=0, **kwargs)Â¶ Evaluates nth order curve derivatives at the given parameter value.
Parameters:  u (float) â€“ parameter value
 order (int) â€“ derivative order
Returns: a list containing up to {order}th derivative of the curve
Return type: list

dimension
Â¶ Spatial dimension.
Spatial dimension will be automatically estimated from the first element of the control points array.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

domain
Â¶ Domain.
Domain is determined using the knot vector(s).
Getter: Gets the domain

evalpts
Â¶ Evaluated points.
Please refer to the wiki for details on using this class member.
Getter: Gets the coordinates of the evaluated points Type: list

evaluate
(**kwargs)Â¶ Evaluates the curve.
The evaluated curve points are stored in :py:attr:`~evalpts` property.
 Keyword arguments:
start
: start parameterstop
: stop parameter
The
start
andstop
parameters allow evaluation of a curve segment in the range [start, stop], i.e. the curve will also be evaluated at thestop
parameter value.The following examples illustrate the usage of the keyword arguments.
# Start evaluating from u=0.2 to u=1.0 curve.evaluate(start=0.2) # Start evaluating from u=0.0 to u=0.7 curve.evaluate(stop=0.7) # Start evaluating from u=0.1 to u=0.5 curve.evaluate(start=0.1, stop=0.5) # Get the evaluated points curve_points = curve.evalpts

evaluate_list
(param_list)Â¶ Evaluates the curve for an input range of parameters.
Parameters: param_list (list, tuple) â€“ list of parameters Returns: evaluated surface points at the input parameters Return type: list

evaluate_single
(param)Â¶ Evaluates the curve at the input parameter.
Parameters: param (float) â€“ parameter Returns: evaluated surface point at the given parameter Return type: list

evaluator
Â¶ Evaluator instance.
Evaluators allow users to use different algorithms for BSpline and NURBS evaluations. Please see the documentation on
Evaluator
classes.Please refer to the wiki for details on using this class member.
Getter: Gets the current Evaluator instance Setter: Sets the Evaluator instance Type: evaluators.AbstractEvaluator

insert_knot
(u, **kwargs)Â¶ Inserts the given knot and updates the control points array and the knot vector.
 Keyword Arguments:
r
: Number of knot insertions. Default: 1
Parameters: u (float) â€“ knot to be inserted

knotvector
Â¶ Knot vector.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets the knot vector Setter: Sets the knot vector Type: list

load
(file_name)Â¶ Loads the curve from a pickled file.
Parameters: file_name (str) â€“ name of the file to be loaded Raises: IOError â€“ an error occurred reading the file

name
Â¶ Descriptor field for storing the shape identification data, such as names, ID numbers, etc.
Please refer to the wiki for details on using this class member.
Getter: Gets the descriptor Setter: Sets the descriptor Type: str

next
()Â¶

normal
(parpos, **kwargs)Â¶ Evaluates the normal vector of the curve at the given parametric position(s).
The
param
argument can be a float value for evaluation at a single parametric position
 a list of float values for evaluation at the multiple parametric positions
The return value will be in the order of the input parametric position list.
This method accepts the following keyword arguments:
normalize
: normalizes the output vector. Default value is True.
Parameters: parpos (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: an array containing â€œpointâ€ and â€œvectorâ€ pairs Return type: tuple

order
Â¶ Order.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the order Setter: Sets the order Type: int

pdimension
Â¶ Parametric dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the parametric dimension Type: int

range
Â¶ Domain range.
Getter: Gets the range

rational
Â¶ Defines the rational and nonrational Bspline shapes.
Rational shapes use homogeneous coordinates which includes a weight alongside with the Cartesian coordinates. Rational Bsplines are also named as NURBS (Nonuniform rational basis spline) and nonrational Bsplines are sometimes named as NUBS (Nonuniform basis spline) or directly as Bsplines.
Please refer to the wiki for details on using this class member.
Getter: Returns True is the Bspline object is rational (NURBS) Type: bool

render
(**kwargs)Â¶ Renders the curve using the visualization component
The visualization component must be set using
vis
property before calling this method. Keyword Arguments:
cpcolor
: sets the color of the control points polygonevalcolor
: sets the color of the curvebboxcolor
: sets the color of the bounding boxfilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falseextras
: adds line plots to the figure. Default: None
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.extras
argument can be used to add extra line plots to the figure. This argument expects a list of dicts in the format described below:1 2 3 4 5 6 7 8 9 10 11 12 13 14
[ dict( # line plot 1 points=[[1, 2, 3], [4, 5, 6]], # list of points name="My line Plot 1", # name displayed on the legend color="red", # color of the line plot size=6.5 # size of the line plot ), dict( # line plot 2 points=[[7, 8, 9], [10, 11, 12]], # list of points name="My line Plot 2", # name displayed on the legend color="navy", # color of the line plot size=12.5 # size of the line plot ) ]

reset
(**kwargs)Â¶ Resets control points and/or evaluated points.
 Keyword Arguments:
evalpts
: if True, then resets evaluated pointsctrlpts
if True, then resets control points

sample_size
Â¶ Sample size.
Sample size defines the number of evaluated points to generate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size Setter: Sets sample size Type: int

save
(file_name)Â¶ Saves the curve as a pickled file.
Parameters: file_name (str) â€“ name of the file to be saved Raises: IOError â€“ an error occurred writing the file

set_ctrlpts
(ctrlpts, *args, **kwargs)Â¶ Sets control points and checks if the data is consistent.
This method is designed to provide a consistent way to set control points whether they are weighted or not. It directly sets the control points member of the class, and therefore it doesnâ€™t return any values. The input will be an array of coordinates. If you are working in the 3dimensional space, then your coordinates will be an array of 3 elements representing (x, y, z) coordinates.
Parameters: ctrlpts (list) â€“ input control points as a list of coordinates

tangent
(param, **kwargs)Â¶ Evaluates the tangent vector of the curve at the given parametric position(s).
The
param
argument can be a float value for evaluation at a single parametric position
 a list of float values for evaluation at the multiple parametric positions
The return value will be in the order of the input parametric position list.
This method accepts the following keyword arguments:
normalize
: normalizes the output vector. Default value is True.
Parameters: param (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: an array containing â€œpointâ€ and â€œvectorâ€ pairs Return type: tuple
BSpline SurfaceÂ¶

class
geomdl.BSpline.
Surface
(**kwargs)Â¶ Bases:
geomdl.abstract.Surface
Data storage and evaluation class for Bspline (nonrational) surfaces.
This class provides the following properties:
order_u
order_v
degree_u
degree_v
knotvector_u
knotvector_v
ctrlpts
ctrlpts_size_u
ctrlpts_size_v
ctrlpts2d
delta
delta_u
delta_v
sample_size
sample_size_u
sample_size_v
bbox
name
dimension
vis
evaluator
tessellator
rational
trims
 Notes:
 Please see the
abstract.Surface()
documentation for details.  This class sets the FindSpan implementation to Linear Search by default.
 Please see the
The following code segment illustrates the usage of Surface class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
from geomdl import BSpline # Create a BSpline surface instance (Bezier surface) surf = BSpline.Surface() # Set degrees surf.degree_u = 3 surf.degree_v = 2 # Set control points 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

bbox
Â¶ Bounding box.
Evaluates the bounding box and returns the minimum and maximum coordinates.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box Type: tuple

ctrlpts
Â¶ 1dimensional array of control points.
Note
The v index varies first. That is, a row of v control points for the first u value is found first. Then, the row of v control points for the next u value.
Please refer to the wiki for details on using this class member.
Getter: Gets the control points Setter: Sets the control points Type: list

ctrlpts2d
Â¶ 2dimensional array of control points.
The getter returns a tuple of 2D control points (weighted control points + weights if NURBS) in [u][v] format. The rows of the returned tuple correspond to vdirection and the columns correspond to udirection.
The following example can be used to traverse 2D control points:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# Create a BSpline surface surf_bs = BSpline.Surface() # Do degree, control points and knot vector assignments here # Each u includes a row of v values for u in surf_bs.ctrlpts2d: # Each row contains the coordinates of the control points for v in u: print(str(v)) # will be something like (1.0, 2.0, 3.0) # Create a NURBS surface surf_nb = NURBS.Surface() # Do degree, weighted control points and knot vector assignments here # Each u includes a row of v values for u in surf_nb.ctrlpts2d: # Each row contains the coordinates of the weighted control points for v in u: print(str(v)) # will be something like (0.5, 1.0, 1.5, 0.5)
When using NURBS.Surface class, the output of
ctrlpts2d
property could be confusing since,ctrlpts
always returns the unweighted control points, i.e.ctrlpts
property returns 3D control points all divided by the weights and you can useweights
property to access the weights vector, butctrlpts2d
returns the weighted ones plus weights as the last element. This difference is intentionally added for compatibility and interoperability purposes.To explain this situation in a simple way;
 If you need the weighted control points directly, use
ctrlpts2d
 If you need the control points and the weights separately, use
ctrlpts
andweights
Note
Please note that the setter doesnâ€™t check for inconsistencies and using the setter is not recommended. Instead of the setter property, please use
set_ctrlpts()
function.Please refer to the wiki for details on using this class member.
Getter: Gets the control points as a 2dimensional array in [u][v] format Setter: Sets the control points as a 2dimensional array in [u][v] format Type: list  If you need the weighted control points directly, use

ctrlpts_size
Â¶ Total number of control points.
Getter: Gets the total number of control points Type: int

ctrlpts_size_u
Â¶ Number of control points for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the udirection Setter: Sets number of control points for the udirection

ctrlpts_size_v
Â¶ Number of control points for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points on the vdirection Setter: Sets number of control points on the vdirection

data
Â¶ Returns a dictionary containing all shape data.
Please refer to the wiki for details on using this class member.

degree
Â¶ Degree for u and vdirections
Getter: Gets the degree Setter: Sets the degree Type: list

degree_u
Â¶ Degree for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the udirection Setter: Sets degree for the udirection Type: int

degree_v
Â¶ Degree for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the vdirection Setter: Sets degree for the vdirection Type: int

delta
Â¶ Evaluation delta for both u and vdirections.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta
andsample_size
properties correspond to the same variable with different descriptions. Therefore, settingdelta
will also setsample_size
.The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta as a tuple of values corresponding to u and vdirections Setter: Sets evaluation delta for both u and vdirections Type: float

delta_u
Â¶ Evaluation delta for the udirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_u
andsample_size_u
properties correspond to the same variable with different descriptions. Therefore, settingdelta_u
will also setsample_size_u
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the udirection Setter: Sets evaluation delta for the udirection Type: float

delta_v
Â¶ Evaluation delta for the vdirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_v
andsample_size_v
properties correspond to the same variable with different descriptions. Therefore, settingdelta_v
will also setsample_size_v
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the vdirection Setter: Sets evaluation delta for the vdirection Type: float

derivatives
(u, v, order=0, **kwargs)Â¶ Evaluates nth order surface derivatives at the given (u, v) parameter pair.
 SKL[0][0] will be the surface point itself
 SKL[0][1] will be the 1st derivative w.r.t. v
 SKL[2][1] will be the 2nd derivative w.r.t. u and 1st derivative w.r.t. v
Parameters:  u (float) â€“ parameter on the udirection
 v (float) â€“ parameter on the vdirection
 order (integer) â€“ derivative order
Returns: A list SKL, where SKL[k][l] is the derivative of the surface S(u,v) w.r.t. u k times and v l times
Return type: list

dimension
Â¶ Spatial dimension.
Spatial dimension will be automatically estimated from the first element of the control points array.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

domain
Â¶ Domain.
Domain is determined using the knot vector(s).
Getter: Gets the domain

evalpts
Â¶ Evaluated points.
Please refer to the wiki for details on using this class member.
Getter: Gets the coordinates of the evaluated points Type: list

evaluate
(**kwargs)Â¶ Evaluates the surface.
The evaluated surface points are stored in :py:attr:`~evalpts` property.
 Keyword arguments:
start_u
: start parameter on the udirectionstop_u
: stop parameter on the udirectionstart_v
: start parameter on the vdirectionstop_v
: stop parameter on the vdirection
The
start_u
,start_v
andstop_u
andstop_v
parameters allow evaluation of a surface segment in the range [start_u, stop_u][start_v, stop_v] i.e. the surface will also be evaluated at thestop_u
andstop_v
parameter values.The following examples illustrate the usage of the keyword arguments.
1 2 3 4 5 6 7 8
# Start evaluating in range u=[0, 0.7] and v=[0.1, 1] surf.evaluate(stop_u=0.7, start_v=0.1) # Start evaluating in range u=[0, 1] and v=[0.1, 0.3] surf.evaluate(start_v=0.1, stop_v=0.3) # Get the evaluated points surface_points = surf.evalpts

evaluate_list
(param_list)Â¶ Evaluates the surface for a given list of (u, v) parameters.
Parameters: param_list (list, tuple) â€“ list of parameter pairs (u, v) Returns: evaluated surface point at the input parameter pairs Return type: tuple

evaluate_single
(param)Â¶ Evaluates the surface at the input (u, v) parameter pair.
Parameters: param (list, tuple) â€“ parameter pair (u, v) Returns: evaluated surface point at the given parameter pair Return type: list

evaluator
Â¶ Evaluator instance.
Evaluators allow users to use different algorithms for BSpline and NURBS evaluations. Please see the documentation on
Evaluator
classes.Please refer to the wiki for details on using this class member.
Getter: Gets the current Evaluator instance Setter: Sets the Evaluator instance Type: evaluators.AbstractEvaluator

insert_knot
(u=None, v=None, **kwargs)Â¶ Inserts knot(s) in u or vdirections
If you keep a parameter assigned to
None
, there will be no knot insertion to that parametric direction. Keyword Arguments:
ru
: Number of knot insertions on the udirection. Default: 1rv
: Number of knot insertions on the vdirection. Default: 1
Parameters:  u (float) â€“ Knot to be inserted on the udirection
 v (float) â€“ Knot to be inserted on the vdirection

knotvector
Â¶ Knot vector for u and vdirections
Getter: Gets the knot vector Setter: Sets the knot vector Type: list

knotvector_u
Â¶ Knot vector for the udirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the udirection Setter: Sets knot vector for the udirection Type: list

knotvector_v
Â¶ Knot vector for the vdirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the vdirection Setter: Sets knot vector for the vdirection Type: list

load
(file_name)Â¶ Loads the surface from a pickled file.
Parameters: file_name (str) â€“ name of the file to be loaded Raises: IOError â€“ an error occurred reading the file

name
Â¶ Descriptor field for storing the shape identification data, such as names, ID numbers, etc.
Please refer to the wiki for details on using this class member.
Getter: Gets the descriptor Setter: Sets the descriptor Type: str

next
()Â¶

normal
(parpos, **kwargs)Â¶ Evaluates the normal vector of the surface at the given parametric position(s).
The
param
argument can be a float value for evaluation at a single parametric position
 a list of float values for evaluation at the multiple parametric positions
The parametric positions should be a pair of (u,v) values. The return value will be in the order of the input parametric position list.
This method accepts the following keyword arguments:
normalize
: normalizes the output vector. Default value is True.
Parameters: parpos (list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: an array containing â€œpointâ€ and â€œvectorâ€ pairs Return type: tuple

order_u
Â¶ Order for the udirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets order for the udirection Setter: Sets order for the udirection Type: int

order_v
Â¶ Order for the vdirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets surface order for the vdirection Setter: Sets surface order for the vdirection Type: int

pdimension
Â¶ Parametric dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the parametric dimension Type: int

range
Â¶ Domain range.
Getter: Gets the range

rational
Â¶ Defines the rational and nonrational Bspline shapes.
Rational shapes use homogeneous coordinates which includes a weight alongside with the Cartesian coordinates. Rational Bsplines are also named as NURBS (Nonuniform rational basis spline) and nonrational Bsplines are sometimes named as NUBS (Nonuniform basis spline) or directly as Bsplines.
Please refer to the wiki for details on using this class member.
Getter: Returns True is the Bspline object is rational (NURBS) Type: bool

render
(**kwargs)Â¶ Renders the surface using the visualization component.
The visualization component must be set using
vis
property before calling this method. Keyword Arguments:
cpcolor
: sets the color of the control points gridevalcolor
: sets the color of the surfacetrimcolor
: sets the color of the trim curvesfilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falseextras
: adds line plots to the figure. Default: Nonecolormap
: sets the colormap of the surface
The
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.extras
argument can be used to add extra line plots to the figure. This argument expects a list of dicts in the format described below:1 2 3 4 5 6 7 8 9 10 11 12 13 14
[ dict( # line plot 1 points=[[1, 2, 3], [4, 5, 6]], # list of points name="My line Plot 1", # name displayed on the legend color="red", # color of the line plot size=6.5 # size of the line plot ), dict( # line plot 2 points=[[7, 8, 9], [10, 11, 12]], # list of points name="My line Plot 2", # name displayed on the legend color="navy", # color of the line plot size=12.5 # size of the line plot ) ]
Please note that
colormap
argument can only work with visualization classes that support colormaps. As an example, please seeVisMPL.VisSurfTriangle()
class documentation. This method expects a single colormap input.

reset
(**kwargs)Â¶ Resets control points and/or evaluated points.
 Keyword Arguments:
evalpts
: if True, then resets evaluated pointsctrlpts
if True, then resets control points

sample_size
Â¶ Sample size for both u and vdirections.
Sample size defines the number of surface points to generate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size as a tuple of values corresponding to u and vdirections Setter: Sets sample size for both u and vdirections Type: int

sample_size_u
Â¶ Sample size for the udirection.
Sample size defines the number of surface points to generate. It also sets the
delta_u
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the udirection Setter: Sets sample size for the udirection Type: int

sample_size_v
Â¶ Sample size for the vdirection.
Sample size defines the number of surface points to generate. It also sets the
delta_v
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the vdirection Setter: Sets sample size for the vdirection Type: int

save
(file_name)Â¶ Saves the surface as a pickled file.
Parameters: file_name (str) â€“ name of the file to be saved Raises: IOError â€“ an error occurred writing the file

set_ctrlpts
(ctrlpts, *args, **kwargs)Â¶ Sets the control points and checks if the data is consistent.
This method is designed to provide a consistent way to set control points whether they are weighted or not. It directly sets the control points member of the class, and therefore it doesnâ€™t return any values. The input will be an array of coordinates. If you are working in the 3dimensional space, then your coordinates will be an array of 3 elements representing (x, y, z) coordinates.
This method also generates 2D control points in [u][v] format which can be accessed via
ctrlpts2d
.Note
The v index varies first. That is, a row of v control points for the first u value is found first. Then, the row of v control points for the next u value.
Parameters: ctrlpts (list) â€“ input control points as a list of coordinates

tangent
(parpos, **kwargs)Â¶ Evaluates the tangent vectors of the surface at the given parametric position(s).
The
param
argument can be a float value for evaluation at a single parametric position
 a list of float values for evaluation at the multiple parametric positions
The parametric positions should be a pair of (u,v) values. The return value will be in the order of the input parametric position list.
This method accepts the following keyword arguments:
normalize
: normalizes the output vector. Default value is True.
Parameters: parpos (list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: an array containing â€œpointâ€ and â€œvectorâ€s on u and vdirections, respectively Return type: tuple

tessellate
(**kwargs)Â¶ Tessellates the surface.
Keyword arguments are directly passed to the tessellation component.

tessellator
Â¶ Tessellation component.
Please refer to the wiki for details on using this class member.
Getter: Gets the tessellation component Setter: Sets the tessellation component

transpose
()Â¶ Transposes the surface by swapping u and v parametric directions.

trims
Â¶ Trim curves.
Trim curves are introduced to the surfaces on the parametric space. It should be an array (or list, tuple, etc.) and they are integrated to the existing visualization system.
Please refer to the wiki for details on using this class member.
Getter: Gets the array of trim curves Setter: Sets the array of trim curves
BSpline VolumeÂ¶

class
geomdl.BSpline.
Volume
(**kwargs)Â¶ Bases:
geomdl.abstract.Volume
Data storage and evaluation class for Bspline (nonrational) volumes.
This class provides the following properties:
order_u
order_v
order_w
degree_u
degree_v
degree_w
knotvector_u
knotvector_v
knotvector_w
ctrlpts
ctrlpts_size_u
ctrlpts_size_v
ctrlpts_size_w
delta
delta_u
delta_v
delta_w
sample_size
sample_size_u
sample_size_v
sample_size_w
bbox
name
dimension
vis
evaluator
rational
 Notes:
 Please see the
abstract.Volume()
documentation for details.  This class sets the FindSpan implementation to Linear Search by default.
 Please see the

bbox
Â¶ Bounding box.
Evaluates the bounding box and returns the minimum and maximum coordinates.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box Type: tuple

ctrlpts
Â¶ 1dimensional array of control points.
Please refer to the wiki for details on using this class member.
Getter: Gets the control points Setter: Sets the control points Type: list

ctrlpts_size
Â¶ Total number of control points.
Getter: Gets the total number of control points Type: int

ctrlpts_size_u
Â¶ Number of control points for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the udirection Setter: Sets number of control points for the udirection

ctrlpts_size_v
Â¶ Number of control points for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the vdirection Setter: Sets number of control points for the vdirection

ctrlpts_size_w
Â¶ Number of control points for the wdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the wdirection Setter: Sets number of control points for the wdirection

data
Â¶ Returns a dictionary containing all shape data.
Please refer to the wiki for details on using this class member.

degree
Â¶ Degree for u, v and wdirections
Getter: Gets the degree Setter: Sets the degree Type: list

degree_u
Â¶ Degree for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the udirection Setter: Sets degree for the udirection Type: int

degree_v
Â¶ Degree for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the vdirection Setter: Sets degree for the vdirection Type: int

degree_w
Â¶ Degree for the wdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the wdirection Setter: Sets degree for the wdirection Type: int

delta
Â¶ Evaluation delta for u, v and wdirections.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta
andsample_size
properties correspond to the same variable with different descriptions. Therefore, settingdelta
will also setsample_size
.The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta as a tuple of values corresponding to u, v and wdirections Setter: Sets evaluation delta for u, v and wdirections Type: float

delta_u
Â¶ Evaluation delta for the udirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_u
andsample_size_u
properties correspond to the same variable with different descriptions. Therefore, settingdelta_u
will also setsample_size_u
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the udirection Setter: Sets evaluation delta for the udirection Type: float

delta_v
Â¶ Evaluation delta for the vdirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_v
andsample_size_v
properties correspond to the same variable with different descriptions. Therefore, settingdelta_v
will also setsample_size_v
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the vdirection Setter: Sets evaluation delta for the vdirection Type: float

delta_w
Â¶ Evaluation delta for the wdirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_w
andsample_size_w
properties correspond to the same variable with different descriptions. Therefore, settingdelta_w
will also setsample_size_w
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the wdirection Setter: Sets evaluation delta for the wdirection Type: float

dimension
Â¶ Spatial dimension.
Spatial dimension will be automatically estimated from the first element of the control points array.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

domain
Â¶ Domain.
Domain is determined using the knot vector(s).
Getter: Gets the domain

evalpts
Â¶ Evaluated points.
Please refer to the wiki for details on using this class member.
Getter: Gets the coordinates of the evaluated points Type: list

evaluate
(**kwargs)Â¶ Evaluates the volume.
The evaluated points are stored in :py:attr:`~evalpts` property.
 Keyword arguments:
start_u
: start parameter on the udirectionstop_u
: stop parameter on the udirectionstart_v
: start parameter on the vdirectionstop_v
: stop parameter on the vdirectionstart_w
: start parameter on the wdirectionstop_w
: stop parameter on the wdirection

evaluate_list
(param_list)Â¶ Evaluates the volume for a given list of (u, v, w) parameters.
Parameters: param_list (list, tuple) â€“ list of parameters in format (u, v, w) Returns: evaluated surface point at the input parameter pairs Return type: tuple

evaluate_single
(param)Â¶ Evaluates the volume at the input (u, v, w) parameter.
Parameters: param (list, tuple) â€“ parameter (u, v, w) Returns: evaluated surface point at the given parameter pair Return type: list

evaluator
Â¶ Evaluator instance.
Evaluators allow users to use different algorithms for BSpline and NURBS evaluations. Please see the documentation on
Evaluator
classes.Please refer to the wiki for details on using this class member.
Getter: Gets the current Evaluator instance Setter: Sets the Evaluator instance Type: evaluators.AbstractEvaluator

knotvector
Â¶ Knot vector for u, v and wdirections
Getter: Gets the knot vector Setter: Sets the knot vector Type: list

knotvector_u
Â¶ Knot vector for the udirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the udirection Setter: Sets knot vector for the udirection Type: list

knotvector_v
Â¶ Knot vector for the vdirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the vdirection Setter: Sets knot vector for the vdirection Type: list

knotvector_w
Â¶ Knot vector for the wdirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the wdirection Setter: Sets knot vector for the wdirection Type: list

load
(file_name)Â¶ Loads the volume from a pickled file.
Parameters: file_name (str) â€“ name of the file to be loaded Raises: IOError â€“ an error occurred reading the file

name
Â¶ Descriptor field for storing the shape identification data, such as names, ID numbers, etc.
Please refer to the wiki for details on using this class member.
Getter: Gets the descriptor Setter: Sets the descriptor Type: str

next
()Â¶

order_u
Â¶ Order for the udirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the surface order for udirection Setter: Sets the surface order for udirection Type: int

order_v
Â¶ Order for the vdirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the surface order for vdirection Setter: Sets the surface order for vdirection Type: int

order_w
Â¶ Order for the wdirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the surface order for vdirection Setter: Sets the surface order for vdirection Type: int

pdimension
Â¶ Parametric dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the parametric dimension Type: int

range
Â¶ Domain range.
Getter: Gets the range

rational
Â¶ Defines the rational and nonrational Bspline shapes.
Rational shapes use homogeneous coordinates which includes a weight alongside with the Cartesian coordinates. Rational Bsplines are also named as NURBS (Nonuniform rational basis spline) and nonrational Bsplines are sometimes named as NUBS (Nonuniform basis spline) or directly as Bsplines.
Please refer to the wiki for details on using this class member.
Getter: Returns True is the Bspline object is rational (NURBS) Type: bool

render
(**kwargs)Â¶ Renders the volume using the visualization component.
The visualization component must be set using
vis
property before calling this method. Keyword Arguments:
cpcolor
: sets the color of the control pointsevalcolor
: sets the color of the volumefilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falsegrid_size
: grid size for voxelization. Default: (16, 16, 16)use_mp
: flag to activate multithreaded voxelization. Default: Falsenum_procs
: number of concurrent processes for multithreaded voxelization. Default: 4
The
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.extras
argument can be used to add extra line plots to the figure. This argument expects a list of dicts in the format described below:1 2 3 4 5 6 7 8 9 10 11 12 13 14
[ dict( # line plot 1 points=[[1, 2, 3], [4, 5, 6]], # list of points name="My line Plot 1", # name displayed on the legend color="red", # color of the line plot size=6.5 # size of the line plot ), dict( # line plot 2 points=[[7, 8, 9], [10, 11, 12]], # list of points name="My line Plot 2", # name displayed on the legend color="navy", # color of the line plot size=12.5 # size of the line plot ) ]

reset
(**kwargs)Â¶ Resets control points and/or evaluated points.
 Keyword Arguments:
evalpts
: if True, then resets evaluated pointsctrlpts
if True, then resets control points

sample_size
Â¶ Sample size for both u and vdirections.
Sample size defines the number of surface points to generate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size as a tuple of values corresponding to u, v and wdirections Setter: Sets sample size value for both u, v and wdirections Type: int

sample_size_u
Â¶ Sample size for the udirection.
Sample size defines the number of evaluated points to generate. It also sets the
delta_u
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the udirection Setter: Sets sample size for the udirection Type: int

sample_size_v
Â¶ Sample size for the vdirection.
Sample size defines the number of evaluated points to generate. It also sets the
delta_v
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the vdirection Setter: Sets sample size for the vdirection Type: int

sample_size_w
Â¶ Sample size for the wdirection.
Sample size defines the number of evaluated points to generate. It also sets the
delta_w
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the wdirection Setter: Sets sample size for the wdirection Type: int

save
(file_name)Â¶ Saves the volume as a pickled file.
Parameters: file_name (str) â€“ name of the file to be saved Raises: IOError â€“ an error occurred writing the file

set_ctrlpts
(ctrlpts, *args, **kwargs)Â¶ Sets the control points and checks if the data is consistent.
This method is designed to provide a consistent way to set control points whether they are weighted or not. It directly sets the control points member of the class, and therefore it doesnâ€™t return any values. The input will be an array of coordinates. If you are working in the 3dimensional space, then your coordinates will be an array of 3 elements representing (x, y, z) coordinates.
Parameters:  ctrlpts (list) â€“ input control points as a list of coordinates
 args (tuple[int, int, int]) â€“ number of control points corresponding to each parametric dimension
NURBS GeometryÂ¶
NURBS
module provides data storage and evaluation functions for rational spline geometries.
Inheritance DiagramÂ¶
NURBS CurveÂ¶

class
geomdl.NURBS.
Curve
(**kwargs)Â¶ Bases:
geomdl.BSpline.Curve
Data storage and evaluation class for nvariate NURBS (rational) curves.
The rational shapes have some minor differences between the nonrational ones. This class is designed to operate with weighted control points (Pw) as described in The NURBS Book by Piegl and Tiller. Therefore, it provides a different set of properties (i.e. getters and setters):
ctrlptsw
: 1dimensional array of weighted control pointsctrlpts
: 1dimensional array of control pointsweights
: 1dimensional array of weights
You may also use
set_ctrlpts()
function which is designed to work with all types of control points.This class provides the following properties:
order
degree
knotvector
ctrlptsw
ctrlpts
weights
delta
sample_size
bbox
vis
name
dimension
evaluator
rational
 Notes:
 Please see the
abstract.Surface()
documentation for details.  This class sets the FindSpan implementation to Linear Search by default.
 Please see the
Please refer to
ex_curve04.py
in the Examples repository for a NURBS curve example.
bbox
Â¶ Bounding box.
Evaluates the bounding box and returns the minimum and maximum coordinates.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box Type: tuple

binormal
(parpos, **kwargs)Â¶ Evaluates the binormal vector of the curve at the given parametric position(s).
The
param
argument can be a float value for evaluation at a single parametric position
 a list of float values for evaluation at the multiple parametric positions
The return value will be in the order of the input parametric position list.
This method accepts the following keyword arguments:
normalize
: normalizes the output vector. Default value is True.
Parameters: parpos (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: an array containing â€œpointâ€ and â€œvectorâ€ pairs Return type: tuple

ctrlpts
Â¶ Control points (P).
Please refer to the wiki for details on using this class member.
Getter: Gets unweighted control points. Use weights
to get weights vector.Setter: Sets unweighted control points Type: list

ctrlpts_size
Â¶ Total number of control points.
Getter: Gets the total number of control points Type: int

ctrlptsw
Â¶ Weighted control points (Pw).
Weighted control points are in (x*w, y*w, z*w, w) format; where x,y,z are the coordinates and w is the weight.
Please refer to the wiki for details on using this class member.
Getter: Gets the weighted control points Setter: Sets the weighted control points

data
Â¶ Returns a dictionary containing all shape data.
Please refer to the wiki for details on using this class member.

degree
Â¶ Degree.
Please refer to the wiki for details on using this class member.
Getter: Gets the degree Setter: Sets the degree Type: int

delta
Â¶ Evaluation delta.
Evaluation delta corresponds to the step size while
evaluate
function iterates on the knot vector to generate curve points. Decreasing step size results in generation of more curve points. Therefore; smaller the delta value, smoother the curve.The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets the delta value Setter: Sets the delta value Type: float

derivatives
(u, order=0, **kwargs)Â¶ Evaluates nth order curve derivatives at the given parameter value.
Parameters:  u (float) â€“ parameter value
 order (int) â€“ derivative order
Returns: a list containing up to {order}th derivative of the curve
Return type: list

dimension
Â¶ Spatial dimension.
Spatial dimension will be automatically estimated from the first element of the control points array.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

domain
Â¶ Domain.
Domain is determined using the knot vector(s).
Getter: Gets the domain

evalpts
Â¶ Evaluated points.
Please refer to the wiki for details on using this class member.
Getter: Gets the coordinates of the evaluated points Type: list

evaluate
(**kwargs)Â¶ Evaluates the curve.
The evaluated curve points are stored in :py:attr:`~evalpts` property.
 Keyword arguments:
start
: start parameterstop
: stop parameter
The
start
andstop
parameters allow evaluation of a curve segment in the range [start, stop], i.e. the curve will also be evaluated at thestop
parameter value.The following examples illustrate the usage of the keyword arguments.
# Start evaluating from u=0.2 to u=1.0 curve.evaluate(start=0.2) # Start evaluating from u=0.0 to u=0.7 curve.evaluate(stop=0.7) # Start evaluating from u=0.1 to u=0.5 curve.evaluate(start=0.1, stop=0.5) # Get the evaluated points curve_points = curve.evalpts

evaluate_list
(param_list)Â¶ Evaluates the curve for an input range of parameters.
Parameters: param_list (list, tuple) â€“ list of parameters Returns: evaluated surface points at the input parameters Return type: list

evaluate_single
(param)Â¶ Evaluates the curve at the input parameter.
Parameters: param (float) â€“ parameter Returns: evaluated surface point at the given parameter Return type: list

evaluator
Â¶ Evaluator instance.
Evaluators allow users to use different algorithms for BSpline and NURBS evaluations. Please see the documentation on
Evaluator
classes.Please refer to the wiki for details on using this class member.
Getter: Gets the current Evaluator instance Setter: Sets the Evaluator instance Type: evaluators.AbstractEvaluator

insert_knot
(u, **kwargs)Â¶ Inserts the given knot and updates the control points array and the knot vector.
 Keyword Arguments:
r
: Number of knot insertions. Default: 1
Parameters: u (float) â€“ knot to be inserted

knotvector
Â¶ Knot vector.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets the knot vector Setter: Sets the knot vector Type: list

load
(file_name)Â¶ Loads the curve from a pickled file.
Parameters: file_name (str) â€“ name of the file to be loaded Raises: IOError â€“ an error occurred reading the file

name
Â¶ Descriptor field for storing the shape identification data, such as names, ID numbers, etc.
Please refer to the wiki for details on using this class member.
Getter: Gets the descriptor Setter: Sets the descriptor Type: str

next
()Â¶

normal
(parpos, **kwargs)Â¶ Evaluates the normal vector of the curve at the given parametric position(s).
The
param
argument can be a float value for evaluation at a single parametric position
 a list of float values for evaluation at the multiple parametric positions
The return value will be in the order of the input parametric position list.
This method accepts the following keyword arguments:
normalize
: normalizes the output vector. Default value is True.
Parameters: parpos (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: an array containing â€œpointâ€ and â€œvectorâ€ pairs Return type: tuple

order
Â¶ Order.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the order Setter: Sets the order Type: int

pdimension
Â¶ Parametric dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the parametric dimension Type: int

range
Â¶ Domain range.
Getter: Gets the range

rational
Â¶ Defines the rational and nonrational Bspline shapes.
Rational shapes use homogeneous coordinates which includes a weight alongside with the Cartesian coordinates. Rational Bsplines are also named as NURBS (Nonuniform rational basis spline) and nonrational Bsplines are sometimes named as NUBS (Nonuniform basis spline) or directly as Bsplines.
Please refer to the wiki for details on using this class member.
Getter: Returns True is the Bspline object is rational (NURBS) Type: bool

render
(**kwargs)Â¶ Renders the curve using the visualization component
The visualization component must be set using
vis
property before calling this method. Keyword Arguments:
cpcolor
: sets the color of the control points polygonevalcolor
: sets the color of the curvebboxcolor
: sets the color of the bounding boxfilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falseextras
: adds line plots to the figure. Default: None
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.extras
argument can be used to add extra line plots to the figure. This argument expects a list of dicts in the format described below:1 2 3 4 5 6 7 8 9 10 11 12 13 14
[ dict( # line plot 1 points=[[1, 2, 3], [4, 5, 6]], # list of points name="My line Plot 1", # name displayed on the legend color="red", # color of the line plot size=6.5 # size of the line plot ), dict( # line plot 2 points=[[7, 8, 9], [10, 11, 12]], # list of points name="My line Plot 2", # name displayed on the legend color="navy", # color of the line plot size=12.5 # size of the line plot ) ]

reset
(**kwargs)Â¶ Resets control points and/or evaluated points.
Keyword Arguments:
evalpts
: if True, then resets evaluated pointsctrlpts
if True, then resets control points

sample_size
Â¶ Sample size.
Sample size defines the number of evaluated points to generate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size Setter: Sets sample size Type: int

save
(file_name)Â¶ Saves the curve as a pickled file.
Parameters: file_name (str) â€“ name of the file to be saved Raises: IOError â€“ an error occurred writing the file

set_ctrlpts
(ctrlpts, *args, **kwargs)Â¶ Sets control points and checks if the data is consistent.
This method is designed to provide a consistent way to set control points whether they are weighted or not. It directly sets the control points member of the class, and therefore it doesnâ€™t return any values. The input will be an array of coordinates. If you are working in the 3dimensional space, then your coordinates will be an array of 3 elements representing (x, y, z) coordinates.
Parameters: ctrlpts (list) â€“ input control points as a list of coordinates

tangent
(param, **kwargs)Â¶ Evaluates the tangent vector of the curve at the given parametric position(s).
The
param
argument can be a float value for evaluation at a single parametric position
 a list of float values for evaluation at the multiple parametric positions
The return value will be in the order of the input parametric position list.
This method accepts the following keyword arguments:
normalize
: normalizes the output vector. Default value is True.
Parameters: param (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: an array containing â€œpointâ€ and â€œvectorâ€ pairs Return type: tuple
NURBS SurfaceÂ¶

class
geomdl.NURBS.
Surface
(**kwargs)Â¶ Bases:
geomdl.BSpline.Surface
Data storage and evaluation class for NURBS (rational) surfaces.
The rational shapes have some minor differences between the nonrational ones. This class is designed to operate with weighted control points (Pw) as described in The NURBS Book by Piegl and Tiller. Therefore, it provides a different set of properties (i.e. getters and setters):
ctrlptsw
: 1dimensional array of weighted control pointsctrlpts2d
: 2dimensional array of weighted control pointsctrlpts
: 1dimensional array of control pointsweights
: 1dimensional array of weights
You may also use
set_ctrlpts()
function which is designed to work with all types of control points.This class provides the following properties:
order_u
order_v
degree_u
degree_v
knotvector_u
knotvector_v
ctrlptsw
ctrlpts
weights
ctrlpts_size_u
ctrlpts_size_v
ctrlpts2d
delta
delta_u
delta_v
sample_size
sample_size_u
sample_size_v
bbox
name
dimension
vis
evaluator
tessellator
rational
trims
 Notes:
 Please see the
abstract.Surface()
documentation for details.  This class sets the FindSpan implementation to Linear Search by default.
 Please see the
Please refer to
ex_surface03.py
in the Examples repository for a NURBS surface example.
bbox
Â¶ Bounding box.
Evaluates the bounding box and returns the minimum and maximum coordinates.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box Type: tuple

ctrlpts
Â¶ 1dimensional array of control points (P).
This property sets and gets the control points in 1D.
Getter: Gets unweighted control points. Use weights
to get weights vector.Setter: Sets unweighted control points. Type: list

ctrlpts2d
Â¶ 2dimensional array of control points.
The getter returns a tuple of 2D control points (weighted control points + weights if NURBS) in [u][v] format. The rows of the returned tuple correspond to vdirection and the columns correspond to udirection.
The following example can be used to traverse 2D control points:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# Create a BSpline surface surf_bs = BSpline.Surface() # Do degree, control points and knot vector assignments here # Each u includes a row of v values for u in surf_bs.ctrlpts2d: # Each row contains the coordinates of the control points for v in u: print(str(v)) # will be something like (1.0, 2.0, 3.0) # Create a NURBS surface surf_nb = NURBS.Surface() # Do degree, weighted control points and knot vector assignments here # Each u includes a row of v values for u in surf_nb.ctrlpts2d: # Each row contains the coordinates of the weighted control points for v in u: print(str(v)) # will be something like (0.5, 1.0, 1.5, 0.5)
When using NURBS.Surface class, the output of
ctrlpts2d
property could be confusing since,ctrlpts
always returns the unweighted control points, i.e.ctrlpts
property returns 3D control points all divided by the weights and you can useweights
property to access the weights vector, butctrlpts2d
returns the weighted ones plus weights as the last element. This difference is intentionally added for compatibility and interoperability purposes.To explain this situation in a simple way;
 If you need the weighted control points directly, use
ctrlpts2d
 If you need the control points and the weights separately, use
ctrlpts
andweights
Note
Please note that the setter doesnâ€™t check for inconsistencies and using the setter is not recommended. Instead of the setter property, please use
set_ctrlpts()
function.Please refer to the wiki for details on using this class member.
Getter: Gets the control points as a 2dimensional array in [u][v] format Setter: Sets the control points as a 2dimensional array in [u][v] format Type: list  If you need the weighted control points directly, use

ctrlpts_size
Â¶ Total number of control points.
Getter: Gets the total number of control points Type: int

ctrlpts_size_u
Â¶ Number of control points for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the udirection Setter: Sets number of control points for the udirection

ctrlpts_size_v
Â¶ Number of control points for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points on the vdirection Setter: Sets number of control points on the vdirection

ctrlptsw
Â¶ 1dimensional array of weighted control points (Pw).
Weighted control points are in (x*w, y*w, z*w, w) format; where x,y,z are the coordinates and w is the weight.
This property sets and gets the control points in 1D.
Getter: Gets weighted control points Setter: Sets weighted control points

data
Â¶ Returns a dictionary containing all shape data.
Please refer to the wiki for details on using this class member.

degree
Â¶ Degree for u and vdirections
Getter: Gets the degree Setter: Sets the degree Type: list

degree_u
Â¶ Degree for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the udirection Setter: Sets degree for the udirection Type: int

degree_v
Â¶ Degree for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the vdirection Setter: Sets degree for the vdirection Type: int

delta
Â¶ Evaluation delta for both u and vdirections.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta
andsample_size
properties correspond to the same variable with different descriptions. Therefore, settingdelta
will also setsample_size
.The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta as a tuple of values corresponding to u and vdirections Setter: Sets evaluation delta for both u and vdirections Type: float

delta_u
Â¶ Evaluation delta for the udirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_u
andsample_size_u
properties correspond to the same variable with different descriptions. Therefore, settingdelta_u
will also setsample_size_u
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the udirection Setter: Sets evaluation delta for the udirection Type: float

delta_v
Â¶ Evaluation delta for the vdirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_v
andsample_size_v
properties correspond to the same variable with different descriptions. Therefore, settingdelta_v
will also setsample_size_v
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the vdirection Setter: Sets evaluation delta for the vdirection Type: float

derivatives
(u, v, order=0, **kwargs)Â¶ Evaluates nth order surface derivatives at the given (u, v) parameter pair.
 SKL[0][0] will be the surface point itself
 SKL[0][1] will be the 1st derivative w.r.t. v
 SKL[2][1] will be the 2nd derivative w.r.t. u and 1st derivative w.r.t. v
Parameters:  u (float) â€“ parameter on the udirection
 v (float) â€“ parameter on the vdirection
 order (integer) â€“ derivative order
Returns: A list SKL, where SKL[k][l] is the derivative of the surface S(u,v) w.r.t. u k times and v l times
Return type: list

dimension
Â¶ Spatial dimension.
Spatial dimension will be automatically estimated from the first element of the control points array.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

domain
Â¶ Domain.
Domain is determined using the knot vector(s).
Getter: Gets the domain

evalpts
Â¶ Evaluated points.
Please refer to the wiki for details on using this class member.
Getter: Gets the coordinates of the evaluated points Type: list

evaluate
(**kwargs)Â¶ Evaluates the surface.
The evaluated surface points are stored in :py:attr:`~evalpts` property.
 Keyword arguments:
start_u
: start parameter on the udirectionstop_u
: stop parameter on the udirectionstart_v
: start parameter on the vdirectionstop_v
: stop parameter on the vdirection
The
start_u
,start_v
andstop_u
andstop_v
parameters allow evaluation of a surface segment in the range [start_u, stop_u][start_v, stop_v] i.e. the surface will also be evaluated at thestop_u
andstop_v
parameter values.The following examples illustrate the usage of the keyword arguments.
1 2 3 4 5 6 7 8
# Start evaluating in range u=[0, 0.7] and v=[0.1, 1] surf.evaluate(stop_u=0.7, start_v=0.1) # Start evaluating in range u=[0, 1] and v=[0.1, 0.3] surf.evaluate(start_v=0.1, stop_v=0.3) # Get the evaluated points surface_points = surf.evalpts

evaluate_list
(param_list)Â¶ Evaluates the surface for a given list of (u, v) parameters.
Parameters: param_list (list, tuple) â€“ list of parameter pairs (u, v) Returns: evaluated surface point at the input parameter pairs Return type: tuple

evaluate_single
(param)Â¶ Evaluates the surface at the input (u, v) parameter pair.
Parameters: param (list, tuple) â€“ parameter pair (u, v) Returns: evaluated surface point at the given parameter pair Return type: list

evaluator
Â¶ Evaluator instance.
Evaluators allow users to use different algorithms for BSpline and NURBS evaluations. Please see the documentation on
Evaluator
classes.Please refer to the wiki for details on using this class member.
Getter: Gets the current Evaluator instance Setter: Sets the Evaluator instance Type: evaluators.AbstractEvaluator

insert_knot
(u=None, v=None, **kwargs)Â¶ Inserts knot(s) in u or vdirections
If you keep a parameter assigned to
None
, there will be no knot insertion to that parametric direction. Keyword Arguments:
ru
: Number of knot insertions on the udirection. Default: 1rv
: Number of knot insertions on the vdirection. Default: 1
Parameters:  u (float) â€“ Knot to be inserted on the udirection
 v (float) â€“ Knot to be inserted on the vdirection

knotvector
Â¶ Knot vector for u and vdirections
Getter: Gets the knot vector Setter: Sets the knot vector Type: list

knotvector_u
Â¶ Knot vector for the udirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the udirection Setter: Sets knot vector for the udirection Type: list

knotvector_v
Â¶ Knot vector for the vdirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the vdirection Setter: Sets knot vector for the vdirection Type: list

load
(file_name)Â¶ Loads the surface from a pickled file.
Parameters: file_name (str) â€“ name of the file to be loaded Raises: IOError â€“ an error occurred reading the file

name
Â¶ Descriptor field for storing the shape identification data, such as names, ID numbers, etc.
Please refer to the wiki for details on using this class member.
Getter: Gets the descriptor Setter: Sets the descriptor Type: str

next
()Â¶

normal
(parpos, **kwargs)Â¶ Evaluates the normal vector of the surface at the given parametric position(s).
The
param
argument can be a float value for evaluation at a single parametric position
 a list of float values for evaluation at the multiple parametric positions
The parametric positions should be a pair of (u,v) values. The return value will be in the order of the input parametric position list.
This method accepts the following keyword arguments:
normalize
: normalizes the output vector. Default value is True.
Parameters: parpos (list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: an array containing â€œpointâ€ and â€œvectorâ€ pairs Return type: tuple

order_u
Â¶ Order for the udirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets order for the udirection Setter: Sets order for the udirection Type: int

order_v
Â¶ Order for the vdirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets surface order for the vdirection Setter: Sets surface order for the vdirection Type: int

pdimension
Â¶ Parametric dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the parametric dimension Type: int

range
Â¶ Domain range.
Getter: Gets the range

rational
Â¶ Defines the rational and nonrational Bspline shapes.
Rational shapes use homogeneous coordinates which includes a weight alongside with the Cartesian coordinates. Rational Bsplines are also named as NURBS (Nonuniform rational basis spline) and nonrational Bsplines are sometimes named as NUBS (Nonuniform basis spline) or directly as Bsplines.
Please refer to the wiki for details on using this class member.
Getter: Returns True is the Bspline object is rational (NURBS) Type: bool

render
(**kwargs)Â¶ Renders the surface using the visualization component.
The visualization component must be set using
vis
property before calling this method. Keyword Arguments:
cpcolor
: sets the color of the control points gridevalcolor
: sets the color of the surfacetrimcolor
: sets the color of the trim curvesfilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falseextras
: adds line plots to the figure. Default: Nonecolormap
: sets the colormap of the surface
The
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.extras
argument can be used to add extra line plots to the figure. This argument expects a list of dicts in the format described below:1 2 3 4 5 6 7 8 9 10 11 12 13 14
[ dict( # line plot 1 points=[[1, 2, 3], [4, 5, 6]], # list of points name="My line Plot 1", # name displayed on the legend color="red", # color of the line plot size=6.5 # size of the line plot ), dict( # line plot 2 points=[[7, 8, 9], [10, 11, 12]], # list of points name="My line Plot 2", # name displayed on the legend color="navy", # color of the line plot size=12.5 # size of the line plot ) ]
Please note that
colormap
argument can only work with visualization classes that support colormaps. As an example, please seeVisMPL.VisSurfTriangle()
class documentation. This method expects a single colormap input.

reset
(**kwargs)Â¶ Resets control points and/or evaluated points.
Keyword Arguments:
evalpts
: if True, then resets evaluated pointsctrlpts
if True, then resets control points

sample_size
Â¶ Sample size for both u and vdirections.
Sample size defines the number of surface points to generate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size as a tuple of values corresponding to u and vdirections Setter: Sets sample size for both u and vdirections Type: int

sample_size_u
Â¶ Sample size for the udirection.
Sample size defines the number of surface points to generate. It also sets the
delta_u
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the udirection Setter: Sets sample size for the udirection Type: int

sample_size_v
Â¶ Sample size for the vdirection.
Sample size defines the number of surface points to generate. It also sets the
delta_v
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the vdirection Setter: Sets sample size for the vdirection Type: int

save
(file_name)Â¶ Saves the surface as a pickled file.
Parameters: file_name (str) â€“ name of the file to be saved Raises: IOError â€“ an error occurred writing the file

set_ctrlpts
(ctrlpts, *args, **kwargs)Â¶ Sets the control points and checks if the data is consistent.
This method is designed to provide a consistent way to set control points whether they are weighted or not. It directly sets the control points member of the class, and therefore it doesnâ€™t return any values. The input will be an array of coordinates. If you are working in the 3dimensional space, then your coordinates will be an array of 3 elements representing (x, y, z) coordinates.
This method also generates 2D control points in [u][v] format which can be accessed via
ctrlpts2d
.Note
The v index varies first. That is, a row of v control points for the first u value is found first. Then, the row of v control points for the next u value.
Parameters: ctrlpts (list) â€“ input control points as a list of coordinates

tangent
(parpos, **kwargs)Â¶ Evaluates the tangent vectors of the surface at the given parametric position(s).
The
param
argument can be a float value for evaluation at a single parametric position
 a list of float values for evaluation at the multiple parametric positions
The parametric positions should be a pair of (u,v) values. The return value will be in the order of the input parametric position list.
This method accepts the following keyword arguments:
normalize
: normalizes the output vector. Default value is True.
Parameters: parpos (list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: an array containing â€œpointâ€ and â€œvectorâ€s on u and vdirections, respectively Return type: tuple

tessellate
(**kwargs)Â¶ Tessellates the surface.
Keyword arguments are directly passed to the tessellation component.

tessellator
Â¶ Tessellation component.
Please refer to the wiki for details on using this class member.
Getter: Gets the tessellation component Setter: Sets the tessellation component

transpose
()Â¶ Transposes the surface by swapping u and v parametric directions.

trims
Â¶ Trim curves.
Trim curves are introduced to the surfaces on the parametric space. It should be an array (or list, tuple, etc.) and they are integrated to the existing visualization system.
Please refer to the wiki for details on using this class member.
Getter: Gets the array of trim curves Setter: Sets the array of trim curves

vis
Â¶ Visualization component.
Please refer to the wiki for details on using this class member.
Getter: Gets the visualization component Setter: Sets the visualization component Type: vis.VisAbstract

weights
Â¶ Weights vector.
Getter: Gets the weights vector Setter: Sets the weights vector Type: list
NURBS VolumeÂ¶

class
geomdl.NURBS.
Volume
(**kwargs)Â¶ Bases:
geomdl.BSpline.Volume
Data storage and evaluation class for NURBS (rational) volumes.
The rational shapes have some minor differences between the nonrational ones. This class is designed to operate with weighted control points (Pw) as described in The NURBS Book by Piegl and Tiller. Therefore, it provides a different set of properties (i.e. getters and setters):
ctrlptsw
: 1dimensional array of weighted control pointsctrlpts
: 1dimensional array of control pointsweights
: 1dimensional array of weights
This class provides the following properties:
order_u
order_v
order_w
degree_u
degree_v
degree_w
knotvector_u
knotvector_v
knotvector_w
ctrlptsw
ctrlpts
weights
ctrlpts_size_u
ctrlpts_size_v
ctrlpts_size_w
delta
delta_u
delta_v
delta_w
sample_size
sample_size_u
sample_size_v
sample_size_w
bbox
name
dimension
vis
evaluator
rational
 Notes:
 Please see the
abstract.Volume()
documentation for details.  This class sets the FindSpan implementation to Linear Search by default.
 Please see the

bbox
Â¶ Bounding box.
Evaluates the bounding box and returns the minimum and maximum coordinates.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box Type: tuple

ctrlpts
Â¶ 1dimensional array of control points (P).
This property sets and gets the control points in 1D.
Getter: Gets unweighted control points. Use weights
to get weights vector.Setter: Sets unweighted control points. Type: list

ctrlpts_size
Â¶ Total number of control points.
Getter: Gets the total number of control points Type: int

ctrlpts_size_u
Â¶ Number of control points for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the udirection Setter: Sets number of control points for the udirection

ctrlpts_size_v
Â¶ Number of control points for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the vdirection Setter: Sets number of control points for the vdirection

ctrlpts_size_w
Â¶ Number of control points for the wdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets number of control points for the wdirection Setter: Sets number of control points for the wdirection

ctrlptsw
Â¶ 1dimensional array of weighted control points (Pw).
Weighted control points are in (x*w, y*w, z*w, w) format; where x,y,z are the coordinates and w is the weight.
This property sets and gets the control points in 1D.
Getter: Gets weighted control points Setter: Sets weighted control points

data
Â¶ Returns a dictionary containing all shape data.
Please refer to the wiki for details on using this class member.

degree
Â¶ Degree for u, v and wdirections
Getter: Gets the degree Setter: Sets the degree Type: list

degree_u
Â¶ Degree for the udirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the udirection Setter: Sets degree for the udirection Type: int

degree_v
Â¶ Degree for the vdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the vdirection Setter: Sets degree for the vdirection Type: int

degree_w
Â¶ Degree for the wdirection.
Please refer to the wiki for details on using this class member.
Getter: Gets degree for the wdirection Setter: Sets degree for the wdirection Type: int

delta
Â¶ Evaluation delta for u, v and wdirections.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta
andsample_size
properties correspond to the same variable with different descriptions. Therefore, settingdelta
will also setsample_size
.The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta as a tuple of values corresponding to u, v and wdirections Setter: Sets evaluation delta for u, v and wdirections Type: float

delta_u
Â¶ Evaluation delta for the udirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_u
andsample_size_u
properties correspond to the same variable with different descriptions. Therefore, settingdelta_u
will also setsample_size_u
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the udirection Setter: Sets evaluation delta for the udirection Type: float

delta_v
Â¶ Evaluation delta for the vdirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_v
andsample_size_v
properties correspond to the same variable with different descriptions. Therefore, settingdelta_v
will also setsample_size_v
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the vdirection Setter: Sets evaluation delta for the vdirection Type: float

delta_w
Â¶ Evaluation delta for the wdirection.
Evaluation delta corresponds to the step size while
evaluate()
function iterates on the knot vector to generate surface points. Decreasing step size results in generation of more surface points. Therefore; smaller the delta value, smoother the surface.Please note that
delta_w
andsample_size_w
properties correspond to the same variable with different descriptions. Therefore, settingdelta_w
will also setsample_size_w
.Please refer to the wiki for details on using this class member.
Getter: Gets evaluation delta for the wdirection Setter: Sets evaluation delta for the wdirection Type: float

dimension
Â¶ Spatial dimension.
Spatial dimension will be automatically estimated from the first element of the control points array.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

domain
Â¶ Domain.
Domain is determined using the knot vector(s).
Getter: Gets the domain

evalpts
Â¶ Evaluated points.
Please refer to the wiki for details on using this class member.
Getter: Gets the coordinates of the evaluated points Type: list

evaluate
(**kwargs)Â¶ Evaluates the volume.
The evaluated points are stored in :py:attr:`~evalpts` property.
 Keyword arguments:
start_u
: start parameter on the udirectionstop_u
: stop parameter on the udirectionstart_v
: start parameter on the vdirectionstop_v
: stop parameter on the vdirectionstart_w
: start parameter on the wdirectionstop_w
: stop parameter on the wdirection

evaluate_list
(param_list)Â¶ Evaluates the volume for a given list of (u, v, w) parameters.
Parameters: param_list (list, tuple) â€“ list of parameters in format (u, v, w) Returns: evaluated surface point at the input parameter pairs Return type: tuple

evaluate_single
(param)Â¶ Evaluates the volume at the input (u, v, w) parameter.
Parameters: param (list, tuple) â€“ parameter (u, v, w) Returns: evaluated surface point at the given parameter pair Return type: list

evaluator
Â¶ Evaluator instance.
Evaluators allow users to use different algorithms for BSpline and NURBS evaluations. Please see the documentation on
Evaluator
classes.Please refer to the wiki for details on using this class member.
Getter: Gets the current Evaluator instance Setter: Sets the Evaluator instance Type: evaluators.AbstractEvaluator

knotvector
Â¶ Knot vector for u, v and wdirections
Getter: Gets the knot vector Setter: Sets the knot vector Type: list

knotvector_u
Â¶ Knot vector for the udirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the udirection Setter: Sets knot vector for the udirection Type: list

knotvector_v
Â¶ Knot vector for the vdirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the vdirection Setter: Sets knot vector for the vdirection Type: list

knotvector_w
Â¶ Knot vector for the wdirection.
The knot vector will be normalized to [0, 1] domain if the class is initialized with
normalize_kv=True
argument.Please refer to the wiki for details on using this class member.
Getter: Gets knot vector for the wdirection Setter: Sets knot vector for the wdirection Type: list

load
(file_name)Â¶ Loads the volume from a pickled file.
Parameters: file_name (str) â€“ name of the file to be loaded Raises: IOError â€“ an error occurred reading the file

name
Â¶ Descriptor field for storing the shape identification data, such as names, ID numbers, etc.
Please refer to the wiki for details on using this class member.
Getter: Gets the descriptor Setter: Sets the descriptor Type: str

next
()Â¶

order_u
Â¶ Order for the udirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the surface order for udirection Setter: Sets the surface order for udirection Type: int

order_v
Â¶ Order for the vdirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the surface order for vdirection Setter: Sets the surface order for vdirection Type: int

order_w
Â¶ Order for the wdirection.
Defined as
order = degree + 1
Please refer to the wiki for details on using this class member.
Getter: Gets the surface order for vdirection Setter: Sets the surface order for vdirection Type: int

pdimension
Â¶ Parametric dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the parametric dimension Type: int

range
Â¶ Domain range.
Getter: Gets the range

rational
Â¶ Defines the rational and nonrational Bspline shapes.
Rational shapes use homogeneous coordinates which includes a weight alongside with the Cartesian coordinates. Rational Bsplines are also named as NURBS (Nonuniform rational basis spline) and nonrational Bsplines are sometimes named as NUBS (Nonuniform basis spline) or directly as Bsplines.
Please refer to the wiki for details on using this class member.
Getter: Returns True is the Bspline object is rational (NURBS) Type: bool

render
(**kwargs)Â¶ Renders the volume using the visualization component.
The visualization component must be set using
vis
property before calling this method. Keyword Arguments:
cpcolor
: sets the color of the control pointsevalcolor
: sets the color of the volumefilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falsegrid_size
: grid size for voxelization. Default: (16, 16, 16)use_mp
: flag to activate multithreaded voxelization. Default: Falsenum_procs
: number of concurrent processes for multithreaded voxelization. Default: 4
The
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.extras
argument can be used to add extra line plots to the figure. This argument expects a list of dicts in the format described below:1 2 3 4 5 6 7 8 9 10 11 12 13 14
[ dict( # line plot 1 points=[[1, 2, 3], [4, 5, 6]], # list of points name="My line Plot 1", # name displayed on the legend color="red", # color of the line plot size=6.5 # size of the line plot ), dict( # line plot 2 points=[[7, 8, 9], [10, 11, 12]], # list of points name="My line Plot 2", # name displayed on the legend color="navy", # color of the line plot size=12.5 # size of the line plot ) ]

reset
(**kwargs)Â¶ Resets control points and/or evaluated points.
Keyword Arguments:
evalpts
: if True, then resets the evaluated pointsctrlpts
if True, then resets the control points

sample_size
Â¶ Sample size for both u and vdirections.
Sample size defines the number of surface points to generate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size as a tuple of values corresponding to u, v and wdirections Setter: Sets sample size value for both u, v and wdirections Type: int

sample_size_u
Â¶ Sample size for the udirection.
Sample size defines the number of evaluated points to generate. It also sets the
delta_u
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the udirection Setter: Sets sample size for the udirection Type: int

sample_size_v
Â¶ Sample size for the vdirection.
Sample size defines the number of evaluated points to generate. It also sets the
delta_v
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the vdirection Setter: Sets sample size for the vdirection Type: int

sample_size_w
Â¶ Sample size for the wdirection.
Sample size defines the number of evaluated points to generate. It also sets the
delta_w
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the wdirection Setter: Sets sample size for the wdirection Type: int

save
(file_name)Â¶ Saves the volume as a pickled file.
Parameters: file_name (str) â€“ name of the file to be saved Raises: IOError â€“ an error occurred writing the file

set_ctrlpts
(ctrlpts, *args, **kwargs)Â¶ Sets the control points and checks if the data is consistent.
This method is designed to provide a consistent way to set control points whether they are weighted or not. It directly sets the control points member of the class, and therefore it doesnâ€™t return any values. The input will be an array of coordinates. If you are working in the 3dimensional space, then your coordinates will be an array of 3 elements representing (x, y, z) coordinates.
Parameters:  ctrlpts (list) â€“ input control points as a list of coordinates
 args (tuple[int, int, int]) â€“ number of control points corresponding to each parametric dimension

vis
Â¶ Visualization component.
Please refer to the wiki for details on using this class member.
Getter: Gets the visualization component Setter: Sets the visualization component Type: vis.VisAbstract

weights
Â¶ Weights vector.
Getter: Gets the weights vector Setter: Sets the weights vector Type: list
EvaluatorsÂ¶
Evaluators (or geometric evaluation strategies) allow users to change shape evaluation strategy, i.e. the algorithms that are used to evaluate curves, surfaces and volumes, take derivatives, knot and degree change operations and more. Therefore, the user can switch between the evaluation algorithms at runtime, implement and use different algorithms or extend existing ones.
Inheritance DiagramÂ¶
Abstract BaseÂ¶

class
geomdl.evaluators.
AbstractEvaluator
(**kwargs)Â¶ Bases:
object
Abstract base class for implementations of fundamental spline algorithms, such as evaluate and derivative.
Abstract Methods:
evaluate
is used for computation of the complete spline shapeevaluate_single
is used for computation of one single point on the spline shapederivative_single
is used for computation of derivatives at a single parametric coordinate
Please note that this class requires the keyword argument
find_span_func
to be set to a valid find_span function implementation. Please seehelpers
module for details.
derivatives_single
(**kwargs)Â¶ Abstract method for computation of derivatives at a single parameter.
Note
This is an abstract method and it must be implemented in the subclass.

evaluate
(**kwargs)Â¶ Abstract method for computation of points over a range of parameters.
Note
This is an abstract method and it must be implemented in the subclass.

evaluate_single
(**kwargs)Â¶ Abstract method for computation of a single point at a single parameter.
Note
This is an abstract method and it must be implemented in the subclass.

name
Â¶ Evaluator name.
Getter: Gets the name of the evaluator Type: str

class
geomdl.evaluators.
AbstractEvaluatorExtended
(**kwargs)Â¶ Bases:
geomdl.evaluators.AbstractEvaluator
Abstract base class for implementations of extended spline algorithms.
Abstract Methods:
evaluate
is used for computation of the complete spline shapeevaluate_single
is used for computation of one single point on the spline shapederivative_single
is used for computation of derivatives at a single parametric coordinateinsert_knot
is used for implementation of knot insertion algorithm
Please note that this class requires the keyword argument
find_span_func
to be set to a valid find_span function implementation. Please seehelpers
module for details.
derivatives_single
(**kwargs)Â¶ Abstract method for computation of derivatives at a single parameter.
Note
This is an abstract method and it must be implemented in the subclass.

evaluate
(**kwargs)Â¶ Abstract method for computation of points over a range of parameters.
Note
This is an abstract method and it must be implemented in the subclass.

evaluate_single
(**kwargs)Â¶ Abstract method for computation of a single point at a single parameter.
Note
This is an abstract method and it must be implemented in the subclass.

insert_knot
(**kwargs)Â¶ Abstract method for implementation of knot insertion algorithm.
Note
This is an abstract method and it must be implemented in the subclass.

name
Â¶ Evaluator name.
Getter: Gets the name of the evaluator Type: str
Curve EvaluatorsÂ¶

class
geomdl.evaluators.
CurveEvaluator
(**kwargs)Â¶ Bases:
geomdl.evaluators.AbstractEvaluatorExtended
Sequential curve evaluation algorithms.
This evaluator implements the following algorithms from The NURBS Book:
 Algorithm A3.1: CurvePoint
 Algorithm A3.2: CurveDerivsAlg1
 Algorithm A5.1: CurveKnotIns
Please note that knot vector span finding function may be changed by setting
find_span_func
keyword argument during the initialization. By default, this function is set tohelpers.find_span_linear()
. Please see Helpers Module Documentation for more details.
derivatives_single
(**kwargs)Â¶ Evaluates the derivatives at the input parameter.

evaluate
(**kwargs)Â¶ Evaluates the curve.

evaluate_single
(**kwargs)Â¶ Evaluates a single curve point.

insert_knot
(**kwargs)Â¶ Inserts a knot multiple times.

name
Â¶ Evaluator name.
Getter: Gets the name of the evaluator Type: str

class
geomdl.evaluators.
CurveEvaluator2
(**kwargs)Â¶ Bases:
geomdl.evaluators.CurveEvaluator
Sequential curve evaluation algorithms (alternative).
This evaluator implements the following algorithms from The NURBS Book:
 Algorithm A3.1: CurvePoint
 Algorithm A3.4: CurveDerivsAlg2
 Algorithm A5.1: CurveKnotIns
Please note that knot vector span finding function may be changed by setting
find_span_func
keyword argument during the initialization. By default, this function is set tohelpers.find_span_linear()
. Please see Helpers Module Documentation for more details.
static
derivatives_ctrlpts
(**kwargs)Â¶ Computes the control points of all derivative curves up to and including the {degree}th derivative.
Implementation of Algorithm A3.3 from The NURBS Book by Piegl & Tiller.
Output is PK[k][i], ith control point of the kth derivative curve where 0 <= k <= degree and r1 <= i <= r2k.

derivatives_single
(**kwargs)Â¶ Evaluates the derivatives at the input parameter.

evaluate
(**kwargs)Â¶ Evaluates the curve.

evaluate_single
(**kwargs)Â¶ Evaluates a single curve point.

insert_knot
(**kwargs)Â¶ Inserts a knot multiple times.

name
Â¶ Evaluator name.
Getter: Gets the name of the evaluator Type: str

class
geomdl.evaluators.
CurveEvaluatorRational
(**kwargs)Â¶ Bases:
geomdl.evaluators.CurveEvaluator
Sequential rational curve evaluation algorithms.
This evaluator implements the following algorithms from The NURBS Book:
 Algorithm A3.1: CurvePoint
 Algorithm A4.2: RatCurveDerivs
 Algorithm A5.1: CurveKnotIns
Please note that knot vector span finding function may be changed by setting
find_span_func
keyword argument during the initialization. By default, this function is set tohelpers.find_span_linear()
. Please see Helpers Module Documentation for more details.
derivatives_single
(**kwargs)Â¶ Evaluates the derivatives at the input parameter.

evaluate
(**kwargs)Â¶ Evaluates the rational curve.

evaluate_single
(**kwargs)Â¶ Evaluates a single curve point.

insert_knot
(**kwargs)Â¶ Inserts a knot multiple times.

name
Â¶ Evaluator name.
Getter: Gets the name of the evaluator Type: str
Surface EvaluatorsÂ¶

class
geomdl.evaluators.
SurfaceEvaluator
(**kwargs)Â¶ Bases:
geomdl.evaluators.AbstractEvaluatorExtended
Sequential surface evaluation algorithms.
This evaluator implements the following algorithms from The NURBS Book:
 Algorithm A3.5: SurfacePoint
 Algorithm A3.6: SurfaceDerivsAlg1
 Algorithm A5.3: SurfaceKnotIns
Please note that knot vector span finding function may be changed by setting
find_span_func
keyword argument during the initialization. By default, this function is set tohelpers.find_span_linear()
. Please see Helpers Module Documentation for more details.
derivatives_single
(**kwargs)Â¶ Evaluates the derivatives at the input parameter.

evaluate
(**kwargs)Â¶ Evaluates the surface.

evaluate_single
(**kwargs)Â¶ Evaluates a single surface point.

insert_knot
(direction, **kwargs)Â¶ Inserts a knot multiple times.

name
Â¶ Evaluator name.
Getter: Gets the name of the evaluator Type: str

class
geomdl.evaluators.
SurfaceEvaluator2
(**kwargs)Â¶ Bases:
geomdl.evaluators.SurfaceEvaluator
Sequential surface evaluation algorithms.
This evaluator implements the following algorithms from The NURBS Book:
 Algorithm A3.5: SurfacePoint
 Algorithm A3.7: SurfaceDerivCpts
 Algorithm A3.8: SurfaceDerivsAlg2
 Algorithm A5.3: SurfaceKnotIns
Please note that knot vector span finding function may be changed by setting
find_span_func
keyword argument during the initialization. By default, this function is set tohelpers.find_span_linear()
. Please see Helpers Module Documentation for more details.
static
derivatives_ctrlpts
(**kwargs)Â¶ Computes the control points of all derivative surfaces up to and including the {degree}th derivative.
Output is PKL[k][l][i][j], i,jth control point of the surface differentiated k times w.r.t to u and l times w.r.t v.

derivatives_single
(**kwargs)Â¶ Evaluates the derivatives at the input parameter.

evaluate
(**kwargs)Â¶ Evaluates the surface.

evaluate_single
(**kwargs)Â¶ Evaluates a single surface point.

insert_knot
(direction, **kwargs)Â¶ Inserts a knot multiple times.

name
Â¶ Evaluator name.
Getter: Gets the name of the evaluator Type: str

class
geomdl.evaluators.
SurfaceEvaluatorRational
(**kwargs)Â¶ Bases:
geomdl.evaluators.SurfaceEvaluator
Sequential rational surface evaluation algorithms.
This evaluator implements the following algorithms from The NURBS Book:
 Algorithm A4.3: SurfacePoint
 Algorithm A4.4: RatSurfaceDerivs
 Algorithm A5.3: SurfaceKnotIns
Please note that knot vector span finding function may be changed by setting
find_span_func
keyword argument during the initialization. By default, this function is set tohelpers.find_span_linear()
. Please see Helpers Module Documentation for more details.
derivatives_single
(**kwargs)Â¶ Evaluates the derivatives at the input parameter.

evaluate
(**kwargs)Â¶ Evaluates the rational surface.

evaluate_single
(**kwargs)Â¶ Evaluates a single surface point.

insert_knot
(direction, **kwargs)Â¶ Inserts a knot multiple times.

name
Â¶ Evaluator name.
Getter: Gets the name of the evaluator Type: str
Volume EvaluatorsÂ¶

class
geomdl.evaluators.
VolumeEvaluator
(**kwargs)Â¶ Bases:
geomdl.evaluators.AbstractEvaluator
Sequential volume evaluation algorithms.
Please note that knot vector span finding function may be changed by setting
find_span_func
keyword argument during the initialization. By default, this function is set tohelpers.find_span_linear()
. Please see Helpers Module Documentation for more details.
derivatives_single
(**kwargs)Â¶ Evaluates the derivative at the given parametric coordinate.

evaluate
(**kwargs)Â¶ Evaluates the volume.

evaluate_single
(**kwargs)Â¶ Evaluates a single point.

name
Â¶ Evaluator name.
Getter: Gets the name of the evaluator Type: str


class
geomdl.evaluators.
VolumeEvaluatorRational
(**kwargs)Â¶ Bases:
geomdl.evaluators.VolumeEvaluator
Sequential rational volume evaluation algorithms.
Please note that knot vector span finding function may be changed by setting
find_span_func
keyword argument during the initialization. By default, this function is set tohelpers.find_span_linear()
. Please see Helpers Module Documentation for more details.
derivatives_single
(**kwargs)Â¶ Evaluates the derivatives at the input parameter.

evaluate
(**kwargs)Â¶ Evaluates the rational volume.

evaluate_single
(**kwargs)Â¶ Evaluates a single point.

name
Â¶ Evaluator name.
Getter: Gets the name of the evaluator Type: str

Geometric OperationsÂ¶
This module provides common geometric operations for curves and surfaces. It includes the following operations:
 Curve and surface splitting / BÃ©zier decomposition
 Tangent, normal and binormal evaluations
 Hodograph curve and surface computations
 Translation
Function ReferenceÂ¶

geomdl.operations.
add_dimension
(obj, **kwargs)Â¶ Converts xdimensional curve to a (x+1)dimensional curve.
If you pass
inplace=True
keyword argument, the input shape will be updated. Otherwise, this function does not change the input shape but returns a new instance of the same shape with the updated data.Useful when converting a 2dimensional curve to a 3dimensional curve.
Parameters: obj (abstract.Curve) â€“ Curve Returns: updated Curve Return type: BSpline.Curve or NURBS.Curve

geomdl.operations.
binormal
(obj, params, **kwargs)Â¶ Evaluates the binormal vector of the curves or surfaces at the input parameter values.
This function is designed to evaluate binormal vectors of the BSpline and NURBS shapes at single or multiple parameter positions.
Parameters:  obj (abstract.Curve or abstract.Surface) â€“ input shape
 params (float, list or tuple) â€“ parameters
Returns: a list containing â€œpointâ€ and â€œvectorâ€ pairs
Return type: tuple

geomdl.operations.
decompose_curve
(obj, **kwargs)Â¶ Decomposes the curve into Bezier curve segments of the same degree.
This operation does not modify the input curve, instead it returns the split curve segments.
Parameters: obj (abstract.Curve) â€“ Curve to be decomposed Returns: a list of curve objects arranged in Bezier curve segments Return type: list

geomdl.operations.
decompose_surface
(obj, **kwargs)Â¶ Decomposes the surface into Bezier surface patches of the same degree.
This operation does not modify the input surface, instead it returns the surface patches.
Parameters: obj (abstract.Surface) â€“ surface Returns: a list of surface objects arranged as Bezier surface patches Return type: multi.SurfaceContainer

geomdl.operations.
derivative_curve
(obj)Â¶ Computes the hodograph (first derivative) curve of the input curve.
This function constructs the hodograph (first derivative) curve from the input curve by computing the degrees, knot vectors and the control points of the derivative curve.
Parameters: obj (abstract.Curve) â€“ input curve Returns: derivative curve

geomdl.operations.
derivative_surface
(obj)Â¶ Computes the hodograph (first derivative) surface of the input surface.
This function constructs the hodograph (first derivative) surface from the input surface by computing the degrees, knot vectors and the control points of the derivative surface.
The return value of this function is a tuple containing the following derivative surfaces in the given order:
 Uderivative surface (derivative taken only on the udirection)
 Vderivative surface (derivative taken only on the vdirection)
 UVderivative surface (derivative taken on both the u and the vdirection)
Parameters: obj (abstract.Surface) â€“ input surface Returns: derivative surfaces w.r.t. u, v and both uv Return type: tuple

geomdl.operations.
find_ctrlpts
(obj, u, v=None, **kwargs)Â¶ Finds the control points involved in the evaluation of the curve/surface point defined by the input parameter(s).
Parameters:  obj (abstract.Curve or abstract.Surface) â€“ curve or surface
 u (float) â€“ parameter (for curve), parameter on the udirection (for surface)
 v (float) â€“ parameter on the vdirection (for surface only)
Returns: control points; 1dimensional array for curve, 2dimensional array for surface
Return type: list

geomdl.operations.
length_curve
(obj)Â¶ Computes the approximate length of the parametric curve.
Parameters: obj (abstract.Curve) â€“ input curve Returns: length Return type: float

geomdl.operations.
normal
(obj, params, **kwargs)Â¶ Evaluates the normal vector of the curves or surfaces at the input parameter values.
This function is designed to evaluate normal vectors of the BSpline and NURBS shapes at single or multiple parameter positions.
Parameters:  obj (abstract.Curve or abstract.Surface) â€“ input geometry
 params (float, list or tuple) â€“ parameters
Returns: a list containing â€œpointâ€ and â€œvectorâ€ pairs
Return type: tuple

geomdl.operations.
rotate
(obj, angle, **kwargs)Â¶ Rotates curves, surfaces or volumes about the chosen axis.
 Keyword Arguments:
axis
: rotation axis; x, y, z correspond to 0, 1, 2 respectively.inplace
: if True, the input shape is modified. Default: False
Parameters:  obj (abstract.Curve, abstract.Surface or abstract.Volume) â€“ input geometry
 angle (float) â€“ angle of rotation (in degrees)
Returns: rotated geometry object

geomdl.operations.
scale
(obj, multiplier, **kwargs)Â¶ Scales curves, surfaces or volumes by the input multiplier.
 Keyword Arguments:
inplace
: if True, the input shape is modified. Default: False
Parameters:  obj (abstract.Curve, abstract.Surface or abstract.Volume) â€“ input geometry
 multiplier (float) â€“ scaling multiplier
Returns: scaled geometry object

geomdl.operations.
split_curve
(obj, u, **kwargs)Â¶ Splits the curve at the input parametric coordinate.
This method splits the curve into two pieces at the given parametric coordinate, generates two different curve objects and returns them. It does not modify the input curve.
Parameters:  obj (abstract.Curve) â€“ Curve to be split
 u (float) â€“ parameter
Returns: list of curves as the split pieces of the initial curve
Return type: list

geomdl.operations.
split_surface_u
(obj, t, **kwargs)Â¶ Splits the surface at the input parametric coordinate on the udirection.
This method splits the surface into two pieces at the given parametric coordinate on the udirection, generates two different surface objects and returns them. It does not modify the input surface.
Parameters:  obj (abstract.Surface) â€“ surface
 t (float) â€“ parameter for the udirection
Returns: list of surface as the split pieces of the initial surface
Return type: list

geomdl.operations.
split_surface_v
(obj, t, **kwargs)Â¶ Splits the surface at the input parametric coordinate on the vdirection.
This method splits the surface into two pieces at the given parametric coordinate on the vdirection, generates two different surface objects and returns them. It does not modify the input surface.
Parameters:  obj (abstract.Surface) â€“ surface
 t (float) â€“ parameter for the vdirection
Returns: list of surface as the split pieces of the initial surface
Return type: list

geomdl.operations.
tangent
(obj, params, **kwargs)Â¶ Evaluates the tangent vector of the curves or surfaces at the input parameter values.
This function is designed to evaluate tangent vectors of the BSpline and NURBS shapes at single or multiple parameter positions.
Parameters:  obj (abstract.Curve or abstract.Surface) â€“ input shape
 params (float, list or tuple) â€“ parameters
Returns: a list containing â€œpointâ€ and â€œvectorâ€ pairs
Return type: tuple

geomdl.operations.
translate
(obj, vec, **kwargs)Â¶ Translates curves, surface or volumes by the input vector.
If you pass
inplace=True
keyword argument, the input shape will be updated. Otherwise, this function does not change the input shape but returns a new instance of the same shape with the updated data.Parameters:  obj (abstract.SplineGeometry or multi.AbstractContainer) â€“ input geometry
 vec (list, tuple) â€“ translation vector
Returns: translated geometry object

geomdl.operations.
transpose
(surf, **kwargs)Â¶ Transposes the input surface by swapping u and v parametric directions.
If you pass
inplace=True
keyword argument, the input surface will be updated. Otherwise, this function does not change the input surface but returns a new instance of the same surface with the updated data.Parameters: surf (abstract.Surface) â€“ input surface Returns: transposed surface Return type: abstract.Surface
Utilities and HelpersÂ¶
These modules contain common utility and helper functions for BSpline / NURBS curve and surface evaluation operations.
UtilitiesÂ¶
The utilities
module contains common utility functions for NURBSPython library and its extensions.

geomdl.utilities.
generate_knot_vector
(degree, num_ctrlpts, **kwargs)Â¶ Generates an equally spaced knot vector.
It uses the following equation to generate knot vector:
m = n + p + 1
where;
p: degree, n+1: number of control points, m+1: number of knots
Keyword Arguments:
clamped
: Flag to choose from clamped or unclamped knot vector options. Default: True
Parameters:  degree (int) â€“ degree
 num_ctrlpts (int) â€“ number of control points
Returns: knot vector
Return type: list
HelpersÂ¶
The helpers
module contains common functions required for evaluating both surfaces and curves, such as basis
function computations, knot vector span finding, etc.

geomdl.helpers.
basis_function
(degree, knot_vector, span, knot)Â¶ Computes the nonvanishing basis functions for a single parameter.
Implementation of Algorithm A2.2 from The NURBS Book by Piegl & Tiller.
Parameters:  degree (int) â€“ degree,
 knot_vector (list, tuple) â€“ knot vector,
 span (int) â€“ knot span,
 knot (float) â€“ knot or parameter,
Returns: basis functions
Return type: list

geomdl.helpers.
basis_function_all
(degree, knot_vector, span, knot)Â¶ Computes all nonzero basis functions of all degrees from 0 up to the input degree for a single parameter.
A slightly modified version of Algorithm A2.2 from The NURBS Book by Piegl & Tiller.
Parameters:  degree (int) â€“ degree,
 knot_vector (list, tuple) â€“ knot vector,
 span (int) â€“ knot span,
 knot (float) â€“ knot or parameter,
Returns: basis functions
Return type: list

geomdl.helpers.
basis_function_ders
(degree, knot_vector, span, knot, order)Â¶ Computes derivatives of the basis functions for a single parameter.
Implementation of Algorithm A2.3 from The NURBS Book by Piegl & Tiller.
Parameters:  degree (int) â€“ degree,
 knot_vector (list, tuple) â€“ knot vector,
 span (int) â€“ knot span,
 knot (float) â€“ knot or parameter,
 order (int) â€“ order of the derivative
Returns: derivatives of the basis functions
Return type: list

geomdl.helpers.
basis_function_ders_one
(degree, knot_vector, span, knot, order)Â¶ Computes the derivative of one basis functions for a single parameter.
Implementation of Algorithm A2.5 from The NURBS Book by Piegl & Tiller.
Parameters:  degree (int) â€“ degree,
 knot_vector (list, tuple) â€“ knot_vector,
 span (int) â€“ knot span,
 knot (float) â€“ knot or parameter,
 order (int) â€“ order of the derivative
Returns: basis function derivatives
Return type: list

geomdl.helpers.
basis_function_one
(degree, knot_vector, span, knot)Â¶ Computes the value of a basis function for a single parameter.
Implementation of Algorithm 2.4 from The NURBS Book by Piegl & Tiller.
Parameters:  degree (int) â€“ degree,
 knot_vector (list, tuple) â€“ knot vector
 span (int) â€“ knot span,
 knot (float) â€“ knot or parameter,
Returns: basis function,
Return type: float

geomdl.helpers.
basis_functions
(degree, knot_vector, spans, knots)Â¶ Computes the nonvanishing basis functions for a list of parameters.
Parameters:  degree (int) â€“ degree,
 knot_vector (list, tuple) â€“ knot vector,
 spans (list, tuple) â€“ list of knot spans
 knots (list, tuple) â€“ list of knots or parameters
Returns: basis functions
Return type: list

geomdl.helpers.
basis_functions_ders
(degree, knot_vector, spans, knots, order)Â¶ Computes derivatives of the basis functions for a list of parameters.
Parameters:  degree (int) â€“ degree,
 knot_vector (list, tuple) â€“ knot vector,
 spans (list, tuple) â€“ list of knot spans
 knots (list, tuple) â€“ list of knots or parameters
 order (int) â€“ order of the derivative
Returns: derivatives of the basis functions
Return type: list

geomdl.helpers.
find_multiplicity
(knot, knot_vector, **kwargs)Â¶ Finds knot multiplicity over the knot vector.
Parameters:  knot (float) â€“ knot or parameter,
 knot_vector (list, tuple) â€“ knot vector,
Returns: knot multiplicity,
Return type: int

geomdl.helpers.
find_span_binsearch
(degree, knot_vector, num_ctrlpts, knot, **kwargs)Â¶ Finds the span of the knot over the input knot vector using binary search.
Implementation of Algorithm A2.1 from The NURBS Book by Piegl & Tiller.
The NURBS Book states that the knot span index always starts from zero, i.e. for a knot vector [0, 0, 1, 1]; if FindSpan returns 1, then the knot is between the interval [0, 1).
Parameters:  degree (int) â€“ degree,
 knot_vector (list, tuple) â€“ knot vector,
 num_ctrlpts (int) â€“ number of control points,
 knot (float) â€“ knot or parameter,
Returns: knot span
Return type: int

geomdl.helpers.
find_span_linear
(degree, knot_vector, num_ctrlpts, knot, **kwargs)Â¶ Finds the span of a single knot over the knot vector using linear search.
Alternative implementation for the Algorithm A2.1 from The NURBS Book by Piegl & Tiller.
Parameters:  degree (int) â€“ degree,
 knot_vector (list, tuple) â€“ knot vector,
 num_ctrlpts (int) â€“ number of control points,
 knot (float) â€“ knot or parameter,
Returns: knot span
Return type: int

geomdl.helpers.
find_spans
(degree, knot_vector, num_ctrlpts, knots, func=<function find_span_linear>)Â¶ Finds spans of a list of knots over the knot vector.
Parameters:  degree (int) â€“ degree,
 knot_vector (list, tuple) â€“ knot vector,
 num_ctrlpts (int) â€“ number of control points,
 knots (list, tuple) â€“ list of knots or parameters
 func â€“ function for span finding, e.g. linear or binary search
Returns: list of spans
Return type: list
Linear AlgebraÂ¶
The linalg
module contains some basic functions for point, vector and matrix operations.
Although most of the functions are designed for internal usage, the users can still use some of the functions for their
advantage, especially the point and vector manipulation and generation functions. Functions related to point
manipulation have point_
prefix and the ones related to vectors have vector_
prefix.

geomdl.linalg.
backward_substitution
(matrix_u, matrix_y)Â¶ Backward substitution method for the solution of linear systems.
Solves the equation using backward substitution method where is a upper triangular matrix and is a column matrix.
Parameters:  matrix_u (list, tuple) â€“ U, upper triangular matrix
 matrix_y (list, tuple) â€“ y, column matrix
Returns: x, column matrix
Return type: list

geomdl.linalg.
binomial_coefficient
(k, i)Â¶ Computes the binomial coefficient (denoted by k choose i).
Please see the following website for details: http://mathworld.wolfram.com/BinomialCoefficient.html
Parameters:  k (int) â€“ size of the set of distinct elements
 i (int) â€“ size of the subsets
Returns: combination of k and i
Return type: float

geomdl.linalg.
forward_substitution
(matrix_l, matrix_b)Â¶ Forward substitution method for the solution of linear systems.
Solves the equation using forward substitution method where is a lower triangular matrix and is a column matrix.
Parameters:  matrix_l (list, tuple) â€“ L, lower triangular matrix
 matrix_b (list, tuple) â€“ b, column matrix
Returns: y, column matrix
Return type: list

geomdl.linalg.
frange
(start, stop, step=1.0)Â¶ Implementation of Pythonâ€™s
range()
function which works with floats.Reference to this implementation: https://stackoverflow.com/a/36091634
Parameters:  start (float) â€“ start value
 stop (float) â€“ end value
 step (float) â€“ increment
Returns: float
Return type: generator

geomdl.linalg.
linspace
(start, stop, num, decimals=18)Â¶ Returns a list of evenly spaced numbers over a specified interval.
Inspired from Numpyâ€™s linspace function: https://github.com/numpy/numpy/blob/master/numpy/core/function_base.py
Parameters:  start (float) â€“ starting value
 stop (float) â€“ end value
 num (int) â€“ number of samples to generate
 decimals (int) â€“ number of significands
Returns: a list of equally spaced numbers
Return type: list

geomdl.linalg.
lu_decomposition
(matrix_a)Â¶ LUFactorization method using Doolittleâ€™s Method for solution of linear systems.
Decomposes the matrix such that .
The input matrix is represented by a list or a tuple. The input matrix is 2dimensional, i.e. list of lists of integers and/or floats.
Parameters: matrix_a (list, tuple) â€“ Input matrix (must be a square matrix) Returns: a tuple containing matrices L and U Return type: tuple

geomdl.linalg.
matrix_multiply
(m1, m2)Â¶ Matrix multiplication (iterative algorithm).
The running time of the iterative matrix multiplication algorithm is .
Parameters:  m1 (list, tuple) â€“ 1st matrix with dimensions
 m2 (list, tuple) â€“ 2nd matrix with dimensions
Returns: resultant matrix with dimensions
Return type: list

geomdl.linalg.
matrix_transpose
(m)Â¶ Transposes the input matrix.
The input matrix is a 2dimensional array.
Parameters: m (list, tuple) â€“ input matrix with dimensions Returns: transpose matrix with dimensions Return type: list

geomdl.linalg.
point_distance
(pt1, pt2)Â¶ Computes distance between two points.
Parameters:  pt1 (list, tuple) â€“ point 1
 pt2 (list, tuple) â€“ point 2
Returns: distance between input points
Return type: float

geomdl.linalg.
point_mid
(pt1, pt2)Â¶ Computes the midpoint of the input points.
Parameters:  pt1 (list, tuple) â€“ point 1
 pt2 (list, tuple) â€“ point 2
Returns: midpoint
Return type: list

geomdl.linalg.
point_translate
(point_in, vector_in)Â¶ Translates the input points using the input vector.
Parameters:  point_in (list, tuple) â€“ input point
 vector_in (list, tuple) â€“ input vector
Returns: translated point
Return type: list

geomdl.linalg.
vector_angle_between
(vector1, vector2, **kwargs)Â¶ Computes the angle between the two input vectors.
If the keyword argument
degrees
is set to True, then the angle will be in degrees. Otherwise, it will be in radians. By default,degrees
is set to True.Parameters:  vector1 (list, tuple) â€“ vector
 vector2 (list, tuple) â€“ vector
Returns: angle between the vectors
Return type: float

geomdl.linalg.
vector_cross
(vector1, vector2)Â¶ Computes the crossproduct of the input vectors.
Parameters:  vector1 (list, tuple) â€“ input vector 1
 vector2 (list, tuple) â€“ input vector 2
Returns: result of the cross product
Return type: tuple

geomdl.linalg.
vector_dot
(vector1, vector2)Â¶ Computes the dotproduct of the input vectors.
Parameters:  vector1 (list, tuple) â€“ input vector 1
 vector2 (list, tuple) â€“ input vector 2
Returns: result of the dot product
Return type: float

geomdl.linalg.
vector_generate
(start_pt, end_pt, normalize=False)Â¶ Generates a vector from 2 input points.
Parameters:  start_pt (list, tuple) â€“ start point of the vector
 end_pt (list, tuple) â€“ end point of the vector
 normalize (bool) â€“ if True, the generated vector is normalized
Returns: a vector from start_pt to end_pt
Return type: list

geomdl.linalg.
vector_is_zero
(vector_in, tol=1e07)Â¶ Checks if the input vector is a zero vector.
Parameters:  vector_in (list, tuple) â€“ input vector
 tol (float) â€“ tolerance value
Returns: True if the input vector is zero, False otherwise
Return type: bool

geomdl.linalg.
vector_magnitude
(vector_in)Â¶ Computes the magnitude of the input vector.
Parameters: vector_in (list, tuple) â€“ input vector Returns: magnitude of the vector Return type: float

geomdl.linalg.
vector_mean
(*args)Â¶ Computes the mean (average) of a list of vectors.
The function computes the arithmetic mean of a list of vectors, which are also organized as a list of integers or floating point numbers.
1 2 3 4 5 6 7 8 9 10 11
# Import geomdl.utilities module from geomdl import utilities # Create a list of vectors as an example vector_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # Compute mean vector mean_vector = utilities.vector_mean(*vector_list) # Alternative usage example (same as above): mean_vector = utilities.vector_mean([1, 2, 3], [4, 5, 6], [7, 8, 9])
Parameters: args (list, tuple) â€“ list of vectors Returns: mean vector Return type: list

geomdl.linalg.
vector_multiply
(vector_in, scalar)Â¶ Multiplies the vector with a scalar value.
This operation is also called vector scaling.
Parameters:  vector_in (list, tuple) â€“ vector
 scalar (int, float) â€“ scalar value
Returns: updated vector
Return type: tuple

geomdl.linalg.
vector_normalize
(vector_in, decimals=18)Â¶ Generates a unit vector from the input.
Parameters:  vector_in (list, tuple) â€“ vector to be normalized
 decimals (int) â€“ number of significands
Returns: the normalized vector (i.e. the unit vector)
Return type: list

geomdl.linalg.
vector_sum
(vector1, vector2, coeff=1.0)Â¶ Sums the vectors.
This function computes the result of the vector operation , where is
vector1
, isvector2
and iscoeff
.Parameters:  vector1 (list, tuple) â€“ vector 1
 vector2 (list, tuple) â€“ vector 2
 coeff (float) â€“ multiplier for vector 2
Returns: updated vector
Return type: list
ConvertersÂ¶
convert
module provides functions for converting Bspline shapes and NURBS shapes to each other.
Function ReferenceÂ¶

geomdl.convert.
bspline_to_nurbs
(obj)Â¶ Converts nonrational parametric shapes to rational ones.
Parameters: obj (BSpline.Curve, BSpline.Surface or BSpline.Volume) â€“ BSpline shape Returns: NURBS shape Return type: NURBS.Curve, NURBS.Surface or NURBS.Volume Raises: TypeError

geomdl.convert.
nurbs_to_bspline
(obj, **kwargs)Â¶ Extracts the nonrational components from rational parametric shapes, if possible.
The possibility of converting a rational shape to a nonrational one depends on the weights vector.
Parameters: obj (NURBS.Curve, NURBS.Surface or NURBS.Volume) â€“ NURBS shape Returns: BSpline shape Return type: BSpline.Curve, BSpline.Surface or BSpline.Volume Raises: TypeError
Shape ConstructorsÂ¶
construct
module provides functions for constructing and extracting parametric shapes. A surface can be constructed
from curves and a volume can be constructed from surfaces. Moreover, a surface can be extracted to curves and a volume
can be extracted to surfaces in all parametric directions.
Function ReferenceÂ¶

geomdl.construct.
construct_surface
(*args, **kwargs)Â¶ Generates surfaces from curves.
Returns: NURBS surface Return type: NURBS.Surface

geomdl.construct.
construct_volume
(*args, **kwargs)Â¶ Generates volumes from surfaces.
Returns: NURBS volume Return type: NURBS.Volume

geomdl.construct.
extract_curves
(psurf)Â¶ Extracts curves from a surface.
Parameters: psurf (abstract.Surface) â€“ input surface Returns: extracted curves Return type: dict

geomdl.construct.
extract_isosurface
(pvol)Â¶ Extracts the largest isosurface from a volume.
The following example illustrates one of the usage scenarios:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from geomdl import construct, multi from geomdl.visualization import VisMPL # Assuming that "myvol" variable stores your spline volume information isosrf = construct.extract_isosurface(myvol) # Create a surface container to store extracted isosurface msurf = multi.SurfaceContainer(isosrf) # Set visualization components msurf.vis = VisMPL.VisSurface(VisMPL.VisConfig(ctrlpts=False)) # Render isosurface msurf.render()
Parameters: pvol (abstract.Volume) â€“ input volume Returns: isosurface (as a tuple of surfaces) Return type: tuple

geomdl.construct.
extract_surfaces
(pvol)Â¶ Extracts surfaces from a volume.
Parameters: pvol (abstract.Volume) â€“ input volume Returns: extracted surface Return type: dict
Shape ContainersÂ¶
This module provides object containers for curves, surfaces and volumes. A container is a holder object that stores a collection of other objects, i.e. its elements. In NURBSPython, containers can be generated as a result of
 A geometric operation, such as splitting
 File import, e.g. reading a file or a set of files containing multiple surfaces
Additionally, they can be used for advanced postprocessing, such as visualization or file export.
This module works with BSpline
and NURBS
modules and it contains the following classes:
AbstractContainer
abstract base class for containersCurveContainer
for storing multiple curvesSurfaceContainer
for storing multiple surfacesVolumeContainer
for storing multiple volumes
Inheritance DiagramÂ¶
Abstract ContainerÂ¶

class
geomdl.multi.
AbstractContainer
(*args, **kwargs)Â¶ Bases:
object
Abstract class for curve and surface containers.
This class implements Python Iterator Protocol and therefore any instance of this class can be directly used in a for loop.
This class provides the following properties:

add
(element)Â¶ Adds shapes to the container.
The input can be a single shape, a list of shapes or a container object.
Parameters: element â€“ shape to be added

append
(element)Â¶ Adds shapes to the container.
The input can be a single shape, a list of shapes or a container object.
Parameters: element â€“ shape to be added

bbox
Â¶ Bounding box.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box of all contained shapes

delta
Â¶ Evaluation delta (for all parametric directions).
Evaluation delta corresponds to the step size. Decreasing the step size results in evaluation of more points. Therefore; smaller the delta value, smoother the shape.
The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets the delta value Setter: Sets the delta value

dimension
Â¶ Shape dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the dimension of the shape

evalpts
Â¶ Evaluated points.
Since there are multiple shapes contained in the multi objects, the evaluated points will be returned in the format of list of individual evaluated points which is also a list of Cartesian coordinates.
The following code example illustrates these details:
1 2 3 4 5 6 7 8
multi_obj = multi.SurfaceContainer() # it can also be multi.CurveContainer() # Add shapes to multi_obj via multi_obj.add() method # Then, the following loop will print all the evaluated points of the Multi object for idx, mpt in enumerate(multi_obj.evalpts): print("Shape", idx+1, "contains", len(mpt), "points. These points are:") for pt in mpt: line = ", ".join([str(p) for p in pt]) print(line)
Please refer to the wiki for details on using this class member.
Getter: Gets the evaluated points of all contained shapes

render
(**kwargs)Â¶ Renders plots using the visualization component.
Note
This is an abstract method and it must be implemented in the subclass.

sample_size
Â¶ Sample size (for all parametric directions).
Sample size defines the number of points to evaluate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size Setter: Sets sample size

Curve ContainerÂ¶

class
geomdl.multi.
CurveContainer
(*args, **kwargs)Â¶ Bases:
geomdl.multi.AbstractContainer
Container class for storing multiple curves.
This class implements Python Iterator Protocol and therefore any instance of this class can be directly used in a for loop.
This class provides the following properties:
The following code example illustrates the usage of the Python properties:
# Create a multicurve container instance mcrv = Multi.CurveContainer() # Add single or multi curves to the multi container using mcrv.add() command # Addition operator, e.g. mcrv1 + mcrv2, also works # Set the evaluation delta of the multicurve mcrv.delta = 0.05 # Get the evaluated points curve_points = mcrv.evalpts

add
(element)Â¶ Adds shapes to the container.
The input can be a single shape, a list of shapes or a container object.
Parameters: element â€“ shape to be added

append
(element)Â¶ Adds shapes to the container.
The input can be a single shape, a list of shapes or a container object.
Parameters: element â€“ shape to be added

bbox
Â¶ Bounding box.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box of all contained shapes

delta
Â¶ Evaluation delta (for all parametric directions).
Evaluation delta corresponds to the step size. Decreasing the step size results in evaluation of more points. Therefore; smaller the delta value, smoother the shape.
The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets the delta value Setter: Sets the delta value

dimension
Â¶ Shape dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the dimension of the shape

evalpts
Â¶ Evaluated points.
Since there are multiple shapes contained in the multi objects, the evaluated points will be returned in the format of list of individual evaluated points which is also a list of Cartesian coordinates.
The following code example illustrates these details:
1 2 3 4 5 6 7 8
multi_obj = multi.SurfaceContainer() # it can also be multi.CurveContainer() # Add shapes to multi_obj via multi_obj.add() method # Then, the following loop will print all the evaluated points of the Multi object for idx, mpt in enumerate(multi_obj.evalpts): print("Shape", idx+1, "contains", len(mpt), "points. These points are:") for pt in mpt: line = ", ".join([str(p) for p in pt]) print(line)
Please refer to the wiki for details on using this class member.
Getter: Gets the evaluated points of all contained shapes

render
(**kwargs)Â¶ Renders the curves.
The visualization component must be set using
vis
property before calling this method.Keyword Arguments:
cpcolor
: sets the color of the control points gridevalcolor
: sets the color of the surfacefilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falsedelta
: if True, the evaluation delta of the Multi object will be used. Default: True
The
cpcolor
andevalcolor
arguments can be a string or a list of strings corresponding to the color values. Both arguments are processed separately, e.g.cpcolor
can be a string whereasevalcolor
can be a list or a tuple, or vice versa. A single string value sets the color to the same value. List input allows customization over the color values. If none provided, a random color will be selected.The
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.

sample_size
Â¶ Sample size (for all parametric directions).
Sample size defines the number of points to evaluate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size Setter: Sets sample size

Surface ContainerÂ¶

class
geomdl.multi.
SurfaceContainer
(*args, **kwargs)Â¶ Bases:
geomdl.multi.AbstractContainer
Container class for storing multiple surfaces.
This class implements Python Iterator Protocol and therefore any instance of this class can be directly used in a for loop.
This class provides the following properties:
The following code example illustrates the usage of these Python properties:
# Create a multisurface container instance msurf = Multi.SurfaceContainer() # Add single or multi surfaces to the multi container using msurf.add() command # Addition operator, e.g. msurf1 + msurf2, also works # Set the evaluation delta of the multisurface msurf.delta = 0.05 # Get the evaluated points surface_points = msurf.evalpts

add
(element)Â¶ Adds shapes to the container.
The input can be a single shape, a list of shapes or a container object.
Parameters: element â€“ shape to be added

append
(element)Â¶ Adds shapes to the container.
The input can be a single shape, a list of shapes or a container object.
Parameters: element â€“ shape to be added

bbox
Â¶ Bounding box.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box of all contained shapes

delta
Â¶ Evaluation delta (for all parametric directions).
Evaluation delta corresponds to the step size. Decreasing the step size results in evaluation of more points. Therefore; smaller the delta value, smoother the shape.
The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets the delta value Setter: Sets the delta value

delta_u
Â¶ Evaluation delta for the udirection.
Evaluation delta corresponds to the step size. Decreasing the step size results in evaluation of more points. Therefore; smaller the delta, smoother the shape.
Please note that
delta_u
andsample_size_u
properties correspond to the same variable with different descriptions. Therefore, settingdelta_u
will also setsample_size_u
.Please refer to the wiki for details on using this class member.
Getter: Gets the delta value for the udirection Setter: Sets the delta value for the udirection Type: float

delta_v
Â¶ Evaluation delta for the vdirection.
Evaluation delta corresponds to the step size. Decreasing the step size results in evaluation of more points. Therefore; smaller the delta, smoother the shape.
Please note that
delta_v
andsample_size_v
properties correspond to the same variable with different descriptions. Therefore, settingdelta_v
will also setsample_size_v
.Please refer to the wiki for details on using this class member.
Getter: Gets the delta value for the vdirection Setter: Sets the delta value for the vdirection Type: float

dimension
Â¶ Shape dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the dimension of the shape

evalpts
Â¶ Evaluated points.
Since there are multiple shapes contained in the multi objects, the evaluated points will be returned in the format of list of individual evaluated points which is also a list of Cartesian coordinates.
The following code example illustrates these details:
1 2 3 4 5 6 7 8
multi_obj = multi.SurfaceContainer() # it can also be multi.CurveContainer() # Add shapes to multi_obj via multi_obj.add() method # Then, the following loop will print all the evaluated points of the Multi object for idx, mpt in enumerate(multi_obj.evalpts): print("Shape", idx+1, "contains", len(mpt), "points. These points are:") for pt in mpt: line = ", ".join([str(p) for p in pt]) print(line)
Please refer to the wiki for details on using this class member.
Getter: Gets the evaluated points of all contained shapes

render
(**kwargs)Â¶ Renders the surfaces.
The visualization component must be set using
vis
property before calling this method. Keyword Arguments:
cpcolor
: sets the color of the control points gridsevalcolor
: sets the color of the surfacefilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falsecolormap
: sets the colormap of the surfacesdelta
: if True, the evaluation delta of the Multi object will be used. Default: True
The
cpcolor
andevalcolor
arguments can be a string or a list of strings corresponding to the color values. Both arguments are processed separately, e.g.cpcolor
can be a string whereasevalcolor
can be a list or a tuple, or vice versa. A single string value sets the color to the same value. List input allows customization over the color values. If none provided, a random color will be selected.The
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.Please note that
colormap
argument can only work with visualization classes that support colormaps. As an example, please seeVisMPL.VisSurfTriangle()
class documentation. This method expects multiple colormap inputs as a list or tuple, preferable the input list size is the same as the number of surfaces contained in the class. In the case of number of surfaces is bigger than number of input colormaps, this method will automatically assign a random color for the remaining surfaces.

sample_size
Â¶ Sample size (for all parametric directions).
Sample size defines the number of points to evaluate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size Setter: Sets sample size

sample_size_u
Â¶ Sample size for the udirection.
Sample size defines the number of points to evaluate. It also sets the
delta_u
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the udirection Setter: Sets sample size for the udirection Type: int

Volume ContainerÂ¶

class
geomdl.multi.
VolumeContainer
(*args, **kwargs)Â¶ Bases:
geomdl.multi.SurfaceContainer
Container class for storing multiple volumes.
This class implements Python Iterator Protocol and therefore any instance of this class can be directly used in a for loop.
This class provides the following properties:
dimension
evalpts
bbox
vis
delta
delta_u
delta_v
delta_w
sample_size
sample_size_u
sample_size_v
sample_size_w
The following code example illustrates the usage of these Python properties:
# Create a multivolume container instance mvol = Multi.VolumeContainer() # Add single or multi volumes to the multi container using mvol.add() command # Addition operator, e.g. mvol1 + mvol2, also works # Set the evaluation delta of the multivolume mvol.delta = 0.05 # Get the evaluated points volume_points = mvol.evalpts

add
(element)Â¶ Adds shapes to the container.
The input can be a single shape, a list of shapes or a container object.
Parameters: element â€“ shape to be added

append
(element)Â¶ Adds shapes to the container.
The input can be a single shape, a list of shapes or a container object.
Parameters: element â€“ shape to be added

bbox
Â¶ Bounding box.
Please refer to the wiki for details on using this class member.
Getter: Gets the bounding box of all contained shapes

delta
Â¶ Evaluation delta (for all parametric directions).
Evaluation delta corresponds to the step size. Decreasing the step size results in evaluation of more points. Therefore; smaller the delta value, smoother the shape.
The following figure illustrates the working principles of the delta property:
Please refer to the wiki for details on using this class member.
Getter: Gets the delta value Setter: Sets the delta value

delta_u
Â¶ Evaluation delta for the udirection.
Evaluation delta corresponds to the step size. Decreasing the step size results in evaluation of more points. Therefore; smaller the delta, smoother the shape.
Please note that
delta_u
andsample_size_u
properties correspond to the same variable with different descriptions. Therefore, settingdelta_u
will also setsample_size_u
.Please refer to the wiki for details on using this class member.
Getter: Gets the delta value for the udirection Setter: Sets the delta value for the udirection Type: float

delta_v
Â¶ Evaluation delta for the vdirection.
Evaluation delta corresponds to the step size. Decreasing the step size results in evaluation of more points. Therefore; smaller the delta, smoother the shape.
Please note that
delta_v
andsample_size_v
properties correspond to the same variable with different descriptions. Therefore, settingdelta_v
will also setsample_size_v
.Please refer to the wiki for details on using this class member.
Getter: Gets the delta value for the vdirection Setter: Sets the delta value for the vdirection Type: float

delta_w
Â¶ Evaluation delta for the wdirection.
Evaluation delta corresponds to the step size. Decreasing the step size results in evaluation of more points. Therefore; smaller the delta, smoother the shape.
Please note that
delta_w
andsample_size_w
properties correspond to the same variable with different descriptions. Therefore, settingdelta_w
will also setsample_size_w
.Please refer to the wiki for details on using this class member.
Getter: Gets the delta value for the wdirection Setter: Sets the delta value for the wdirection Type: float

dimension
Â¶ Shape dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the dimension of the shape

evalpts
Â¶ Evaluated points.
Since there are multiple shapes contained in the multi objects, the evaluated points will be returned in the format of list of individual evaluated points which is also a list of Cartesian coordinates.
The following code example illustrates these details:
1 2 3 4 5 6 7 8
multi_obj = multi.SurfaceContainer() # it can also be multi.CurveContainer() # Add shapes to multi_obj via multi_obj.add() method # Then, the following loop will print all the evaluated points of the Multi object for idx, mpt in enumerate(multi_obj.evalpts): print("Shape", idx+1, "contains", len(mpt), "points. These points are:") for pt in mpt: line = ", ".join([str(p) for p in pt]) print(line)
Please refer to the wiki for details on using this class member.
Getter: Gets the evaluated points of all contained shapes

render
(**kwargs)Â¶ Renders the volumes.
The visualization component must be set using
vis
property before calling this method. Keyword Arguments:
cpcolor
: sets the color of the control points plotevalcolor
: sets the color of the volumefilename
: saves the plot with the input nameplot
: controls plot window visibility. Default: Trueanimate
: activates animation (if supported). Default: Falsedelta
: if True, the evaluation delta of the Multi object will be used. Default: Truegrid_size
: grid size for voxelization. Default: (16, 16, 16)use_mp
: flag to activate multithreaded voxelization. Default: Falsenum_procs
: number of concurrent processes for multithreaded voxelization. Default: 4
The
cpcolor
andevalcolor
arguments can be a string or a list of strings corresponding to the color values. Both arguments are processed separately, e.g.cpcolor
can be a string whereasevalcolor
can be a list or a tuple, or vice versa. A single string value sets the color to the same value. List input allows customization over the color values. If none provided, a random color will be selected.The
plot
argument is useful when you would like to work on the command line without any window context. Ifplot
flag is False, this method saves the plot as an image file (.png file where possible) and disables plot window popping out. If you donâ€™t provide a file name, the name of the image file will be pulled from the configuration class.

sample_size
Â¶ Sample size (for all parametric directions).
Sample size defines the number of points to evaluate. It also sets the
delta
property.The following figure illustrates the working principles of sample size property:
Please refer to the wiki for details on using this class member.
Getter: Gets sample size Setter: Sets sample size

sample_size_u
Â¶ Sample size for the udirection.
Sample size defines the number of points to evaluate. It also sets the
delta_u
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the udirection Setter: Sets sample size for the udirection Type: int

sample_size_v
Â¶ Sample size for the vdirection.
Sample size defines the number of points to evaluate. It also sets the
delta_v
property.Please refer to the wiki for details on using this class member.
Getter: Gets sample size for the vdirection Setter: Sets sample size for the vdirection Type: int
Compatibility and ConversionÂ¶
This module contains conversion operations related to control points, such as flipping arrays and adding weights.
Function ReferenceÂ¶

geomdl.compatibility.
combine_ctrlpts_weights
(ctrlpts, weights=None)Â¶ Multiplies control points by the weights to generate weighted control points.
This function is dimension agnostic, i.e. control points can be in any dimension but weights should be 1D.
The
weights
function parameter can be set to None to let the function generate a weights vector composed of 1.0 values. This feature can be used to convert BSpline basis to NURBS basis.Parameters:  ctrlpts (list, tuple) â€“ unweighted control points
 weights (list, tuple or None) â€“ weights vector; if set to None, a weights vector of 1.0s will be automatically generated
Returns: weighted control points
Return type: list

geomdl.compatibility.
flip_ctrlpts
(ctrlpts, size_u, size_v)Â¶ Flips a list of 1dimensional control points from vrow order to urow order.
urow order: each row corresponds to a list of u values
vrow order: each row corresponds to a list of v values
Parameters:  ctrlpts (list, tuple) â€“ control points in vrow order
 size_u (int) â€“ size in udirection (row length)
 size_v (int) â€“ size in vdirection (column length)
Returns: control points in urow order
Return type: list

geomdl.compatibility.
flip_ctrlpts2d
(ctrlpts2d, size_u=0, size_v=0)Â¶ Flips a list of surface 2D control points from [u][v] to [v][u] order.
Parameters:  ctrlpts2d (list, tuple) â€“ 2D control points
 size_u (int) â€“ size in Udirection (row length)
 size_v (int) â€“ size in Vdirection (column length)
Returns: flipped 2D control points
Return type: list

geomdl.compatibility.
flip_ctrlpts2d_file
(file_in='', file_out='ctrlpts_flip.txt')Â¶ Flips u and v directions of a 2D control points file and saves flipped coordinates to a file.
Parameters:  file_in (str) â€“ name of the input file (to be read)
 file_out (str) â€“ name of the output file (to be saved)
Raises: IOError â€“ an error occurred reading or writing the file

geomdl.compatibility.
flip_ctrlpts_u
(ctrlpts, size_u, size_v)Â¶ Flips a list of 1dimensional control points from urow order to vrow order.
urow order: each row corresponds to a list of u values
vrow order: each row corresponds to a list of v values
Parameters:  ctrlpts (list, tuple) â€“ control points in urow order
 size_u (int) â€“ size in udirection
 size_v (int) â€“ size in vdirection
Returns: control points in vrow order
Return type: list

geomdl.compatibility.
generate_ctrlpts2d_weights
(ctrlpts2d)Â¶ Generates unweighted control points from weighted ones in 2D.
This function
 Takes in 2D control points list whose coordinates are organized like (x*w, y*w, z*w, w)
 Converts the input control points list into (x, y, z, w) format
 Returns the result
Parameters: ctrlpts2d (list) â€“ 2D control points (P) Returns: 2D weighted control points (Pw) Return type: list

geomdl.compatibility.
generate_ctrlpts2d_weights_file
(file_in='', file_out='ctrlpts_weights.txt')Â¶ Generates unweighted control points from weighted ones in 2D.
 Takes in 2D control points list whose coordinates are organized like (x*w, y*w, z*w, w)
 Converts the input control points list into (x, y, z, w) format
 Saves the result to a file
Parameters:  file_in (str) â€“ name of the input file (to be read)
 file_out (str) â€“ name of the output file (to be saved)
Raises: IOError â€“ an error occurred reading or writing the file

geomdl.compatibility.
generate_ctrlpts_weights
(ctrlpts)Â¶ Generates unweighted control points from weighted ones in 1D.
This function
 Takes in 1D control points list whose coordinates are organized in (x*w, y*w, z*w, w) format
 Converts the input control points list into (x, y, z, w) format
 Returns the result
Parameters: ctrlpts (list) â€“ 1D control points (P) Returns: 1D weighted control points (Pw) Return type: list

geomdl.compatibility.
generate_ctrlptsw
(ctrlpts)Â¶ Generates weighted control points from unweighted ones in 1D.
This function
 Takes in a 1D control points list whose coordinates are organized in (x, y, z, w) format
 converts into (x*w, y*w, z*w, w) format
 Returns the result
Parameters: ctrlpts (list) â€“ 1D control points (P) Returns: 1D weighted control points (Pw) Return type: list

geomdl.compatibility.
generate_ctrlptsw2d
(ctrlpts2d)Â¶ Generates weighted control points from unweighted ones in 2D.
This function
 Takes in a 2D control points list whose coordinates are organized in (x, y, z, w) format
 converts into (x*w, y*w, z*w, w) format
 Returns the result
Therefore, the returned list could be a direct input of the NURBS.Surface class.
Parameters: ctrlpts2d (list) â€“ 2D control points (P) Returns: 2D weighted control points (Pw) Return type: list

geomdl.compatibility.
generate_ctrlptsw2d_file
(file_in='', file_out='ctrlptsw.txt')Â¶ Generates weighted control points from unweighted ones in 2D.
This function
 Takes in a 2D control points file whose coordinates are organized in (x, y, z, w) format
 Converts into (x*w, y*w, z*w, w) format
 Saves the result to a file
Therefore, the resultant file could be a direct input of the NURBS.Surface class.
Parameters:  file_in (str) â€“ name of the input file (to be read)
 file_out (str) â€“ name of the output file (to be saved)
Raises: IOError â€“ an error occurred reading or writing the file

geomdl.compatibility.
separate_ctrlpts_weights
(ctrlptsw)Â¶ Divides weighted control points by weights to generate unweighted control points and weights vector.
This function is dimension agnostic, i.e. control points can be in any dimension but the last element of the array should indicate the weight.
Parameters: ctrlptsw (list, tuple) â€“ weighted control points Returns: unweighted control points and weights vector Return type: list
Curve and Surface FittingÂ¶
fitting
module provides functions for interpolating and approximating Bspline curves and surfaces from points.
It provides functions for global interpolation and approximation to a list of data points.
Please see the following functions for details:
Function ReferenceÂ¶

geomdl.fitting.
interpolate_curve
(points, degree, **kwargs)Â¶ Curve interpolation through the data points.
Please refer to Algorithm A9.1 on The NURBS Book (2nd Edition), pp.369370 for details.
 Keyword Arguments:
centripetal
: activates centripetal parametrization method. Default: False
Parameters:  points (list, tuple) â€“ data points
 degree (int) â€“ degree of the output parametric curve
Returns: interpolated BSpline curve
Return type:

geomdl.fitting.
interpolate_surface
(points, size_u, size_v, degree_u, degree_v, **kwargs)Â¶ Surface interpolation through the data points.
Please refer to the Algorithm A9.4 on The NURBS Book (2nd Edition), pp.380 for details.
 Keyword Arguments:
centripetal
: activates centripetal parametrization method. Default: False
Parameters:  points (list, tuple) â€“ data points
 size_u (int) â€“ number of data points on the udirection
 size_v (int) â€“ number of data points on the vdirection
 degree_u (int) â€“ degree of the output surface for the udirection
 degree_v (int) â€“ degree of the output surface for the vdirection
Returns: interpolated BSpline surface
Return type:

geomdl.fitting.
approximate_curve
(points, degree, **kwargs)Â¶ Curve approximation using least squares method with fixed number of control points.
Please refer to The NURBS Book (2nd Edition), pp.410413 for details.
 Keyword Arguments:
centripetal
: activates centripetal parametrization method. Default: Falsectrlpts_size
: number of control points. Default: len(points)  1
Parameters:  points (list, tuple) â€“ data points
 degree (int) â€“ degree of the output parametric curve
Returns: approximated BSpline curve
Return type:

geomdl.fitting.
approximate_surface
(points, size_u, size_v, degree_u, degree_v, **kwargs)Â¶ Surface approximation using least squares method with fixed number of control points.
This algorithm interpolates the corner control points and approximates the remaining control points. Please refer to Algorithm A9.7 of The NURBS Book (2nd Edition), pp.422423 for details.
 Keyword Arguments:
centripetal
: activates centripetal parametrization method. Default: Falsectrlpts_size_u
: number of control points on the udirection. Default: size_u  1ctrlpts_size_v
: number of control points on the vdirection. Default: size_v  1
Parameters:  points (list, tuple) â€“ data points
 size_u (int) â€“ number of data points on the udirection,
 size_v (int) â€“ number of data points on the vdirection,
 degree_u (int) â€“ degree of the output surface for the udirection
 degree_v (int) â€“ degree of the output surface for the vdirection
Returns: approximated BSpline surface
Return type:
Surface GeneratorÂ¶
CPGen
module allows users to generate control points grids as an input to BSpline.Surface
and
NURBS.Surface
classes. This module is designed to enable more testing cases in a very simple way and
it doesnâ€™t have the capabilities of a fullyfeatured grid generator, but it should be enough to be used side by side
with BSpline
and NURBS
modules.
CPGen.Grid
class provides an easy way to generate control point grids for use with
BSpline.Surface
class and CPGen.GridWeighted
does the same for NURBS.Surface
class.
GridÂ¶

class
geomdl.CPGen.
Grid
(size_x, size_y, **kwargs)Â¶ Bases:
object
Simple control points grid generator to use with nonrational surfaces.
This class stores grid points in [x, y, z] format and the grid (control) points can be retrieved from the
grid
attribute. The zcoordinate of the control points can be set via the keyword argumentz_value
while initializing the class.Parameters:  size_x (float) â€“ width of the grid
 size_y (float) â€“ height of the grid

bumps
(num_bumps, **kwargs)Â¶ Generates arbitrary bumps (i.e. hills) on the 2dimensional grid.
This method generates hills on the grid defined by the num_bumps argument. It is possible to control the zvalue using bump_height argument. bump_height can be a positive or negative numeric value or it can be a list of numeric values.
Please note that, not all grids can be modified to have num_bumps number of bumps. Therefore, this function uses a bruteforce algorithm to determine whether the bumps can be generated or not. For instance:
test_grid = Grid(5, 10) # generates a 5x10 rectangle test_grid.generate(4, 4) # splits the rectangle into 2x2 pieces test_grid.bumps(100) # impossible, it will return an error message test_grid.bumps(1) # You will get a bump at the center of the generated grid
This method accepts the following keyword arguments:
bump_height
: zvalue of the generated bumps on the grid. Default: 5.0base_extent
: extension of the hill base from its center in terms of grid points. Default: 2base_adjust
: padding between the bases of the hills. Default: 0
Parameters: num_bumps (int) â€“ number of bumps (i.e. hills) to be generated on the 2D grid

generate
(num_u, num_v)Â¶ Generates grid using the input division parameters.
Parameters:  num_u (int) â€“ number of divisions in xdirection
 num_v (int) â€“ number of divisions in ydirection

grid
Â¶ Grid points.
Please refer to the wiki for details on using this class member.
Getter: Gets the 2dimensional list of points in [u][v] format

reset
()Â¶ Resets the grid.
Weighted GridÂ¶

class
geomdl.CPGen.
GridWeighted
(size_x, size_y, **kwargs)Â¶ Bases:
geomdl.CPGen.Grid
Simple control points grid generator to use with rational surfaces.
This class stores grid points in [x*w, y*w, z*w, w] format and the grid (control) points can be retrieved from the
grid
attribute. The zcoordinate of the control points can be set via the keyword argumentz_value
while initializing the class.Parameters:  size_x (float) â€“ width of the grid
 size_y (float) â€“ height of the grid

bumps
(num_bumps, **kwargs)Â¶ Generates arbitrary bumps (i.e. hills) on the 2dimensional grid.
This method generates hills on the grid defined by the num_bumps argument. It is possible to control the zvalue using bump_height argument. bump_height can be a positive or negative numeric value or it can be a list of numeric values.
Please note that, not all grids can be modified to have num_bumps number of bumps. Therefore, this function uses a bruteforce algorithm to determine whether the bumps can be generated or not. For instance:
test_grid = Grid(5, 10) # generates a 5x10 rectangle test_grid.generate(4, 4) # splits the rectangle into 2x2 pieces test_grid.bumps(100) # impossible, it will return an error message test_grid.bumps(1) # You will get a bump at the center of the generated grid
This method accepts the following keyword arguments:
bump_height
: zvalue of the generated bumps on the grid. Default: 5.0base_extent
: extension of the hill base from its center in terms of grid points. Default: 2base_adjust
: padding between the bases of the hills. Default: 0
Parameters: num_bumps (int) â€“ number of bumps (i.e. hills) to be generated on the 2D grid

generate
(num_u, num_v)Â¶ Generates grid using the input division parameters.
Parameters:  num_u (int) â€“ number of divisions in xdirection
 num_v (int) â€“ number of divisions in ydirection

grid
Â¶ Weighted grid points.
Please refer to the wiki for details on using this class member.
Getter: Gets the 2dimensional list of weighted points in [u][v] format

reset
()Â¶ Resets the grid.
Import and Export DataÂ¶
This module allows users to export/import NURBS shapes in common CAD exchange formats. The functions starting with import_ are used for generating Bspline and NURBS objects from the input files. The functions starting with export_ are used for saving Bspline and NURBS objects as files.
The following functions can only import/export control points or export evaluated points:
The following functions can only work with single or multiple surfaces:
exchange.export_obj()
exchange.export_stl()
exchange.export_off()
exchange.import_smesh()
exchange.export_smesh()
The following functions can be used to import/export complete NURBS shapes:
exchange.import_yaml()
exchange.export_yaml()
exchange.import_cfg()
exchange.export_cfg()
exchange.import_json()
exchange.export_json()
Function ReferenceÂ¶

geomdl.exchange.
import_txt
(file_name, two_dimensional=False, **kwargs)Â¶ Reads control points from a text file and generates a 1dimensional list of control points.
The following code examples illustrate importing different types of text files for curves and surfaces:
1 2 3 4 5 6 7 8
# Import curve control points from a text file curve_ctrlpts = exchange.import_txt(file_name="control_points.txt") # Import surface control points from a text file (1dimensional file) surf_ctrlpts = exchange.import_txt(file_name="control_points.txt") # Import surface control points from a text file (2dimensional file) surf_ctrlpts, size_u, size_v = exchange.import_txt(file_name="control_points.txt", two_dimensional=True)
If argument
jinja2=True
is set, then the input file is processed as a Jinja2 template. You can also use the following convenience template functions which correspond to the given mathematical equations:sqrt(x)
:cubert(x)
:pow(x, y)
:
You may set the file delimiters using the keyword arguments
separator
andcol_separator
, respectively.separator
is the delimiter between the coordinates of the control points. It could be comma1, 2, 3
or space1 2 3
or something else.col_separator
is the delimiter between the control points and is only valid whentwo_dimensional
isTrue
. Assuming thatseparator
is set to space, thencol_operator
could be semicolon1 2 3; 4 5 6
or pipe1 2 3 4 5 6
or comma1 2 3, 4 5 6
or something else.The defaults for
separator
andcol_separator
are comma (,) and semicolon (;), respectively.The following code examples illustrate the usage of the keyword arguments discussed above.
1 2 3 4 5 6
# Import curve control points from a text file delimited with space curve_ctrlpts = exchange.import_txt(file_name="control_points.txt", separator=" ") # Import surface control points from a text file (2dimensional file) w/ space and comma delimiters surf_ctrlpts, size_u, size_v = exchange.import_txt(file_name="control_points.txt", two_dimensional=True, separator=" ", col_separator=",")
Please note that this function does not check whether the user set delimiters to the same value or not.
Parameters:  file_name (str) â€“ file name of the text file
 two_dimensional (bool) â€“ type of the text file
Returns: list of control points, if two_dimensional, then also returns size in u and vdirections
Return type: list
Raises: IOError â€“ an error occurred reading the file

geomdl.exchange.
export_txt
(obj, file_name, two_dimensional=False, **kwargs)Â¶ Exports control points as a text file.
For curves the output is always a list of control points. For surfaces, it is possible to generate a 2D control point output file using
two_dimensional
flag. Please see the supported file formats for more details on the text file format.Please see
exchange.import_txt()
for detailed description of the keyword arguments.Parameters:  obj (abstract.Curve, abstract.Surface) â€“ a curve or a surface object
 file_name (str) â€“ file name of the text file to be saved
 two_dimensional (bool) â€“ type of the text file (only works for Surface objects)
Raises: IOError â€“ an error occurred writing the file

geomdl.exchange.
import_csv
(file_name, **kwargs)Â¶ Reads control points from a CSV file and generates a 1dimensional list of control points.
It is possible to use a different value separator via
separator
keyword argument. The following code segment illustrates the usage ofseparator
keyword argument.1 2 3 4 5
# By default, import_csv uses 'comma' as the value separator ctrlpts = exchange.import_csv("control_points.csv") # Alternatively, it is possible to import a file containing tabseparated values ctrlpts = exchange.import_csv("control_points.csv", separator="\t")
The only difference of this function from
exchange.import_txt()
is skipping the first line of the input file which generally contains the column headings.Parameters: file_name (str) â€“ file name of the text file Returns: list of control points Return type: list Raises: IOError â€“ an error occurred reading the file

geomdl.exchange.
export_csv
(obj, file_name, point_type='evalpts', **kwargs)Â¶ Exports control points or evaluated points as a CSV file.
Parameters:  obj (abstract.Curve, abstract.Surface) â€“ a curve or a surface object
 file_name (str) â€“ output file name
 point_type (str) â€“
ctrlpts
for control points orevalpts
for evaluated points
Raises: IOError â€“ an error occurred writing the file

geomdl.exchange.
import_cfg
(file_name, **kwargs)Â¶ Imports curves and surfaces from files in libconfig format.
Note
Requires libconf package.
Use
jinja2=True
to activate Jinja2 template processing. Please refer to the documentation for details.Parameters: file_name (str) â€“ name of the input file Returns: a list of NURBS curve(s) or surface(s) Return type: list Raises: IOError â€“ an error occurred writing the file

geomdl.exchange.
export_cfg
(obj, file_name)Â¶ Exports curves and surfaces in libconfig format.
Note
Requires libconf package.
Libconfig format is also used by the geomdl commandline application as a way to input shape data from the command line.
Parameters:  obj (abstract.Curve, abstract.Surface, multi.CurveContainer or multi.SurfaceContainer) â€“ input curve(s) or surface(s)
 file_name (str) â€“ name of the output file
Raises: IOError â€“ an error occurred writing the file

geomdl.exchange.
import_yaml
(file_name, **kwargs)Â¶ Imports curves and surfaces from files in YAML format.
Note
Requires ruamel.yaml package.
Use
jinja2=True
to activate Jinja2 template processing. Please refer to the documentation for details.Parameters: file_name (str) â€“ name of the input file Returns: a list of NURBS curve(s) or surface(s) Return type: list Raises: IOError â€“ an error occurred reading the file

geomdl.exchange.
export_yaml
(obj, file_name)Â¶ Exports curves and surfaces in YAML format.
Note
Requires ruamel.yaml package.
YAML format is also used by the geomdl commandline application as a way to input shape data from the command line.
Parameters:  obj (abstract.Curve, abstract.Surface, multi.CurveContainer or multi.SurfaceContainer) â€“ input curve(s) or surface(s)
 file_name (str) â€“ name of the output file
Raises: IOError â€“ an error occurred writing the file

geomdl.exchange.
import_json
(file_name, **kwargs)Â¶ Imports curves and surfaces from files in JSON format.
Use
jinja2=True
to activate Jinja2 template processing. Please refer to the documentation for details.Parameters: file_name (str) â€“ name of the input file Returns: a list of NURBS curve(s) or surface(s) Return type: list Raises: IOError â€“ an error occurred reading the file

geomdl.exchange.
export_json
(obj, file_name)Â¶ Exports curves and surfaces in JSON format.
JSON format is also used by the geomdl commandline application as a way to input shape data from the command line.
Parameters:  obj (abstract.Curve, abstract.Surface, multi.CurveContainer or multi.SurfaceContainer) â€“ input curve(s) or surface(s)
 file_name (str) â€“ name of the output file
Raises: IOError â€“ an error occurred writing the file

geomdl.exchange.
export_obj
(surface, file_name, **kwargs)Â¶ Exports surface(s) as a .obj file.
 Keyword Arguments:
vertex_spacing
: size of the triangle edge in terms of points sampled on the surface. Default: 2vertex_normals
: if True, compute vertex normals. Default: Falseupdate_delta
: use multisurface evaluation delta for all surfaces. Default: False
Parameters:  surface (abstract.Surface or multi.SurfaceContainer) â€“ surface or surfaces to be saved
 file_name (str) â€“ name of the output file
Raises: IOError â€“ an error occurred writing the file

geomdl.exchange.
export_stl
(surface, file_name, **kwargs)Â¶ Exports surface(s) as a .stl file in plain text or binary format.
 Keyword Arguments:
binary
: flag to generate a binary STL file. Default: Truevertex_spacing
: size of the triangle edge in terms of points sampled on the surface. Default: 2update_delta
: use multisurface evaluation delta for all surfaces. Default: False
Parameters:  surface (abstract.Surface or multi.SurfaceContainer) â€“ surface or surfaces to be saved
 file_name (str) â€“ name of the output file
Raises: IOError â€“ an error occurred writing the file

geomdl.exchange.
export_off
(surface, file_name, **kwargs)Â¶ Exports surface(s) as a .off file.
 Keyword Arguments:
vertex_spacing
: size of the triangle edge in terms of points sampled on the surface. Default: 2update_delta
: use multisurface evaluation delta for all surfaces. Default: False
Parameters:  surface (abstract.Surface or multi.SurfaceContainer) â€“ surface or surfaces to be saved
 file_name (str) â€“ name of the output file
Raises: IOError â€“ an error occurred writing the file

geomdl.exchange.
import_smesh
(file)Â¶ Generates NURBS surface(s) from surface mesh (smesh) file(s).
smesh files are some text files which contain a set of NURBS surfaces. Each file in the set corresponds to one NURBS surface. Most of the time, you receive multiple smesh files corresponding to an complete object composed of several NURBS surfaces. The files have the extensions of
txt
ordat
and they are named assmesh.X.Y.txt
smesh.X.dat
where X and Y correspond to some integer value which defines the set the surface belongs to and part number of the surface inside the complete object.
Parameters: file (str) â€“ path to a directory containing mesh files or a single mesh file Returns: list of NURBS surfaces Return type: list Raises: IOError â€“ an error occurred reading the file

geomdl.exchange.
export_smesh
(surface, file_name, **kwargs)Â¶ Exports surface(s) as surface mesh (smesh) files.
Please see
import_smesh()
for details on the file format.Parameters:  surface (abstract.Surface or multi.SurfaceContainer) â€“ surface(s) to be exported
 file_name (str) â€“ name of the output file
Raises: IOError â€“ an error occurred writing the file

geomdl.exchange.
import_vmesh
(file)Â¶ Imports NURBS volume(s) from volume mesh (vmesh) file(s).
Parameters: file (str) â€“ path to a directory containing mesh files or a single mesh file Returns: list of NURBS volumes Return type: list Raises: IOError â€“ an error occurred reading the file

geomdl.exchange.
export_vmesh
(volume, file_name, **kwargs)Â¶ Exports volume(s) as volume mesh (vmesh) files.
Parameters:  volume (abstract.Volume) â€“ volume(s) to be exported
 file_name (str) â€“ name of the output file
Raises: IOError â€“ an error occurred writing the file

geomdl.exchange.
import_3dm
(file_name, **kwargs)Â¶ Imports Rhinoceros/OpenNURBS .3dm file format.
Note
Requires
rw3dm
module: https://github.com/orbingol/rw3dmParameters: file_name (str) â€“ input file name

geomdl.exchange.
export_3dm
(obj, file_name, **kwargs)Â¶ Exports NURBS curves and surfaces in Rhinoceros/OpenNURBS .3dm format.
Note
Requires
rw3dm
module: https://github.com/orbingol/rw3dmParameters:  obj (abstract.Curve, abstract.Surface, multi.CurveContainer, multi.SurfaceContainer) â€“ curves/surfaces to be exported
 file_name (str) â€“ file name
VTK SupportÂ¶
The following functions export control points and evaluated points as VTK files (in legacy format).

geomdl.exchange_vtk.
export_polydata
(obj, file_name, point_type='evalpts', **kwargs)Â¶ Exports control points or evaluated points in VTK Polydata format.
Please see the following document for details: http://www.vtk.org/VTK/img/fileformats.pdf
Parameters:  obj (abstract.Curve, abstract.Surface) â€“ a curve or a surface object
 file_name (str) â€“ output file name
 point_type (str) â€“
ctrlpts
for control points orevalpts
for evaluated points
Raises: IOError â€“ an error occurred writing the file
TessellationÂ¶
The tessellate
module provides tessellation algorithms for surfaces. The following example illustrates the usage
scenario of the tessellation algorithms with surfaces.
1 2 3 4 5 6 7 8 9 10 11  from geomdl import NURBS
from geomdl import tessellate
# Create a surface instance
surf = NURBS.Surface()
# Set tessellation algorithm (you can use another algorithm)
surf.tessellator = tessellate.TriangularTessellate()
# Tessellate surface
surf.tessellate()

NURBSPython uses TriangularTessellate
class for surface tessellation by default.
Abstract TessellatorÂ¶

class
geomdl.tessellate.
AbstractTessellate
(**kwargs)Â¶ Bases:
object
Abstract base class for tessellation algorithms.

arguments
Â¶ Arguments passed to the tessellation function.
This property allows customization of the tessellation algorithm, and mainly designed to allow users to pass additional arguments to the tessellation function or change the behavior of the algorithm at runtime. This property can be thought as a way to input and store extra data for the tessellation functionality.
Getter: Gets the tessellation arguments Setter: Sets the tessellation arguments

faces
Â¶ Objects generated after tessellation.
Getter: Gets the faces Type: elements.AbstractEntity

is_tessellated
()Â¶ Checks if vertices and faces are generated.
Returns: tessellation status Return type: bool

reset
()Â¶ Clears stored vertices and faces.

tessellate
(points, **kwargs)Â¶ Abstract method for the implementation of the tessellation algorithm.
This algorithm should update
vertices
andfaces
properties.Note
This is an abstract method and it must be implemented in the subclass.
Parameters: points â€“ points to be tessellated

vertices
Â¶ Vertex objects generated after tessellation.
Getter: Gets the vertices Type: elements.AbstractEntity

Triangular TessellatorÂ¶

class
geomdl.tessellate.
TriangularTessellate
(**kwargs)Â¶ Bases:
geomdl.tessellate.AbstractTessellate
Triangular tessellation algorithm for surfaces.
This class provides the default triangular tessellation algorithm for surfaces.

arguments
Â¶ Arguments passed to the tessellation function.
This property allows customization of the tessellation algorithm, and mainly designed to allow users to pass additional arguments to the tessellation function or change the behavior of the algorithm at runtime. This property can be thought as a way to input and store extra data for the tessellation functionality.
Getter: Gets the tessellation arguments Setter: Sets the tessellation arguments

faces
Â¶ Objects generated after tessellation.
Getter: Gets the faces Type: elements.AbstractEntity

is_tessellated
()Â¶ Checks if vertices and faces are generated.
Returns: tessellation status Return type: bool

reset
()Â¶ Clears stored vertices and faces.

tessellate
(points, **kwargs)Â¶ Applies triangular tessellation.
This function does not check if the points have already been tessellated.
 Keyword Arguments:
size_u
: number of points on the udirectionsize_v
: number of points on the vdirection
Parameters: points (list or tuple) â€“ list of points

vertices
Â¶ Vertex objects generated after tessellation.
Getter: Gets the vertices Type: elements.AbstractEntity

VoxelizationÂ¶
voxelize
module provides functions for voxelizing NURBS volumes. voxelize()
also supports multithreaded
operations via multiporcessing module.
Function ReferenceÂ¶

geomdl.voxelize.
voxelize
(obj, **kwargs)Â¶ Generates binary voxel representation of the surfaces and volumes.
 Keyword Arguments:
grid_size
: size of the voxel grid. Default: (16, 16, 16)padding
: voxel padding for inouts finding. Default: 10e8use_mp
: flag to activate multithreaded voxelization. Default: Falsenum_procs
: number of concurrent processes for multithreaded voxelization. Default: 4
Parameters: obj (abstract.Surface or abstract.Volume) â€“ input surface(s) or volume(s) Returns: voxel grid and filled information Return type: tuple

geomdl.voxelize.
save_voxel_grid
(voxel_grid, file_name)Â¶ Saves binary voxel grid as a binary file.
The binary file is structured in littleendian unsigned int format.
Parameters:  voxel_grid (list, tuple) â€“ binary voxel grid
 file_name (str) â€“ file name to save
Geometric EntitiesÂ¶
The geometric entities are used for advanced algorithms, such as tessellation. The AbstractEntity
class
provides the abstract base for all geometric and topological entities.
This module provides the following geometric and topological entities:
Class ReferenceÂ¶

class
geomdl.elements.
Vertex
(*args, **kwargs)Â¶ Bases:
geomdl.elements.AbstractEntity
3dimensional Vertex entity with spatial and parametric position.

data
Â¶ (x,y,z) components of the vertex.
Getter: Gets the 3dimensional components Setter: Sets the 3dimensional components

id
Â¶ Identifier for the geometric entity.
It must be an integer number, otherwise the setter will raise a ValueError.
Getter: Gets the identifier Setter: Sets the identifier Type: int

inside
Â¶ Insideoutside flag
Getter: Gets the flag Setter: Sets the flag Type: bool

u
Â¶ Parametric ucomponent of the vertex
Getter: Gets the ucomponent of the vertex Setter: Sets the ucomponent of the vertex Type: float

uv
Â¶ Parametric (u,v) pair of the vertex
Getter: Gets the uvcomponent of the vertex Setter: Sets the uvcomponent of the vertex Type: list, tuple

v
Â¶ Parametric vcomponent of the vertex
Getter: Gets the vcomponent of the vertex Setter: Sets the vcomponent of the vertex Type: float

x
Â¶ xcomponent of the vertex
Getter: Gets the xcomponent of the vertex Setter: Sets the xcomponent of the vertex Type: float

y
Â¶ ycomponent of the vertex
Getter: Gets the ycomponent of the vertex Setter: Sets the ycomponent of the vertex Type: float

z
Â¶ zcomponent of the vertex
Getter: Gets the zcomponent of the vertex Setter: Sets the zcomponent of the vertex Type: float


class
geomdl.elements.
Triangle
(*args, **kwargs)Â¶ Bases:
geomdl.elements.AbstractEntity
Triangle entity which represents a triangle composed of vertices.

add_vertex
(*args)Â¶ Adds vertices to the Triangle object.
This method takes a single or a list of vertices as its function arguments.

edges
Â¶ Edges of the triangle
Getter: Gets the list of vertices that generates the edges of the triangle Type: list

id
Â¶ Identifier for the geometric entity.
It must be an integer number, otherwise the setter will raise a ValueError.
Getter: Gets the identifier Setter: Sets the identifier Type: int

inside
Â¶ Insideoutside flag
Getter: Gets the flag Setter: Sets the flag Type: bool

vertex_ids
Â¶ Vertex indices
Vertex numbering starts from 1.
Getter: Gets the vertex indices Type: list

vertex_ids_zero
Â¶ Zeroindexed vertex indices
Vertex numbering starts from 0.
Getter: Gets the vertex indices Type: list

vertices
Â¶ Vertices of the triangle
Getter: Gets the list of vertices Type: tuple

vertices_raw
Â¶ Vertices which generates a closed triangle
Adds the first vertex as a last element of the return value (good for plotting)
Getter: Gets the list of vertices Type: list

vertices_uv
Â¶ Parametric coordinates of the triangle vertices
Getter: Gets the parametric coordinates of the vertices Type: list


class
geomdl.elements.
Quad
(*args, **kwargs)Â¶ Bases:
geomdl.elements.AbstractEntity
Quad entity which represents a quadrilateral structure composed of vertices.

add_vertex
(*args)Â¶ Adds vertices to the Quad object.
This method takes a single or a list of vertices as its function arguments.

data
Â¶ Vertex indices.
Getter: Gets the vertex indices Setter: Sets the vertex indices

id
Â¶ Identifier for the geometric entity.
It must be an integer number, otherwise the setter will raise a ValueError.
Getter: Gets the identifier Setter: Sets the identifier Type: int


class
geomdl.elements.
Face
(*args, **kwargs)Â¶ Bases:
geomdl.elements.AbstractEntity
Representation of Face entity which is composed of triangles or quads.

add_triangle
(*args)Â¶ Adds triangles to the Face object.
This method takes a single or a list of triangles as its function arguments.

id
Â¶ Identifier for the geometric entity.
It must be an integer number, otherwise the setter will raise a ValueError.
Getter: Gets the identifier Setter: Sets the identifier Type: int

triangles
Â¶ Triangles of the face
Getter: Gets the list of triangles Type: tuple


class
geomdl.elements.
Body
(*args, **kwargs)Â¶ Bases:
geomdl.elements.AbstractEntity
Representation of Body entity which is composed of faces.

add_face
(*args)Â¶ Adds faces to the Body object.
This method takes a single or a list of faces as its function arguments.

faces
Â¶ Faces of the body
Getter: Gets the list of faces Type: tuple

id
Â¶ Identifier for the geometric entity.
It must be an integer number, otherwise the setter will raise a ValueError.
Getter: Gets the identifier Setter: Sets the identifier Type: int

Ray ModuleÂ¶
ray
module provides utilities for ray operations. A ray (halfline) is defined by two distinct points represented
by Ray
class. This module also provides a function to compute intersection of 2 rays.
Function and Class ReferenceÂ¶

class
geomdl.ray.
Ray
(point1, point2)Â¶ Representation of a ndimensional ray generated from 2 points.
A ray is defined by where :math`t` is the parameter value, is the vector component of the ray, is the origin point and is the second point which is required to define a line segment
Parameters:  point1 (list, tuple) â€“ 1st point of the line segment
 point2 (list, tuple) â€“ 2nd point of the line segment

d
Â¶ Vector component of the ray (d)
Please refer to the wiki for details on using this class member.
Getter: Gets the vector component of the ray

dimension
Â¶ Spatial dimension of the ray
Please refer to the wiki for details on using this class member.
Getter: Gets the dimension of the ray

eval
(t=0)Â¶ Finds the point on the line segment defined by the input parameter.
returns the origin (1st) point, defined by the input argument
point1
and returns the end (2nd) point, defined by the input argumentpoint2
.Parameters: t (float) â€“ parameter Returns: point at the parameter value Return type: tuple

class
geomdl.ray.
RayIntersection
Â¶ The status of the ray intersection operation

COLINEAR
= 2Â¶

INTERSECT
= 1Â¶

SKEW
= 3Â¶


geomdl.ray.
intersect
(ray1, ray2, **kwargs)Â¶ Finds intersection of 2 rays.
This functions finds the parameter values for the 1st and 2nd input rays and returns a tuple of
(parameter for ray1, parameter for ray2, intersection status)
.status
value is a enum type which reports the case which the intersection operation encounters.The intersection operation can encounter 3 different cases:
 Intersecting: This is the anticipated solution. Returns
(t_ray1, t_ray2, RayIntersection.INTERSECT)
 Colinear: The rays can be parallel or coincident. Returns
(1, 1, RayIntersection.COLINEAR)
 Skew: The rays are neither parallel nor intersecting. Returns
(t_ray1, t_ray2, RayIntersection.SKEW)
Please note that this operation is only implemented for 2 and 3dimensional rays.
Parameters:  ray1 â€“ 1st ray
 ray2 â€“ 2nd ray
Returns: a tuple of the parameter (t) for ray1 and ray2, and status of the intersection
Return type: tuple
 Intersecting: This is the anticipated solution. Returns
NURBSPython takes The NURBS Book 2nd Edition by Piegl & Tiller as the main reference for the evaluation algorithms.
The users may want to use different algorithms and Evaluators serve directly to this purpose by allowing users
to switch evaluation algorithms (i.e. evaluation strategy) at runtime. Please see evaluator
property documentation
for more details.
Visualization ModulesÂ¶
NURBSPython provides an abstract base for visualization modules. It is a part of the Core Library and it can be used to implement various visualization backends.
NURBSPython comes with the following visualization modules:
Visualization BaseÂ¶
The visualization component in the NURBSPython package provides an easy way to visualise the surfaces and the 2D/3D curves generated using the library.
Class ReferenceÂ¶
Matplotlib ImplementationÂ¶
This module provides Matplotlib visualization implementation for NURBSPython.
Class ReferenceÂ¶

class
geomdl.visualization.VisMPL.
VisConfig
(**kwargs)Â¶ Bases:
geomdl.vis.VisConfigAbstract
Configuration class for Matplotlib visualization module.
This class is only required when you would like to change the visual defaults of the plots and the figure, such as hiding control points plot or legend.
The
VisMPL
module has the following configuration variables:ctrlpts
(bool): Control points polygon/grid visibility. Default: Trueevalpts
(bool): Curve/surface points visibility. Default: Truebbox
(bool): Bounding box visibility. Default: Falselegend
(bool): Figure legend visibility. Default: Trueaxes
(bool): Axes and figure grid visibility. Default: Truelabels
(bool): Axis labels visibility. Default: Truetrims
(bool): Trim curves visibility. Default: Trueaxes_equal
(bool): Enables or disables equal aspect ratio for the axes. Default: Truefigure_size
(list): Size of the figure in (x, y). Default: [10.67, 8]figure_dpi
(int): Resolution of the figure in DPI. Default: 96trim_size
(int): Size of the trim curves. Default: 20
The following example illustrates the usage of the configuration class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Create a curve (or a surface) instance curve = NURBS.Curve() # Skipping degree, knot vector and control points assignments # Create a visualization configuration instance with no legend, no axes and set the resolution to 120 dpi vis_config = VisMPL.VisConfig(legend=False, axes=False, figure_dpi=120) # Create a visualization method instance using the configuration above vis_obj = VisMPL.VisCurve2D(vis_config) # Set the visualization method of the curve object curve.vis = vis_obj # Plot the curve curve.render()
Please refer to the Examples Repository for more details.

static
save_figure_as
(fig, filename)Â¶ Saves the figure as a file.
Parameters:  fig â€“ a Matplotlib figure instance
 filename â€“ file name to save

static
set_axes_equal
(ax)Â¶ Sets equal aspect ratio across the three axes of a 3D plot.
Contributed by Xuefeng Zhao.
Parameters: ax â€“ a Matplotlib axis, e.g., as output from plt.gca().

class
geomdl.visualization.VisMPL.
VisCurve2D
(config=<geomdl.visualization.VisMPL.VisConfig object>)Â¶ Bases:
geomdl.vis.VisAbstract
Matplotlib visualization module for 2D curves

add
(ptsarr, plot_type, name='', color='')Â¶ Adds points sets to the visualization instance for plotting.
Parameters:  ptsarr (list, tuple) â€“ control or evaluated points
 plot_type (str) â€“ type of the plot, e.g. ctrlpts, evalpts, bbox, etc.
 name (str) â€“ name of the plot displayed on the legend
 color (str) â€“ plot color

animate
(**kwargs)Â¶ Generates animated plots (if supported).
If the implemented visualization module supports animations, this function will create an animated figure. Otherwise, it will call
render()
method by default.

clear
()Â¶ Clears the points, colors and names lists.

ctrlpts_offset
Â¶ Defines an offset value for the control points grid plots
Only makes sense to use with surfaces with dense control points grid.
Getter: Gets the offset value Setter: Sets the offset value Type: float

render
(**kwargs)Â¶ Plots the 2D curve and the control points polygon.

size
(plot_type)Â¶ Returns the number of plots defined by the plot type.
Parameters: plot_type (str) â€“ plot type Returns: number of plots defined by the plot type Return type: int

vconf
Â¶ User configuration class for visualization
Getter: Gets the user configuration class Type: vis.VisConfigAbstract


class
geomdl.visualization.VisMPL.
VisCurve3D
(config=<geomdl.visualization.VisMPL.VisConfig object>)Â¶ Bases:
geomdl.vis.VisAbstract
Matplotlib visualization module for 3D curves.

add
(ptsarr, plot_type, name='', color='')Â¶ Adds points sets to the visualization instance for plotting.
Parameters:  ptsarr (list, tuple) â€“ control or evaluated points
 plot_type (str) â€“ type of the plot, e.g. ctrlpts, evalpts, bbox, etc.
 name (str) â€“ name of the plot displayed on the legend
 color (str) â€“ plot color

animate
(**kwargs)Â¶ Generates animated plots (if supported).
If the implemented visualization module supports animations, this function will create an animated figure. Otherwise, it will call
