NURBSPython v5.x DocumentationÂ¶
Welcome to the NURBSPython (geomdl) v5.x documentation!
NURBSPython (geomdl) is a crossplatform (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 (geomdl) provides easytouse data structures for storing geometry descriptions in addition to the fundamental and advanced evaluation algorithms.
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 (geomdl):
 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
 Support for common geometric algorithms: tessellation, voxelization, ray intersection, etc.
 Construct surfaces and volumes, extract isosurfaces via
construct
module  Customizable visualization and animation options with Matplotlib, Plotly and VTK modules
 Import geometry data from common CAD formats, such as 3DM and SAT.
 Export geometry data into common CAD formats, such as 3DM, STL, OBJ and VTK
 Support importing/exporting in JSON, YAML and libconfig formats
 Jinja2 support for file imports
 Pure Python, no external C/C++ or FORTRAN library dependencies
 Python compatibility: 2.7.x, 3.4.x and later
 For higher performance, optional Compile with Cython options are also available
 Easy to install via pip or conda
 Docker images are available
geomdlshapes
module for generating common spline and analytic geometriesgeomdlcli
module for using the library from the command line
NURBSPython (geomdl) contains the following fundamental geometric algorithms:
 Point evaluation
 Derivative evaluation
 Knot insertion
 Knot removal
 Knot vector refinement
 Degree elevation
 Degree reduction
ReferencesÂ¶
 Leslie Piegl and Wayne Tiller. The NURBS Book. Springer Science & Business Media, 2012.
 David F. Rogers. An Introduction to NURBS: With Historical Perspective. Academic Press, 2001.
 Elaine Cohen et al. Geometric Modeling with Splines: An Introduction. CRC Press, 2001.
 Mark de Berg et al. Computational Geometry: Algorithms and Applications. SpringerVerlag TELOS, 2008.
 John F. Hughes et al. Computer Graphics: Principles and Practice. Pearson Education, 2014.
 Fletcher Dunn and Ian Parberry. 3D Math Primer for Graphics and Game Development. CRC Press, 2015.
 Erwin Kreyszig. Advanced Engineering Mathematics. John Wiley & Sons, 2010.
 Erich Gamma et al. Design Patterns: Elements of Reusable ObjectOriented Software. AddisonWesley, 1994.
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}
}
LicensesÂ¶
 Source code is released under the terms of the MIT License
 Examples are released under the terms of the MIT License
 Documentation is released under the terms of CC BY 4.0
Questions and AnswersÂ¶
What is NURBS?Â¶
NURBS is an acronym for NonUniform Rational Basis Spline and it represents a mathematical model for generation of geometric shapes in a flexible way. It is a wellaccepted industry standard and used as a basis for nearly all of the 3dimensional modeling and CAD/CAM software packages as well as modeling and visualization frameworks.
Although the mathematical theory of behind the splines dates back to early 1900s, the spline theory in the way we know is coined by Isaac (Iso) Schoenberg and developed further by various researchers around the world.
The following books are recommended for individuals who prefer to investigate the technical details of NURBS:
Why NURBSPython?Â¶
NURBSPython started as a final 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 a free and opensource, objectoriented, pure Python NURBS library and releasing it on the public domain. As an added challenge to the project, everything was developed using Python Standard Library but no other external modules.
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 a userfriendly library, regardless of the mathematical complexity of the splines. To give a head start, it comes with 40+ examples for various use cases. It also provides several extension modules for
 Using the library directly from the commandline
 Generating common spline shapes
 Rhino .3dm file import/export support
 ACIS .sat file import support
Moreover, NURBSPython and its extensions are free and opensource projects distributed under the MIT license.
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 (geomdl) is tested with Python versions 2.7.x, 3.4.x and higher.
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.
Alternatively, you may send an email to nurbspython@googlegroups.com
.
How can I add a new feature?Â¶
The library is designed to be extensible in mind. It provides a set of abstract classes
for creating new geometry types. All classes use evaluators which contain the evaluation
algorithms. Evaluator classes can be extended for new type of algorithms. Please refer to BSpline
and NURBS
modules for implementation examples. It would be also a good idea to refer to the constructors of the abstract
classes for more details.
Why doesnâ€™t NURBSPython have XYZ feature?Â¶
NURBSPython tries to keep the geometric operations on the parametric space without any conversion to other representations. This approach makes some operations and queries hard to implement. Keeping NURBSPython independent of libraries that require compilation caused including implementations some wellknown geometric queries and computations, as well as a simple linear algebra module. However, the main purpose is providing a base for NURBS data and fundamental operations while keeping the external dependencies at minimum. It is usersâ€™ choice to extend the library and add new more advanced features (e.g. intersection computations) or capabilities (e.g. a new file format import/export support).
All advanced features should be packaged separately. If you are developing a feature to replace an existing feature, it might be a good idea to package it separately.
NURBSPython may seem to keep very high standards by means of accepting contributions. For instance, if you implement a feature applicable to curves but not surfaces and volumes, such a pull request wonâ€™t be accepted till you add that feature to surfaces and volumes. Similarly, if you change a single module and/or the function you use most frequently, but that change is affecting the library as a whole, your pull request will be put on hold.
If you are not interested in such level of contributions, it is suggested to create a separate module and add geomdl
as its dependency. If you create a module which uses geomdl
, please let the developers know via emailing
nurbspython@googlegroups.com
and you may be credited as a contributor.
Documentation references to the text booksÂ¶
NURBSPython contains implementations of several algorithms and equations from the references stated in the Introduction section. Please be aware that there is always a difference between an algorithm and an implementation. Depending on the function/method documentation you are looking, it might be an implementation of an algorithm, an equation, a set of equations or the concept/the idea discussed in the given page range.
Why doesnâ€™t NURBSPython follow the algorithms?Â¶
Actually, NURBSPython does follow the algorithms pretty much all the time. However, as stated above, the implementation that you are looking at might not belong to an algorithm, but an equation or a concept.
ContributingÂ¶
Bugs reportsÂ¶
You are encouraged to use the Bug Reporting Template on the issue tracker for reporting bugs. Please fill all required fields and be clear as much as possible. You may attach scripts and sample data to the ticket.
All bug reports must be reproducable. Tickets with missing or unclear information may be ignored.
Please email the author if you have any questions about bug reporting.
Pull requestsÂ¶
Before working on a pull request, please contact the author or open a ticket on the issue tracker to discuss the details. Otherwise, your pull requests may be ignored.
Feature requestsÂ¶
Please email the author for feature requests with the details of your feature request.
Questions and commentsÂ¶
Using nurbspython@googlegroups.com
is strongly encouraged for questions and comments.
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.
Note
On some Linux and MacOS systems, you may encounter 2 different versions of Python installed. In that case Python 2.x
package would use python2
and pip2
, whereas Python 3.x package would use python3
and pip3
. The
default python
and pip
commands could be linked to one of those. Please check your installed Python version
via python V
to make sure that you are using the correct Python package.
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 user geomdl
Upgrading to the latest version:
$ pip install geomdl upgrade
Installing a specific version:
$ pip install user geomdl==5.0.0
Install via CondaÂ¶
NURBSPython can also be installed/upgraded via conda package manager from the Anaconda Cloud repository.
Installing:
$ conda install c orbingol geomdl
Upgrading to the latest version:
$ 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.
The most convenient method to install NURBSPython manually is using pip
:
$ pip install user .
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:
$ pip install user e .
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.
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.
Then, you can execute the following from your favorite IDE or from the command line:
$ pytest
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 user . 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 user . 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.
BasicsÂ¶
In order to generate a spline shape with NURBSPython, you need 3 components:
 degree
 knot vector
 control points
The number of components depend on the parametric dimensionality of the shape regardless of the spatial dimensionality.
 curve is parametrically 1dimensional (or 1manifold)
 surface is parametrically 2dimensional (or 2manifold)
 volume is parametrically 3dimensional (or 3manifold)
Parametric dimensions are defined by u
, v
, w
and spatial dimensions are defined by x
, y
, z
.
Working with the curvesÂ¶
In this section, we will cover the basics of spline curve generation using NURBSPython. The following code snippet is an example to a 3dimensional curve.
1 2 3 4 5 6 7 8 9 10 11 12 13  from geomdl import BSpline
# Create the curve instance
crv = BSpline.Curve()
# Set degree
crv.degree = 2
# Set control points
crv.ctrlpts = [[1, 0, 0], [1, 1, 0], [0, 1, 0]]
# Set knot vector
crv.knotvector = [0, 0, 0, 1, 1, 1]

As described in the introduction text, we set the 3 required components to generate a 3dimensional spline curve.
Evaluating the curve pointsÂ¶
The code snippet is updated to retrieve evaluated curve points.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  from geomdl import BSpline
# Create the curve instance
crv = BSpline.Curve()
# Set degree
crv.degree = 2
# Set control points
crv.ctrlpts = [[1, 0, 0], [1, 1, 0], [0, 1, 0]]
# Set knot vector
crv.knotvector = [0, 0, 0, 1, 1, 1]
# Get curve points
points = crv.evalpts
# Do something with the evaluated points
for pt in points:
print(pt)

evalpts
property will automatically call evaluate()
function.
Getting the curve point at a specific parameterÂ¶
evaluate_single
method will return the point evaluated as the specified parameter.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  from geomdl import BSpline
# Create the curve instance
crv = BSpline.Curve()
# Set degree
crv.degree = 2
# Set control points
crv.ctrlpts = [[1, 0, 0], [1, 1, 0], [0, 1, 0]]
# Set knot vector
crv.knotvector = [0, 0, 0, 1, 1, 1]
# Get curve point at u = 0.5
point = crv.evaluate_single(0.5)

Setting the evaluation deltaÂ¶
Evaluation delta is used to change the number of evaluated points. Increasing the number of points will result in a
bigger evaluated points array, as described with evalpts
property and decreasing will reduce the size of the
evalpts
array. Therefore, evaluation delta can also be used to change smoothness of the plots generated using
the visualization modules.
delta
property will set the evaluation delta. It is also possible to use sample_size
property to set the number
of evaluated 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  from geomdl import BSpline
# Create the curve instance
crv = BSpline.Curve()
# Set degree
crv.degree = 2
# Set control points
crv.ctrlpts = [[1, 0, 0], [1, 1, 0], [0, 1, 0]]
# Set knot vector
crv.knotvector = [0, 0, 0, 1, 1, 1]
# Set evaluation delta
crv.delta = 0.005
# Get evaluated points
points_a = crv.evalpts
# Update delta
crv.delta = 0.1
# The curve will be automatically reevaluated
points_b = crv.evalpts

Inserting a knotÂ¶
insert_knot
method is recommended for this purpose.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  from geomdl import BSpline
# Create the curve instance
crv = BSpline.Curve()
# Set degree
crv.degree = 2
# Set control points
crv.ctrlpts = [[1, 0, 0], [1, 1, 0], [0, 1, 0]]
# Set knot vector
crv.knotvector = [0, 0, 0, 1, 1, 1]
# Insert knot
crv.insert_knot(0.5)

PlottingÂ¶
To plot the curve, a visualization module should be imported and curve should be updated to use the visualization module.
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 BSpline
# Create the curve instance
crv = BSpline.Curve()
# Set degree
crv.degree = 2
# Set control points
crv.ctrlpts = [[1, 0, 0], [1, 1, 0], [0, 1, 0]]
# Set knot vector
crv.knotvector = [0, 0, 0, 1, 1, 1]
# Import Matplotlib visualization module
from geomdl.visualization import VisMPL
# Set the visualization component of the curve
crv.vis = VisMPL.VisCurve3D()
# Plot the curve
crv.render()

Convert nonrational to rational curveÂ¶
The following code snippet generates a BSpline (nonrational) curve and converts it into a NURBS (rational) curve.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  from geomdl import BSpline
# Create the curve instance
crv = BSpline.Curve()
# Set degree
crv.degree = 2
# Set control points
crv.ctrlpts = [[1, 0, 0], [1, 1, 0], [0, 1, 0]]
# Set knot vector
crv.knotvector = [0, 0, 0, 1, 1, 1]
# Import convert module
from geomdl import convert
# BSpline to NURBS
crv_rat = convert.bspline_to_nurbs(crv)

Using knot vector generatorÂ¶
Knot vector generator is located in the knotvector module.
1 2 3 4 5 6 7 8 9 10 11 12 13 14  from geomdl import BSpline
from geomdl import knotvector
# Create the curve instance
crv = BSpline.Curve()
# Set degree
crv.degree = 2
# Set control points
crv.ctrlpts = [[1, 0, 0], [1, 1, 0], [0, 1, 0]]
# Generate a uniform knot vector
crv.knotvector = knotvector.generate(crv.degree, crv.ctrlpts_size)

Plotting multiple curvesÂ¶
multi module can be used to plot multiple curves on the same figure.
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  from geomdl import BSpline
from geomdl import multi
from geomdl import knotvector
# Create the curve instance #1
crv1 = BSpline.Curve()
# Set degree
crv1.degree = 2
# Set control points
crv1.ctrlpts = [[1, 0, 0], [1, 1, 0], [0, 1, 0]]
# Generate a uniform knot vector
crv1.knotvector = knotvector.generate(crv1.degree, crv1.ctrlpts_size)
# Create the curve instance #2
crv2 = BSpline.Curve()
# Set degree
crv2.degree = 3
# Set control points
crv2.ctrlpts = [[1, 0, 0], [1, 1, 0], [2, 1, 0], [1, 1, 0]]
# Generate a uniform knot vector
crv2.knotvector = knotvector.generate(crv2.degree, crv2.ctrlpts_size)
# Create a curve container
mcrv = multi.CurveContainer(crv1, crv2)
# Import Matplotlib visualization module
from geomdl.visualization import VisMPL
# Set the visualization component of the curve container
mcrv.vis = VisMPL.VisCurve3D()
# Plot the curves in the curve container
mcrv.render()

Please refer to the Examples Repository for more curve examples.
Working with the surfacesÂ¶
The majority of the surface API is very similar to the curve API. Since a surface is defined on a 2dimensional
parametric space, the getters/setters have a suffix of _u
and _v
; such as knotvector_u
and
knotvector_v
.
For setting up the control points, please refer to the control points manager documentation.
Please refer to the Examples Repository for surface examples.
Working with the volumesÂ¶
Volumes are defined on a 3dimensional parametric space. Working with the volumes are very similar to working
with the surfaces. The only difference is the 3rd parametric dimension, w
. For instance, to access the
knot vectors, the properties you will use are knotvector_u
, knotvector_v
and knotvector_w
.
For setting up the control points, please refer to the control points manager documentation.
Please refer to the Examples Repository for volume examples.
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 spline geometries into supported formats (docs)
 Compatibility module for control points conversion (docs)
 Surface grid generators (info and docs)
 Geometry containers (docs)
 Automatic uniform knot vector generation via
knotvector.generate()
 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.
Loading and Saving DataÂ¶
NURBSPython provides the following API calls for exporting and importing spline geometry data:
JSON import/export works with all spline geometry and container objects. Please refer to File Formats for more details.
The following code snippet illustrates a Bspline curve generation and its JSON export:
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))
# Export the curve as a JSON file
exchange.export_json(curve, "curve.json")

The following code snippet illustrates importing from a JSON file and adding the result to a container object:
1 2 3 4 5 6 7 8  from geomdl import multi
from geomdl import exchange
# Import curve from a JSON file
curve_list = exchange.import_json("curve.json")
# Add curve list to the container
curve_container = multi.CurveContainer(curve_list)

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 28 29 30  shape:
type: curve # type of the geometry
count: 1 # number of curves in "data" list (optional)
data:
 rational: True # rational or nonrational (optional)
dimension: 2 # spatial dimension of the curve (optional)
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 (required if rational)
 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 example 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  shape:
type: surface # type of the geometry
count: 1 # number of surfaces in "data" list (optional)
data:
 rational: True # rational or nonrational (optional)
dimension: 3 # spatial dimension of the surface (optional)
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 (required if rational)
 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
trims: # define trim curves (optional)
count: 3 # number of trims in the "data" list (optional)
data:
 type: spline # type of the trim curve
rational: False # rational or nonrational (optional)
dimension: 2 # spatial dimension of the trim curve (optional)
degree: 2 # degree of the 1st trim
knotvector: [ ... ] # knot vector of the 1st trim curve
control_points:
points: # parametric coordinates of the 1st trim curve
 [u1, v1] # expected to be 2dimensional, corresponding to (u,v)
 [u2, v2]
 ...
reversed: 0 # 0: trim inside, 1: trim outside (optional, default is 0)
 type: spline # type of the 2nd trim curve
rational: True # rational or nonrational (optional)
dimension: 2 # spatial dimension of the trim curve (optional)
degree: 1 # degree of the 2nd trim
knotvector: [ ... ] # knot vector of the 2nd trim curve
control_points:
points: # parametric coordinates of the 2nd trim curve
 [u1, v1] # expected to be 2dimensional, corresponding to (u,v)
 [u2, v2]
 ...
weights: # weights vector of the 2nd trim curve (required if rational)
 1.0
 1.0
 ...
delta: 0.01 # evaluation delta (optional)
reversed: 1 # 0: trim inside, 1: trim outside (optional, default is 0)
 type: freeform # type of the 3rd trim curve
dimension: 2 # spatial dimension of the trim curve (optional)
points: # parametric coordinates of the 3rd trim curve
 [u1, v1] # expected to be 2dimensional, corresponding to (u,v)
 [u2, v2]
 ...
name: "my freeform curve" # optional
reversed: 1 # 0: trim inside, 1: trim outside (optional, default is 0)
 type: container # type of the 4th trim curve
dimension: 2 # spatial dimension of the trim curve (optional)
data: # a list of freeform and/or spline geometries
 ...
 ...
name: "my trim curves" # optional
reversed: 1 # 0: trim inside, 1: trim outside (optional, default is 0)

 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.
Surfaces can also contain trim curves. These curves can be stored in 2 geometry types inside the surface:
spline
corresponds to a spline geometry, which is defined by a set of degrees, knot vectors and control pointscontainer
corresponds to a geometry containerfreeform
corresponds to a freeform geometry; defined by a set of points
VolumeÂ¶
The following example illustrates a Bspline volume:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  shape:
type: volume # type of the geometry
count: 1 # number of volumes in "data" list (optional)
data:
 rational: False # rational or nonrational (optional)
degree_u: 1 # degree of the udirection
degree_v: 2 # degree of the vdirection
degree_w: 1 # degree of the wdirection
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]
knotvector_w: [0.0, 0.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
size_w: 2 # number of control points on the wdirection
control_points:
points: # cartesian coordinates (x, y, z) of the control points
 [x1, y1, x1] # each control point is defined as a list
 [x2, y2, z2]
 ...
delta:
 0.25 # evaluation delta of the udirection
 0.25 # evaluation delta of the vdirection
 0.10 # evaluation delta of the wdirection

The file organization is very similar to the surface example. The main difference is the parametric 3rd dimension, w
.
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
customized 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 the surfaces.
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  from geomdl import CPGen
from geomdl import BSpline
from geomdl import utilities
from geomdl.visualization import VisMPL
from matplotlib import cm
# Generate a plane with the dimensions 50x100
surfgrid = CPGen.Grid(50, 100)
# Generate a grid of 25x30
surfgrid.generate(50, 60)
# Generate bumps on the grid
surfgrid.bumps(num_bumps=5, bump_height=20, base_extent=8)
# 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 = 100
# Set visualization component
surf.vis = VisMPL.VisSurface(ctrlpts=False, legend=False)
# Plot the surface
surf.render(colormap=cm.terrain)

(Source code, png, hires.png, pdf)
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.
Knot RefinementÂ¶
New in version 5.1.
Knot refinement is simply the operation of inserting multiple knots at the same time. NURBSPython (geomdl) supports
knot refinement operation for the curves, surfaces and volumes via operations.refine_knotvector()
function.
One of the interesting features of the operations.refine_knotvector()
function is the controlling of
knot refinement density. It can increase the number of knots to be inserted in a knot vector. Therefore, it
increases the number of control points.
The following code snippet and the figure illustrate a 2dimensional spline curve with knot refinement:
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  from geomdl import BSpline
from geomdl import utilities
from geomdl import exchange
from geomdl.visualization import VisMPL
# Create a curve instance
curve = BSpline.Curve()
# Set degree
curve.degree = 4
# Set control points
curve.ctrlpts = [
[5.0, 10.0], [15.0, 25.0], [30.0, 30.0], [45.0, 5.0], [55.0, 5.0],
[70.0, 40.0], [60.0, 60.0], [35.0, 60.0], [20.0, 40.0]
]
# Set knot vector
curve.knotvector = [0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.0, 1.0, 1.0, 1.0]
# Set visualization component
curve.vis = VisMPL.VisCurve2D()
# Refine knot vector
operations.refine_knotvector(curve, [1])
# Visualize
curve.render()

(Source code, png, hires.png, pdf)
The default density
value is 1 for the knot refinement operation. The following code snippet and the figure
illustrate the result of the knot refinement operation if density
is set to 2.
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  from geomdl import BSpline
from geomdl import utilities
from geomdl import exchange
from geomdl.visualization import VisMPL
# Create a curve instance
curve = BSpline.Curve()
# Set degree
curve.degree = 4
# Set control points
curve.ctrlpts = [
[5.0, 10.0], [15.0, 25.0], [30.0, 30.0], [45.0, 5.0], [55.0, 5.0],
[70.0, 40.0], [60.0, 60.0], [35.0, 60.0], [20.0, 40.0]
]
# Set knot vector
curve.knotvector = [0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.0, 1.0, 1.0, 1.0]
# Set visualization component
curve.vis = VisMPL.VisCurve2D()
# Refine knot vector
operations.refine_knotvector(curve, [2])
# Visualize
curve.render()

(Source code, png, hires.png, pdf)
The following code snippet and the figure illustrate the result of the knot refinement operation if density
is set
to 3.
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  from geomdl import BSpline
from geomdl import utilities
from geomdl import exchange
from geomdl.visualization import VisMPL
# Create a curve instance
curve = BSpline.Curve()
# Set degree
curve.degree = 4
# Set control points
curve.ctrlpts = [
[5.0, 10.0], [15.0, 25.0], [30.0, 30.0], [45.0, 5.0], [55.0, 5.0],
[70.0, 40.0], [60.0, 60.0], [35.0, 60.0], [20.0, 40.0]
]
# Set knot vector
curve.knotvector = [0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.0, 1.0, 1.0, 1.0]
# Set visualization component
curve.vis = VisMPL.VisCurve2D()
# Refine knot vector
operations.refine_knotvector(curve, [3])
# Visualize
curve.render()

(Source code, png, hires.png, pdf)
The following code snippet and the figure illustrate the knot refinement operation applied to a surface with density
value of 3 for the udirection. No refinement was applied for the vdirection.
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  from geomdl import NURBS
from geomdl import operations
from geomdl.visualization import VisMPL
# Control points
ctrlpts = [[[25.0, 25.0, 0.0, 1.0], [15.0, 25.0, 0.0, 1.0], [5.0, 25.0, 0.0, 1.0],
[5.0, 25.0, 0.0, 1.0], [15.0, 25.0, 0.0, 1.0], [25.0, 25.0, 0.0, 1.0]],
[[25.0, 15.0, 0.0, 1.0], [15.0, 15.0, 0.0, 1.0], [5.0, 15.0, 0.0, 1.0],
[5.0, 15.0, 0.0, 1.0], [15.0, 15.0, 0.0, 1.0], [25.0, 15.0, 0.0, 1.0]],
[[25.0, 5.0, 5.0, 1.0], [15.0, 5.0, 5.0, 1.0], [5.0, 5.0, 5.0, 1.0],
[5.0, 5.0, 5.0, 1.0], [15.0, 5.0, 5.0, 1.0], [25.0, 5.0, 5.0, 1.0]],
[[25.0, 5.0, 5.0, 1.0], [15.0, 5.0, 5.0, 1.0], [5.0, 5.0, 5.0, 1.0],
[5.0, 5.0, 5.0, 1.0], [15.0, 5.0, 5.0, 1.0], [25.0, 5.0, 5.0, 1.0]],
[[25.0, 15.0, 0.0, 1.0], [15.0, 15.0, 0.0, 1.0], [5.0, 15.0, 5.0, 1.0],
[5.0, 15.0, 5.0, 1.0], [15.0, 15.0, 0.0, 1.0], [25.0, 15.0, 0.0, 1.0]],
[[25.0, 25.0, 0.0, 1.0], [15.0, 25.0, 0.0, 1.0], [5.0, 25.0, 5.0, 1.0],
[5.0, 25.0, 5.0, 1.0], [15.0, 25.0, 0.0, 1.0], [25.0, 25.0, 0.0, 1.0]]]
# Generate surface
surf = NURBS.Surface()
surf.degree_u = 3
surf.degree_v = 3
surf.ctrlpts2d = ctrlpts
surf.knotvector_u = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0]
surf.knotvector_v = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0]
surf.sample_size = 30
# Set visualization component
surf.vis = VisMPL.VisSurface(VisMPL.VisConfig(alpha=0.75))
# Refine knot vectors
operations.refine_knotvector(surf, [3, 0])
# Visualize
surf.render()

(Source code, png, hires.png, pdf)
Curve & Surface FittingÂ¶
geomdl
includes 2 fitting methods for curves and surfaces: approximation and interpolation. Please refer to the
Curve and Surface Fitting page for more details on the curve and surface fitting API.
The following sections explain 2dimensional curve fitting using the included fitting methods. geomdl
also supports
3dimensional curve and surface fitting (not shown here). Please refer to the Examples Repository for more examples on
curve and surface fitting.
InterpolationÂ¶
The following code snippet and the figure illustrate interpolation for a 2dimensional curve:
1 2 3 4 5 6 7 8 9 10 11 12 13 14  from geomdl import fitting
from geomdl.visualization import VisMPL as vis
# The NURBS Book Ex9.1
points = ((0, 0), (3, 4), (1, 4), (4, 0), (4, 3))
degree = 3 # cubic curve
# Do global curve interpolation
curve = fitting.interpolate_curve(points, degree)
# Plot the interpolated curve
curve.delta = 0.01
curve.vis = vis.VisCurve2D()
curve.render()

(Source code, png, hires.png, pdf)
The following figure displays the input data (sample) points in red and the evaluated curve after interpolation in blue:
(Source code, png, hires.png, pdf)
ApproximationÂ¶
The following code snippet and the figure illustrate approximation method for a 2dimensional curve:
1 2 3 4 5 6 7 8 9 10 11 12 13 14  from geomdl import fitting
from geomdl.visualization import VisMPL as vis
# The NURBS Book Ex9.1
points = ((0, 0), (3, 4), (1, 4), (4, 0), (4, 3))
degree = 3 # cubic curve
# Do global curve approximation
curve = fitting.approximate_curve(points, degree)
# Plot the interpolated curve
curve.delta = 0.01
curve.vis = vis.VisCurve2D()
curve.render()

(Source code, png, hires.png, pdf)
The following figure displays the input data (sample) points in red and the evaluated curve after approximation in blue:
(Source code, png, hires.png, pdf)
Please note that a spline geometry with a constant set of evaluated points may be represented with an infinite set of control points. The number and positions of the control points depend on the application and the method used to generate the control points.
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 decomposition 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 are the lists of modules included in NURBSPython (geomdl) Core Library. They are split into separate groups to make the documentation more understandable.
User APIÂ¶
The User API is the main entrance point to the library. It provides geometry classes and containers, as well as the geometric operators and support modules.
The following is the list of the geometry classes included in the library:
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:
type
= splineid
order
degree
knotvector
ctrlpts
delta
sample_size
bbox
vis
name
dimension
evaluator
rational
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 control 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 (controls the number of curve points) curve.delta = 0.05 # Get curve points (the curve will be automatically evaluated) curve_points = curve.evalpts
Keyword Arguments:
precision
: number of decimal places to round to. Default: 18normalize_kv
: activates knot vector normalization. Default: Truefind_span_func
: sets knot span search implementation. Default:helpers.find_span_linear()
insert_knot_func
: sets knot insertion implementation. Default:operations.insert_knot()
remove_knot_func
: sets knot removal implementation. Default:operations.remove_knot()
Please refer to the
abstract.Curve()
documentation for more details.
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).
Parameters: parpos (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: binormal vector as a tuple of the origin point and the vector components Return type: tuple

cpsize
Â¶ Number of control points in all parametric directions.
Note
This is an expert property for getting and setting control point size(s) of the geometry.
Please refer to the wiki for details on using this class member.
Getter: Gets the number of control points Setter: Sets the number of control points Type: list

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 dict which contains the geometry 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.
The output of this method is list of nth order derivatives. If
order
is0
, then it will only output the evaluated point. Similarly, iforder
is2
, then it will output the evaluated point, 1st derivative and the 2nd derivative. For instance;# Assuming a curve (crv) is defined on a parametric domain [0.0, 1.0] # Let's take the curve derivative at the parametric position u = 0.35 ders = crv.derivatives(u=0.35, order=2) ders[0] # evaluated point, equal to crv.evaluate_single(0.35) ders[1] # 1st derivative at u = 0.35 ders[2] @ 2nd derivative at u = 0.35
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 points are stored in
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

id
Â¶ Object ID (as an integer).
Please refer to the wiki for details on using this class member.
Getter: Gets the object ID Setter: Sets the object ID Type: int

insert_knot
(param, **kwargs)Â¶ Inserts the knot and updates the control points array and the knot vector.
 Keyword Arguments:
num
: Number of knot insertions. Default: 1
Parameters: param (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.
Deprecated since version 5.2.4: Use
exchange.import_json()
instead.Parameters: file_name (str) â€“ name of the file to be loaded

name
Â¶ Object name (as a string)
Please refer to the wiki for details on using this class member.
Getter: Gets the object name Setter: Sets the object name Type: str

normal
(parpos, **kwargs)Â¶ Evaluates the normal to the tangent vector of the curve at the given parametric position(s).
Parameters: parpos (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: normal vector as a tuple of the origin point and the vector components Return type: tuple

opt
Â¶ Dictionary for storing custom data in the current geometry object.
opt
is a wrapper to a dict in key => value format, where key is string, value is any Python object. You can useopt
property to store custom data inside the geometry object. For instance:geom.opt = ["face_id", 4] # creates "face_id" key and sets its value to an integer geom.opt = ["contents", "data values"] # creates "face_id" key and sets its value to a string print(geom.opt) # will print: {'face_id': 4, 'contents': 'data values'} del geom.opt # deletes the contents of the hash map print(geom.opt) # will print: {} geom.opt = ["body_id", 1] # creates "body_id" key and sets its value to 1 geom.opt = ["body_id", 12] # changes the value of "body_id" to 12 print(geom.opt) # will print: {'body_id': 12} geom.opt = ["body_id", None] # deletes "body_id" print(geom.opt) # will print: {}
Please refer to the wiki for details on using this class member.
Getter: Gets the dict Setter: Adds key and value pair to the dict Deleter: Deletes the contents of the dict

opt_get
(value)Â¶ Safely query for the value from the
opt
property.Parameters: value (str) â€“ a key in the opt
propertyReturns: the corresponding value, if the key exists. None
, otherwise.

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

remove_knot
(param, **kwargs)Â¶ Removes the knot and updates the control points array and the knot vector.
 Keyword Arguments:
num
: Number of knot removals. Default: 1
Parameters: param (float) â€“ knot to be removed

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 ) ]
Returns: the figure object

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

reverse
()Â¶ Reverses the curve

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.
Deprecated since version 5.2.4: Use
exchange.export_json()
instead.Parameters: file_name (str) â€“ name of the file to be saved

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
(parpos, **kwargs)Â¶ Evaluates the tangent vector of the curve at the given parametric position(s).
Parameters: parpos (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: tangent vector as a tuple of the origin point and the vector components Return type: tuple

type
Â¶ Geometry type
Please refer to the wiki for details on using this class member.
Getter: Gets the geometry type Type: str
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:
type
= splineid
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
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
Keyword Arguments:
precision
: number of decimal places to round to. Default: 18normalize_kv
: activates knot vector normalization. Default: Truefind_span_func
: sets knot span search implementation. Default:helpers.find_span_linear()
insert_knot_func
: sets knot insertion implementation. Default:operations.insert_knot()
remove_knot_func
: sets knot removal implementation. Default:operations.remove_knot()
Please refer to the
abstract.Surface()
documentation for more details.
add_trim
(trim)Â¶ Adds a trim to the surface.
A trim is a 2dimensional curve defined on the parametric domain of the surface. Therefore, xcoordinate of the trimming curve corresponds to u parametric direction of the surfaceand ycoordinate of the trimming curve corresponds to v parametric direction of the surface.
trims
uses this method to add trims to the surface.Parameters: trim (abstract.Geometry) â€“ surface trimming curve

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

cpsize
Â¶ Number of control points in all parametric directions.
Note
This is an expert property for getting and setting control point size(s) of the geometry.
Please refer to the wiki for details on using this class member.
Getter: Gets the number of control points Setter: Sets the number of control points Type: list

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 dict which contains the geometry 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 points are stored in
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

faces
Â¶ Faces (triangles, quads, etc.) generated by the tessellation operation.
If the tessellation component is set to None, the result will be an empty list.
Getter: Gets the faces

id
Â¶ Object ID (as an integer).
Please refer to the wiki for details on using this class member.
Getter: Gets the object ID Setter: Sets the object ID Type: int

insert_knot
(u=None, v=None, **kwargs)Â¶ Inserts knot(s) on the u or vdirections
 Keyword Arguments:
num_u
: Number of knot insertions on the udirection. Default: 1num_v
: 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.
Deprecated since version 5.2.4: Use
exchange.import_json()
instead.Parameters: file_name (str) â€“ name of the file to be loaded

name
Â¶ Object name (as a string)
Please refer to the wiki for details on using this class member.
Getter: Gets the object name Setter: Sets the object name Type: str

normal
(parpos, **kwargs)Â¶ Evaluates the normal vector of the surface at the given parametric position(s).
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

opt
Â¶ Dictionary for storing custom data in the current geometry object.
opt
is a wrapper to a dict in key => value format, where key is string, value is any Python object. You can useopt
property to store custom data inside the geometry object. For instance:geom.opt = ["face_id", 4] # creates "face_id" key and sets its value to an integer geom.opt = ["contents", "data values"] # creates "face_id" key and sets its value to a string print(geom.opt) # will print: {'face_id': 4, 'contents': 'data values'} del geom.opt # deletes the contents of the hash map print(geom.opt) # will print: {} geom.opt = ["body_id", 1] # creates "body_id" key and sets its value to 1 geom.opt = ["body_id", 12] # changes the value of "body_id" to 12 print(geom.opt) # will print: {'body_id': 12} geom.opt = ["body_id", None] # deletes "body_id" print(geom.opt) # will print: {}
Please refer to the wiki for details on using this class member.
Getter: Gets the dict Setter: Adds key and value pair to the dict Deleter: Deletes the contents of the dict

opt_get
(value)Â¶ Safely query for the value from the
opt
property.Parameters: value (str) â€“ a key in the opt
propertyReturns: the corresponding value, if the key exists. None
, otherwise.

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

remove_knot
(u=None, v=None, **kwargs)Â¶ Inserts knot(s) on the u or vdirections
 Keyword Arguments:
num_u
: Number of knot removals on the udirection. Default: 1num_v
: Number of knot removals on the vdirection. Default: 1
Parameters:  u (float) â€“ knot to be removed on the udirection
 v (float) â€“ knot to be removed on the vdirection

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.Returns: the figure object

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.
Deprecated since version 5.2.4: Use
exchange.export_json()
instead.Parameters: file_name (str) â€“ name of the file to be saved

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).
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
Â¶ Curves for trimming the surface.
Surface trims are 2dimensional curves which are introduced on the parametric space of the surfaces. Trim curves can be a spline curve, an analytic curve or a 2dimensional freeform shape. To visualize the trimmed surfaces, you need to use a tessellator that supports trimming. The following code snippet illustrates changing the default surface tessellator to the trimmed surface tessellator,
tessellate.TrimTessellate
.1 2 3 4
from geomdl import tessellate # Assuming that "surf" variable stores the surface instance surf.tessellator = tessellate.TrimTessellate()
In addition, using trims initialization argument of the visualization classes, trim curves can be visualized together with their underlying surfaces. Please refer to the visualization configuration class initialization arguments for more details.
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

type
Â¶ Geometry type
Please refer to the wiki for details on using this class member.
Getter: Gets the geometry type Type: str

vertices
Â¶ Vertices generated by the tessellation operation.
If the tessellation component is set to None, the result will be an empty list.
Getter: Gets the vertices
BSpline VolumeÂ¶
New in version 5.0.

class
geomdl.BSpline.
Volume
(**kwargs)Â¶ Bases:
geomdl.abstract.Volume
Data storage and evaluation class for Bspline (nonrational) volumes.
This class provides the following properties:
type
= splineid
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
Keyword Arguments:
precision
: number of decimal places to round to. Default: 18normalize_kv
: activates knot vector normalization. Default: Truefind_span_func
: sets knot span search implementation. Default:helpers.find_span_linear()
insert_knot_func
: sets knot insertion implementation. Default:operations.insert_knot()
remove_knot_func
: sets knot removal implementation. Default:operations.remove_knot()
Please refer to the
abstract.Volume()
documentation for more details.
add_trim
(trim)Â¶ Adds a trim to the volume.
trims
uses this method to add trims to the volume.Parameters: trim (abstract.Surface) â€“ trimming surface

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

cpsize
Â¶ Number of control points in all parametric directions.
Note
This is an expert property for getting and setting control point size(s) of the geometry.
Please refer to the wiki for details on using this class member.
Getter: Gets the number of control points Setter: Sets the number of control points Type: list

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 dict which contains the geometry 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
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

id
Â¶ Object ID (as an integer).
Please refer to the wiki for details on using this class member.
Getter: Gets the object ID Setter: Sets the object ID Type: int

insert_knot
(u=None, v=None, w=None, **kwargs)Â¶ Inserts knot(s) on the u, v and wdirections
 Keyword Arguments:
num_u
: Number of knot insertions on the udirection. Default: 1num_v
: Number of knot insertions on the vdirection. Default: 1num_w
: Number of knot insertions on the wdirection. Default: 1
Parameters:  u (float) â€“ knot to be inserted on the udirection
 v (float) â€“ knot to be inserted on the vdirection
 w (float) â€“ knot to be inserted on the wdirection

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.
Deprecated since version 5.2.4: Use
exchange.import_json()
instead.Parameters: file_name (str) â€“ name of the file to be loaded

name
Â¶ Object name (as a string)
Please refer to the wiki for details on using this class member.
Getter: Gets the object name Setter: Sets the object name Type: str

opt
Â¶ Dictionary for storing custom data in the current geometry object.
opt
is a wrapper to a dict in key => value format, where key is string, value is any Python object. You can useopt
property to store custom data inside the geometry object. For instance:geom.opt = ["face_id", 4] # creates "face_id" key and sets its value to an integer geom.opt = ["contents", "data values"] # creates "face_id" key and sets its value to a string print(geom.opt) # will print: {'face_id': 4, 'contents': 'data values'} del geom.opt # deletes the contents of the hash map print(geom.opt) # will print: {} geom.opt = ["body_id", 1] # creates "body_id" key and sets its value to 1 geom.opt = ["body_id", 12] # changes the value of "body_id" to 12 print(geom.opt) # will print: {'body_id': 12} geom.opt = ["body_id", None] # deletes "body_id" print(geom.opt) # will print: {}
Please refer to the wiki for details on using this class member.
Getter: Gets the dict Setter: Adds key and value pair to the dict Deleter: Deletes the contents of the dict

opt_get
(value)Â¶ Safely query for the value from the
opt
property.Parameters: value (str) â€“ a key in the opt
propertyReturns: the corresponding value, if the key exists. None
, otherwise.

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

remove_knot
(u=None, v=None, w=None, **kwargs)Â¶ Inserts knot(s) on the u, v and wdirections
 Keyword Arguments:
num_u
: Number of knot removals on the udirection. Default: 1num_v
: Number of knot removals on the vdirection. Default: 1num_w
: Number of knot removals on the wdirection. Default: 1
Parameters:  u (float) â€“ knot to be removed on the udirection
 v (float) â€“ knot to be removed on the vdirection
 w (float) â€“ knot to be removed on the wdirection

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: (8, 8, 8)use_cubes
: use cube voxels instead of cuboid ones. Default: Falsenum_procs
: number of concurrent processes for voxelization. Default: 1
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 ) ]
Returns: the figure object

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.
Deprecated since version 5.2.4: Use
exchange.export_json()
instead.Parameters: file_name (str) â€“ name of the file to be saved

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

trims
Â¶ Trimming surfaces.
Please refer to the wiki for details on using this class member.
Getter: Gets the array of trim surfaces Setter: Sets the array of trim surfaces

type
Â¶ Geometry type
Please refer to the wiki for details on using this class member.
Getter: Gets the geometry type Type: str
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
The following code segment illustrates the usage of Curve class:
from geomdl import NURBS # Create a 3dimensional Bspline Curve curve = NURBS.Curve() # Set degree curve.degree = 3 # Set control points (weights vector will be 1 by default) # Use curve.ctrlptsw is if you are using homogeneous points as Pw 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 (controls the number of curve points) curve.delta = 0.05 # Get curve points (the curve will be automatically evaluated) curve_points = curve.evalpts
Keyword Arguments:
precision
: number of decimal places to round to. Default: 18normalize_kv
: activates knot vector normalization. Default: Truefind_span_func
: sets knot span search implementation. Default:helpers.find_span_linear()
insert_knot_func
: sets knot insertion implementation. Default:operations.insert_knot()
remove_knot_func
: sets knot removal implementation. Default:operations.remove_knot()
Please refer to the
abstract.Curve()
documentation for more details.
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).
Parameters: parpos (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: binormal vector as a tuple of the origin point and the vector components Return type: tuple

cpsize
Â¶ Number of control points in all parametric directions.
Note
This is an expert property for getting and setting control point size(s) of the geometry.
Please refer to the wiki for details on using this class member.
Getter: Gets the number of control points Setter: Sets the number of control points Type: list

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 dict which contains the geometry 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.
The output of this method is list of nth order derivatives. If
order
is0
, then it will only output the evaluated point. Similarly, iforder
is2
, then it will output the evaluated point, 1st derivative and the 2nd derivative. For instance;# Assuming a curve (crv) is defined on a parametric domain [0.0, 1.0] # Let's take the curve derivative at the parametric position u = 0.35 ders = crv.derivatives(u=0.35, order=2) ders[0] # evaluated point, equal to crv.evaluate_single(0.35) ders[1] # 1st derivative at u = 0.35 ders[2] @ 2nd derivative at u = 0.35
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 points are stored in
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

id
Â¶ Object ID (as an integer).
Please refer to the wiki for details on using this class member.
Getter: Gets the object ID Setter: Sets the object ID Type: int

insert_knot
(param, **kwargs)Â¶ Inserts the knot and updates the control points array and the knot vector.
 Keyword Arguments:
num
: Number of knot insertions. Default: 1
Parameters: param (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.
Deprecated since version 5.2.4: Use
exchange.import_json()
instead.Parameters: file_name (str) â€“ name of the file to be loaded

name
Â¶ Object name (as a string)
Please refer to the wiki for details on using this class member.
Getter: Gets the object name Setter: Sets the object name Type: str

normal
(parpos, **kwargs)Â¶ Evaluates the normal to the tangent vector of the curve at the given parametric position(s).
Parameters: parpos (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: normal vector as a tuple of the origin point and the vector components Return type: tuple

opt
Â¶ Dictionary for storing custom data in the current geometry object.
opt
is a wrapper to a dict in key => value format, where key is string, value is any Python object. You can useopt
property to store custom data inside the geometry object. For instance:geom.opt = ["face_id", 4] # creates "face_id" key and sets its value to an integer geom.opt = ["contents", "data values"] # creates "face_id" key and sets its value to a string print(geom.opt) # will print: {'face_id': 4, 'contents': 'data values'} del geom.opt # deletes the contents of the hash map print(geom.opt) # will print: {} geom.opt = ["body_id", 1] # creates "body_id" key and sets its value to 1 geom.opt = ["body_id", 12] # changes the value of "body_id" to 12 print(geom.opt) # will print: {'body_id': 12} geom.opt = ["body_id", None] # deletes "body_id" print(geom.opt) # will print: {}
Please refer to the wiki for details on using this class member.
Getter: Gets the dict Setter: Adds key and value pair to the dict Deleter: Deletes the contents of the dict

opt_get
(value)Â¶ Safely query for the value from the
opt
property.Parameters: value (str) â€“ a key in the opt
propertyReturns: the corresponding value, if the key exists. None
, otherwise.

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

remove_knot
(param, **kwargs)Â¶ Removes the knot and updates the control points array and the knot vector.
 Keyword Arguments:
num
: Number of knot removals. Default: 1
Parameters: param (float) â€“ knot to be removed

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 ) ]
Returns: the figure object

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

reverse
()Â¶ Reverses the curve

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.
Deprecated since version 5.2.4: Use
exchange.export_json()
instead.Parameters: file_name (str) â€“ name of the file to be saved

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
(parpos, **kwargs)Â¶ Evaluates the tangent vector of the curve at the given parametric position(s).
Parameters: parpos (float, list or tuple) â€“ parametric position(s) where the evaluation will be executed Returns: tangent vector as a tuple of the origin point and the vector components Return type: tuple

type
Â¶ Geometry type
Please refer to the wiki for details on using this class member.
Getter: Gets the geometry type Type: str
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
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 26
from geomdl import NURBS # Create a NURBS surface instance surf = NURBS.Surface() # Set degrees surf.degree_u = 3 surf.degree_v = 2 # Set control points (weights vector will be 1 by default) # Use curve.ctrlptsw is if you are using homogeneous points as Pw control_points = [[0, 0, 0], [0, 4, 0], [0, 8, 3], [2, 0, 6], [2, 4, 0], [2, 8, 0], [4, 0, 0], [4, 4, 0], [4, 8, 3], [6, 0, 0], [6, 4, 3], [6, 8, 0]] surf.set_ctrlpts(control_points, 4, 3) # Set knot vectors surf.knotvector_u = [0, 0, 0, 0, 1, 1, 1, 1] surf.knotvector_v = [0, 0, 0, 1, 1, 1] # Set evaluation delta (control the number of surface points) surf.delta = 0.05 # Get surface points (the surface will be automatically evaluated) surface_points = surf.evalpts
Keyword Arguments:
precision
: number of decimal places to round to. Default: 18normalize_kv
: activates knot vector normalization. Default: Truefind_span_func
: sets knot span search implementation. Default:helpers.find_span_linear()
insert_knot_func
: sets knot insertion implementation. Default:operations.insert_knot()
remove_knot_func
: sets knot removal implementation. Default:operations.remove_knot()
Please refer to the
abstract.Surface()
documentation for more details.
add_trim
(trim)Â¶ Adds a trim to the surface.
A trim is a 2dimensional curve defined on the parametric domain of the surface. Therefore, xcoordinate of the trimming curve corresponds to u parametric direction of the surfaceand ycoordinate of the trimming curve corresponds to v parametric direction of the surface.
trims
uses this method to add trims to the surface.Parameters: trim (abstract.Geometry) â€“ surface trimming curve

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

cpsize
Â¶ Number of control points in all parametric directions.
Note
This is an expert property for getting and setting control point size(s) of the geometry.
Please refer to the wiki for details on using this class member.
Getter: Gets the number of control points Setter: Sets the number of control points Type: list

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 dict which contains the geometry 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 points are stored in
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

faces
Â¶ Faces (triangles, quads, etc.) generated by the tessellation operation.
If the tessellation component is set to None, the result will be an empty list.
Getter: Gets the faces

id
Â¶ Object ID (as an integer).
Please refer to the wiki for details on using this class member.
Getter: Gets the object ID Setter: Sets the object ID Type: int

insert_knot
(u=None, v=None, **kwargs)Â¶ Inserts knot(s) on the u or vdirections
 Keyword Arguments:
num_u
: Number of knot insertions on the udirection. Default: 1num_v
: 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.
Deprecated since version 5.2.4: Use
exchange.import_json()
instead.Parameters: file_name (str) â€“ name of the file to be loaded

name
Â¶ Object name (as a string)
Please refer to the wiki for details on using this class member.
Getter: Gets the object name Setter: Sets the object name Type: str

normal
(parpos, **kwargs)Â¶ Evaluates the normal vector of the surface at the given parametric position(s).
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

opt
Â¶ Dictionary for storing custom data in the current geometry object.
opt
is a wrapper to a dict in key => value format, where key is string, value is any Python object. You can useopt
property to store custom data inside the geometry object. For instance:geom.opt = ["face_id", 4] # creates "face_id" key and sets its value to an integer geom.opt = ["contents", "data values"] # creates "face_id" key and sets its value to a string print(geom.opt) # will print: {'face_id': 4, 'contents': 'data values'} del geom.opt # deletes the contents of the hash map print(geom.opt) # will print: {} geom.opt = ["body_id", 1] # creates "body_id" key and sets its value to 1 geom.opt = ["body_id", 12] # changes the value of "body_id" to 12 print(geom.opt) # will print: {'body_id': 12} geom.opt = ["body_id", None] # deletes "body_id" print(geom.opt) # will print: {}
Please refer to the wiki for details on using this class member.
Getter: Gets the dict Setter: Adds key and value pair to the dict Deleter: Deletes the contents of the dict

opt_get
(value)Â¶ Safely query for the value from the
opt
property.Parameters: value (str) â€“ a key in the opt
propertyReturns: the corresponding value, if the key exists. None
, otherwise.

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

remove_knot
(u=None, v=None, **kwargs)Â¶ Inserts knot(s) on the u or vdirections
 Keyword Arguments:
num_u
: Number of knot removals on the udirection. Default: 1num_v
: Number of knot removals on the vdirection. Default: 1
Parameters:  u (float) â€“ knot to be removed on the udirection
 v (float) â€“ knot to be removed on the vdirection

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.Returns: the figure object

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.
Deprecated since version 5.2.4: Use
exchange.export_json()
instead.Parameters: file_name (str) â€“ name of the file to be saved

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).
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
Â¶ Curves for trimming the surface.
Surface trims are 2dimensional curves which are introduced on the parametric space of the surfaces. Trim curves can be a spline curve, an analytic curve or a 2dimensional freeform shape. To visualize the trimmed surfaces, you need to use a tessellator that supports trimming. The following code snippet illustrates changing the default surface tessellator to the trimmed surface tessellator,
tessellate.TrimTessellate
.1 2 3 4
from geomdl import tessellate # Assuming that "surf" variable stores the surface instance surf.tessellator = tessellate.TrimTessellate()
In addition, using trims initialization argument of the visualization classes, trim curves can be visualized together with their underlying surfaces. Please refer to the visualization configuration class initialization arguments for more details.
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

type
Â¶ Geometry type
Please refer to the wiki for details on using this class member.
Getter: Gets the geometry type Type: str

vertices
Â¶ Vertices generated by the tessellation operation.
If the tessellation component is set to None, the result will be an empty list.
Getter: Gets the vertices

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Â¶
New in version 5.0.

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
Keyword Arguments:
precision
: number of decimal places to round to. Default: 18normalize_kv
: activates knot vector normalization. Default: Truefind_span_func
: sets knot span search implementation. Default:helpers.find_span_linear()
insert_knot_func
: sets knot insertion implementation. Default:operations.insert_knot()
remove_knot_func
: sets knot removal implementation. Default:operations.remove_knot()
Please refer to the
abstract.Volume()
documentation for more details.
add_trim
(trim)Â¶ Adds a trim to the volume.
trims
uses this method to add trims to the volume.Parameters: trim (abstract.Surface) â€“ trimming surface

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

cpsize
Â¶ Number of control points in all parametric directions.
Note
This is an expert property for getting and setting control point size(s) of the geometry.
Please refer to the wiki for details on using this class member.
Getter: Gets the number of control points Setter: Sets the number of control points Type: list

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 dict which contains the geometry 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
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

id
Â¶ Object ID (as an integer).
Please refer to the wiki for details on using this class member.
Getter: Gets the object ID Setter: Sets the object ID Type: int

insert_knot
(u=None, v=None, w=None, **kwargs)Â¶ Inserts knot(s) on the u, v and wdirections
 Keyword Arguments:
num_u
: Number of knot insertions on the udirection. Default: 1num_v
: Number of knot insertions on the vdirection. Default: 1num_w
: Number of knot insertions on the wdirection. Default: 1
Parameters:  u (float) â€“ knot to be inserted on the udirection
 v (float) â€“ knot to be inserted on the vdirection
 w (float) â€“ knot to be inserted on the wdirection

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.
Deprecated since version 5.2.4: Use
exchange.import_json()
instead.Parameters: file_name (str) â€“ name of the file to be loaded

name
Â¶ Object name (as a string)
Please refer to the wiki for details on using this class member.
Getter: Gets the object name Setter: Sets the object name Type: str

opt
Â¶ Dictionary for storing custom data in the current geometry object.
opt
is a wrapper to a dict in key => value format, where key is string, value is any Python object. You can useopt
property to store custom data inside the geometry object. For instance:geom.opt = ["face_id", 4] # creates "face_id" key and sets its value to an integer geom.opt = ["contents", "data values"] # creates "face_id" key and sets its value to a string print(geom.opt) # will print: {'face_id': 4, 'contents': 'data values'} del geom.opt # deletes the contents of the hash map print(geom.opt) # will print: {} geom.opt = ["body_id", 1] # creates "body_id" key and sets its value to 1 geom.opt = ["body_id", 12] # changes the value of "body_id" to 12 print(geom.opt) # will print: {'body_id': 12} geom.opt = ["body_id", None] # deletes "body_id" print(geom.opt) # will print: {}
Please refer to the wiki for details on using this class member.
Getter: Gets the dict Setter: Adds key and value pair to the dict Deleter: Deletes the contents of the dict

opt_get
(value)Â¶ Safely query for the value from the
opt
property.Parameters: value (str) â€“ a key in the opt
propertyReturns: the corresponding value, if the key exists. None
, otherwise.

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

remove_knot
(u=None, v=None, w=None, **kwargs)Â¶ Inserts knot(s) on the u, v and wdirections
 Keyword Arguments:
num_u
: Number of knot removals on the udirection. Default: 1num_v
: Number of knot removals on the vdirection. Default: 1num_w
: Number of knot removals on the wdirection. Default: 1
Parameters:  u (float) â€“ knot to be removed on the udirection
 v (float) â€“ knot to be removed on the vdirection
 w (float) â€“ knot to be removed on the wdirection

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: (8, 8, 8)use_cubes
: use cube voxels instead of cuboid ones. Default: Falsenum_procs
: number of concurrent processes for voxelization. Default: 1
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 ) ]
Returns: the figure object

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.
Deprecated since version 5.2.4: Use
exchange.export_json()
instead.Parameters: file_name (str) â€“ name of the file to be saved

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

trims
Â¶ Trimming surfaces.
Please refer to the wiki for details on using this class member.
Getter: Gets the array of trim surfaces Setter: Sets the array of trim surfaces

type
Â¶ Geometry type
Please refer to the wiki for details on using this class member.
Getter: Gets the geometry type Type: str

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
Freeform GeometryÂ¶
New in version 5.2.
freeform
module provides classes for representing freeform geometry objects.
Freeform class provides a basis for storing freeform geometries. The points of the geometry can be set via the evaluate() method using a keyword argument.
Inheritance DiagramÂ¶
Class ReferenceÂ¶

class
geomdl.freeform.
Freeform
(**kwargs)Â¶ Bases:
geomdl.abstract.Geometry
ndimensional freeform geometry

data
Â¶ Returns a dict which contains the geometry data.
Please refer to the wiki for details on using this class member.

dimension
Â¶ Spatial dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

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)Â¶ Sets points that form the geometry.
 Keyword Arguments:
points
: sets the points

id
Â¶ Object ID (as an integer).
Please refer to the wiki for details on using this class member.
Getter: Gets the object ID Setter: Sets the object ID Type: int

name
Â¶ Object name (as a string)
Please refer to the wiki for details on using this class member.
Getter: Gets the object name Setter: Sets the object name Type: str

opt
Â¶ Dictionary for storing custom data in the current geometry object.
opt
is a wrapper to a dict in key => value format, where key is string, value is any Python object. You can useopt
property to store custom data inside the geometry object. For instance:geom.opt = ["face_id", 4] # creates "face_id" key and sets its value to an integer geom.opt = ["contents", "data values"] # creates "face_id" key and sets its value to a string print(geom.opt) # will print: {'face_id': 4, 'contents': 'data values'} del geom.opt # deletes the contents of the hash map print(geom.opt) # will print: {} geom.opt = ["body_id", 1] # creates "body_id" key and sets its value to 1 geom.opt = ["body_id", 12] # changes the value of "body_id" to 12 print(geom.opt) # will print: {'body_id': 12} geom.opt = ["body_id", None] # deletes "body_id" print(geom.opt) # will print: {}
Please refer to the wiki for details on using this class member.
Getter: Gets the dict Setter: Adds key and value pair to the dict Deleter: Deletes the contents of the dict

Geometry ContainersÂ¶
The multi
module provides specialized geometry containers. 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
The multi
module contains the following classes:
AbstractContainer
abstract base class for containersCurveContainer
for storing multiple curvesSurfaceContainer
for storing multiple surfacesVolumeContainer
for storing multiple volumes
How to UseÂ¶
These containers can be used for many purposes, such as visualization of a multicomponent geometry or file export. For instance, the following figure shows a heart valve with 3 leaflets:
Each leaflet is a NURBS surface added to a SurfaceContainer
and rendered via Matplotlib visualization
module. It is possible to input a list of colors to the render
method, otherwise it will automatically pick an
arbitrary color.
Inheritance DiagramÂ¶
Abstract ContainerÂ¶

class
geomdl.multi.
AbstractContainer
(*args, **kwargs)Â¶ Bases:
geomdl.abstract.GeomdlBase
Abstract class for geometry 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 geometry objects to the container.
The input can be a single geometry, a list of geometry objects or a geometry container object.
Parameters: element â€“ geometry object

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

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

data
Â¶ Returns a dict which contains the geometry data.
Please refer to the wiki for details on using this class member.

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
Â¶ Spatial dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

evalpts
Â¶ Evaluated points.
Since there are multiple geometry objects 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 geometries 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 geometries

id
Â¶ Object ID (as an integer).
Please refer to the wiki for details on using this class member.
Getter: Gets the object ID Setter: Sets the object ID Type: int

name
Â¶ Object name (as a string)
Please refer to the wiki for details on using this class member.
Getter: Gets the object name Setter: Sets the object name Type: str

opt
Â¶ Dictionary for storing custom data in the current geometry object.
opt
is a wrapper to a dict in key => value format, where key is string, value is any Python object. You can useopt
property to store custom data inside the geometry object. For instance:geom.opt = ["face_id", 4] # creates "face_id" key and sets its value to an integer geom.opt = ["contents", "data values"] # creates "face_id" key and sets its value to a string print(geom.opt) # will print: {'face_id': 4, 'contents': 'data values'} del geom.opt # deletes the contents of the hash map print(geom.opt) # will print: {} geom.opt = ["body_id", 1] # creates "body_id" key and sets its value to 1 geom.opt = ["body_id", 12] # changes the value of "body_id" to 12 print(geom.opt) # will print: {'body_id': 12} geom.opt = ["body_id", None] # deletes "body_id" print(geom.opt) # will print: {}
Please refer to the wiki for details on using this class member.
Getter: Gets the dict Setter: Adds key and value pair to the dict Deleter: Deletes the contents of the dict

opt_get
(value)Â¶ Safely query for the value from the
opt
property.Parameters: value (str) â€“ a key in the opt
propertyReturns: the corresponding value, if the key exists. None
, otherwise.

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

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

reset
()Â¶ Resets the cache.

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 geometry objects to the container.
The input can be a single geometry, a list of geometry objects or a geometry container object.
Parameters: element â€“ geometry object

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

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

data
Â¶ Returns a dict which contains the geometry data.
Please refer to the wiki for details on using this class member.

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
Â¶ Spatial dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

evalpts
Â¶ Evaluated points.
Since there are multiple geometry objects 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 geometries 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 geometries

id
Â¶ Object ID (as an integer).
Please refer to the wiki for details on using this class member.
Getter: Gets the object ID Setter: Sets the object ID Type: int

name
Â¶ Object name (as a string)
Please refer to the wiki for details on using this class member.
Getter: Gets the object name Setter: Sets the object name Type: str

opt
Â¶ Dictionary for storing custom data in the current geometry object.
opt
is a wrapper to a dict in key => value format, where key is string, value is any Python object. You can useopt
property to store custom data inside the geometry object. For instance:geom.opt = ["face_id", 4] # creates "face_id" key and sets its value to an integer geom.opt = ["contents", "data values"] # creates "face_id" key and sets its value to a string print(geom.opt) # will print: {'face_id': 4, 'contents': 'data values'} del geom.opt # deletes the contents of the hash map print(geom.opt) # will print: {} geom.opt = ["body_id", 1] # creates "body_id" key and sets its value to 1 geom.opt = ["body_id", 12] # changes the value of "body_id" to 12 print(geom.opt) # will print: {'body_id': 12} geom.opt = ["body_id", None] # deletes "body_id" print(geom.opt) # will print: {}
Please refer to the wiki for details on using this class member.
Getter: Gets the dict Setter: Adds key and value pair to the dict Deleter: Deletes the contents of the dict

opt_get
(value)Â¶ Safely query for the value from the
opt
property.Parameters: value (str) â€“ a key in the opt
propertyReturns: the corresponding value, if the key exists. None
, otherwise.

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

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 container object will be used. Default: Truereset_names
: resets the name of the curves inside the container. Default: False
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.

reset
()Â¶ Resets the cache.

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:
type
= containerid
name
dimension
opt
pdimension
evalpts
bbox
vis
delta
delta_u
delta_v
sample_size
sample_size_u
sample_size_v
tessellator
vertices
faces
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 geometry objects to the container.
The input can be a single geometry, a list of geometry objects or a geometry container object.
Parameters: element â€“ geometry object

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

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

data
Â¶ Returns a dict which contains the geometry data.
Please refer to the wiki for details on using this class member.

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
Â¶ Spatial dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

evalpts
Â¶ Evaluated points.
Since there are multiple geometry objects 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 geometries 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 geometries

faces
Â¶ Faces (triangles, quads, etc.) generated by the tessellation operation.
If the tessellation component is set to None, the result will be an empty list.
Getter: Gets the faces

id
Â¶ Object ID (as an integer).
Please refer to the wiki for details on using this class member.
Getter: Gets the object ID Setter: Sets the object ID Type: int

name
Â¶ Object name (as a string)
Please refer to the wiki for details on using this class member.
Getter: Gets the object name Setter: Sets the object name Type: str

opt
Â¶ Dictionary for storing custom data in the current geometry object.
opt
is a wrapper to a dict in key => value format, where key is string, value is any Python object. You can useopt
property to store custom data inside the geometry object. For instance:geom.opt = ["face_id", 4] # creates "face_id" key and sets its value to an integer geom.opt = ["contents", "data values"] # creates "face_id" key and sets its value to a string print(geom.opt) # will print: {'face_id': 4, 'contents': 'data values'} del geom.opt # deletes the contents of the hash map print(geom.opt) # will print: {} geom.opt = ["body_id", 1] # creates "body_id" key and sets its value to 1 geom.opt = ["body_id", 12] # changes the value of "body_id" to 12 print(geom.opt) # will print: {'body_id': 12} geom.opt = ["body_id", None] # deletes "body_id" print(geom.opt) # will print: {}
Please refer to the wiki for details on using this class member.
Getter: Gets the dict Setter: Adds key and value pair to the dict Deleter: Deletes the contents of the dict

opt_get
(value)Â¶ Safely query for the value from the
opt
property.Parameters: value (str) â€“ a key in the opt
propertyReturns: the corresponding value, if the key exists. None
, otherwise.

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

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 container object will be used. Default: Truereset_names
: resets the name of the surfaces inside the container. Default: Falsenum_procs
: number of concurrent processes for rendering the surfaces. Default: 1
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.

reset
()Â¶ Resets the cache.

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

tessellate
(**kwargs)Â¶ Tessellates the surfaces inside the container.
Keyword arguments are directly passed to the tessellation component.
The following code snippet illustrates getting the vertices and faces of the surfaces inside the container:
1 2 3 4 5 6 7 8 9 10 11 12
# Tessellate the surfaces inside the container surf_container.tessellate() # Vertices and faces are stored inside the tessellator component tsl = surf_container.tessellator # Loop through all tessellator components for t in tsl: # Get the vertices vertices = t.tessellator.vertices # Get the faces (triangles, quads, etc.) faces = t.tessellator.faces
 Keyword Arguments:
num_procs
: number of concurrent processes for tessellating the surfaces. Default: 1delta
: if True, the evaluation delta of the container object will be used. Default: Trueforce
: flag to force tessellation. Default: False

tessellator
Â¶ Tessellation component of the surfaces inside the container.
Please refer to Tessellation documentation for details.
1 2 3 4 5 6 7 8
from geomdl import multi from geomdl import tessellate # Create the surface container surf_container = multi.SurfaceContainer(surf_list) # Set tessellator component surf_container.tessellator = tessellate.TrimTessellate()
Getter: gets the tessellation component Setter: sets the tessellation component

type
Â¶ Geometry type
Please refer to the wiki for details on using this class member.
Getter: Gets the geometry type Type: str

vertices
Â¶ Vertices generated by the tessellation operation.
If the tessellation component is set to None, the result will be an empty list.
Getter: Gets the vertices
Volume ContainerÂ¶

class
geomdl.multi.
VolumeContainer
(*args, **kwargs)Â¶ Bases:
geomdl.multi.AbstractContainer
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:
type
id
name
dimension
opt
pdimension
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 geometry objects to the container.
The input can be a single geometry, a list of geometry objects or a geometry container object.
Parameters: element â€“ geometry object

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

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

data
Â¶ Returns a dict which contains the geometry data.
Please refer to the wiki for details on using this class member.

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
Â¶ Spatial dimension.
Please refer to the wiki for details on using this class member.
Getter: Gets the spatial dimension, e.g. 2D, 3D, etc. Type: int

evalpts
Â¶ Evaluated points.
Since there are multiple geometry objects 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 geometries 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 geometries

id
Â¶ Object ID (as an integer).
Please refer to the wiki for details on using this class member.
Getter: Gets the object ID Setter: Sets the object ID Type: int

name
Â¶ Object name (as a string)
Please refer to the wiki for details on using this class member.
Getter: Gets the object name Setter: Sets the object name Type: str

opt
Â¶ Dictionary for storing custom data in the current geometry object.
opt
is a wrapper to a dict in key => value format, where key is string, value is any Python object. You can useopt
property to store custom data inside the geometry object. For instance:geom.opt = ["face_id", 4] # creates "face_id" key and sets its value to an integer geom.opt = ["contents", "data values"] # creates "face_id" key and sets its value to a string print(geom.opt) # will print: {'face_id': 4, 'contents': 'data values'} del geom.opt # deletes the contents of the hash map print(geom.opt) # will print: {} geom.opt = ["body_id", 1] # creates "body_id" key and sets its value to 1 geom.opt = ["body_id", 12] # changes the value of "body_id" to 12 print(geom.opt) # will print: {'body_id': 12} geom.opt = ["body_id", None] # deletes "body_id" print(geom.opt) # will print: {}
Please refer to the wiki for details on using this class member.
Getter: Gets the dict Setter: Adds key and value pair to the dict Deleter: Deletes the contents of the dict

opt_get
(value)Â¶ Safely query for the value from the
opt
property.Parameters: value (str) â€“ a key in the opt
propertyReturns: the corresponding value, if the key exists. None
, otherwise.

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

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 container object will be used. Default: Truereset_names
: resets the name of the volumes inside the container. Default: Falsegrid_size
: grid size for voxelization. Default: (16, 16, 16)num_procs
: number of concurrent processes for voxelization. Default: 1
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.

reset
()Â¶ Resets the cache.

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

sample_size_w
Â¶ Sample size for the wdirection.
Sample size defines the number of points to evaluate. 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
The following is the list of the features and geometric operations included in the library:
Geometric OperationsÂ¶
This module provides common geometric operations for curves and surfaces. It includes the following operations:
 Knot insertion, removal and refinement
 Curve and surface splitting / BÃ©zier decomposition
 Tangent, normal and binormal evaluations
 Hodograph curve and surface computations
 Translation, rotation and scaling
Function ReferenceÂ¶

geomdl.operations.
insert_knot
(obj, param, num, **kwargs)Â¶ Inserts knots ntimes to a spline geometry.
The following code snippet illustrates the usage of this function:
# Insert knot u=0.5 to a curve 2 times operations.insert_knot(curve, [0.5], [2]) # Insert knot v=0.25 to a surface 1 time operations.insert_knot(surface, [None, 0.25], [0, 1]) # Insert knots u=0.75, v=0.25 to a surface 2 and 1 times, respectively operations.insert_knot(surface, [0.75, 0.25], [2, 1]) # Insert knot w=0.5 to a volume 1 time operations.insert_knot(volume, [None, None, 0.5], [0, 0, 1])
Please note that input spline geometry object will always be updated if the knot insertion operation is successful.
 Keyword Arguments:
check_num
: enables/disables operation validity checks. Default: True
Parameters:  obj (abstract.SplineGeometry) â€“ spline geometry
 param (list, tuple) â€“ knot(s) to be inserted in [u, v, w] format
 num (list, tuple) â€“ number of knot insertions in [num_u, num_v, num_w] format
Returns: updated spline geometry

geomdl.operations.
remove_knot
(obj, param, num, **kwargs)Â¶ Removes knots ntimes from a spline geometry.
The following code snippet illustrates the usage of this function:
# Remove knot u=0.5 from a curve 2 times operations.remove_knot(curve, [0.5], [2]) # Remove knot v=0.25 from a surface 1 time operations.remove_knot(surface, [None, 0.25], [0, 1]) # Remove knots u=0.75, v=0.25 from a surface 2 and 1 times, respectively operations.remove_knot(surface, [0.75, 0.25], [2, 1]) # Remove knot w=0.5 from a volume 1 time operations.remove_knot(volume, [None, None, 0.5], [0, 0, 1])
Please note that input spline geometry object will always be updated if the knot removal operation is successful.
 Keyword Arguments:
check_num
: enables/disables operation validity checks. Default: True
Parameters:  obj (abstract.SplineGeometry) â€“ spline geometry
 param (list, tuple) â€“ knot(s) to be removed in [u, v, w] format
 num (list, tuple) â€“ number of knot removals in [num_u, num_v, num_w] format
Returns: updated spline geometry

geomdl.operations.
refine_knotvector
(obj, param, **kwargs)Â¶ Refines the knot vector(s) of a spline geometry.
The following code snippet illustrates the usage of this function:
# Refines the knot vector of a curve operations.refine_knotvector(curve, [1]) # Refines the knot vector on the vdirection of a surface operations.refine_knotvector(surface, [0, 1]) # Refines the both knot vectors of a surface operations.refine_knotvector(surface, [1, 1]) # Refines the knot vector on the wdirection of a volume operations.refine_knotvector(volume, [0, 0, 1])
The values of
param
argument can be used to set the knot refinement density. If density is bigger than 1, then the algorithm finds the middle knots in each internal knot span to increase the number of knots to be refined.Example: Let the degree is 2 and the knot vector to be refined is
[0, 2, 4]
with the superfluous knots from the start and end are removed. Knot vectors with the changingdensity (d)
value will be:d = 1
, knot vector[0, 1, 1, 2, 2, 3, 3, 4]
d = 2
, knot vector[0, 0.5, 0.5, 1, 1, 1.5, 1.5, 2, 2, 2.5, 2.5, 3, 3, 3.5, 3.5, 4]
The following code snippet illustrates the usage of knot refinement densities:
# Refines the knot vector of a curve with density = 3 operations.refine_knotvector(curve, [3]) # Refines the knot vectors of a surface with density for # udir = 2 and vdir = 3 operations.refine_knotvector(surface, [2, 3]) # Refines only the knot vector on the vdirection of a surface with density = 1 operations.refine_knotvector(surface, [0, 1]) # Refines the knot vectors of a volume with density for # udir = 1, vdir = 3 and wdir = 2 operations.refine_knotvector(volume, [1, 3, 2])
Please refer to
helpers.knot_refinement()
function for more usage options. Keyword Arguments:
check_num
: enables/disables operation validity checks. Default: True
Parameters:  obj (abstract.SplineGeometry) â€“ spline geometry
 param (list, tuple) â€“ parametric dimensions to be refined in [u, v, w] format
Returns: updated spline geometry

geomdl.operations.
add_dimension
(obj, **kwargs)Â¶ Elevates the spatial dimension of the spline geometry.
If you pass
inplace=True
keyword argument, the input will be updated. Otherwise, this function does not change the input but returns a new instance with the updated data.Parameters: obj (abstract.SplineGeometry) â€“ spline geometry Returns: updated spline geometry Return type: abstract.SplineGeometry

geomdl.operations.
split_curve
(obj, param, **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.
 Keyword Arguments:
find_span_func
: FindSpan implementation. Default:helpers.find_span_linear()
insert_knot_func
: knot insertion algorithm implementation. Default:operations.insert_knot()
Parameters:  obj (abstract.Curve) â€“ Curve to be split
 param (float) â€“ parameter
Returns: a list of curve segments
Return type: list

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.
 Keyword Arguments:
find_span_func
: FindSpan implementation. Default:helpers.find_span_linear()
insert_knot_func
: knot insertion algorithm implementation. Default:operations.insert_knot()
Parameters: obj (abstract.Curve) â€“ Curve to be decomposed Returns: a list of Bezier segments Return type: list

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.
length_curve
(obj)Â¶ Computes the approximate length of the parametric curve.
Uses the following equation to compute the approximate length:
where is number of evaluated curve points and is the ndimensional point.
Parameters: obj (abstract.Curve) â€“ input curve Returns: length Return type: float

geomdl.operations.
split_surface_u
(obj, param, **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.
 Keyword Arguments:
find_span_func
: FindSpan implementation. Default:helpers.find_span_linear()
insert_knot_func
: knot insertion algorithm implementation. Default:operations.insert_knot()
Parameters:  obj (abstract.Surface) â€“ surface
 param (float) â€“ parameter for the udirection
Returns: a list of surface patches
Return type: list

geomdl.operations.
split_surface_v
(obj, param, **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.
 Keyword Arguments:
find_span_func
: FindSpan implementation. Default:helpers.find_span_linear()
insert_knot_func
: knot insertion algorithm implementation. Default:operations.insert_knot()
Parameters:  obj (abstract.Surface) â€“ surface
 param (float) â€“ parameter for the vdirection
Returns: a list of surface patches
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.
 Keyword Arguments:
find_span_func
: FindSpan implementation. Default:helpers.find_span_linear()
insert_knot_func
: knot insertion algorithm implementation. Default:operations.insert_knot()
Parameters: obj (abstract.Surface) â€“ surface Returns: a list of Bezier patches Return type: list

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.
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.
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.
translate
(obj, vec, **kwargs)Â¶ Translates curves, surface or volumes by the input vector.
 Keyword Arguments:
inplace
: if False, operation applied to a copy of the object. Default: False
Parameters:  obj (abstract.SplineGeometry or multi.AbstractContainer) â€“ input geometry
 vec (list, tuple) â€“ translation vector
Returns: translated geometry object

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. Default: 2inplace
: if False, operation applied to a copy of the object. Default: False
Parameters:  obj (abstract.SplineGeometry, multi.AbstractGeometry) â€“ 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 False, operation applied to a copy of the object. Default: False
Parameters:  obj (abstract.SplineGeometry, multi.AbstractGeometry) â€“ input geometry
 multiplier (float) â€“ scaling multiplier
Returns: scaled geometry object

geomdl.operations.
transpose
(surf, **kwargs)Â¶ Transposes the input surface(s) by swapping u and v parametric directions.
 Keyword Arguments:
inplace
: if False, operation applied to a copy of the object. Default: False
Parameters: surf (abstract.Surface, multi.SurfaceContainer) â€“ input surface(s) Returns: transposed surface(s)

geomdl.operations.
flip
(surf, **kwargs)Â¶ Flips the control points grid of the input surface(s).
 Keyword Arguments:
inplace
: if False, operation applied to a copy of the object. Default: False
Parameters: surf (abstract.Surface, multi.SurfaceContainer) â€“ input surface(s) Returns: flipped surface(s)
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
 size_v (int) â€“ size in vdirection
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
Geometry ConvertersÂ¶
convert
module provides functions for converting nonrational and rational geometries to each other.
Function ReferenceÂ¶

geomdl.convert.
bspline_to_nurbs
(obj, **kwargs)Â¶ Converts nonrational splines to rational ones.
Parameters: obj (BSpline.Curve, BSpline.Surface or BSpline.Volume) â€“ nonrational spline geometry Returns: rational spline geometry Return type: NURBS.Curve, NURBS.Surface or NURBS.Volume Raises: TypeError

geomdl.convert.
nurbs_to_bspline
(obj, **kwargs)Â¶ Converts rational splines to nonrational ones (if possible).
The possibility of converting a rational spline geometry to a nonrational one depends on the weights vector.
Parameters: obj (NURBS.Curve, NURBS.Surface or NURBS.Volume) â€“ rational spline geometry Returns: nonrational spline geometry Return type: BSpline.Curve, BSpline.Surface or BSpline.Volume Raises: TypeError
Geometry Constructors and ExtractorsÂ¶
New in version 5.0.
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
(direction, *args, **kwargs)Â¶ Generates surfaces from curves.
 Arguments:
args
: a list of curve instances
 Keyword Arguments (optional):
degree
: degree of the 2nd parametric directionknotvector
: knot vector of the 2nd parametric directionrational
: flag to generate rational surfaces
Parameters: direction (str) â€“ the direction that the input curves lies, i.e. u or v Returns: Surface constructed from the curves on the given parametric direction

geomdl.construct.
construct_volume
(direction, *args, **kwargs)Â¶ Generates volumes from surfaces.
 Arguments:
args
: a list of surface instances
 Keyword Arguments (optional):
degree
: degree of the 3rd parametric directionknotvector
: knot vector of the 3rd parametric directionrational
: flag to generate rational volumes
Parameters: direction (str) â€“ the direction that the input surfaces lies, i.e. u, v, w Returns: Volume constructed from the surfaces on the given parametric direction

geomdl.construct.
extract_curves
(psurf, **kwargs)Â¶ Extracts curves from a surface.
The return value is a
dict
object containing the following keys:u
: the curves which generate udirection (or which lie on the vdirection)v
: the curves which generate vdirection (or which lie on the udirection)
As an example; if a curve lies on the udirection, then its knotvector is equal to surfaceâ€™s knotvector on the vdirection and vice versa.
The curve extraction process can be controlled via
extract_u
andextract_v
boolean keyword arguments.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
Curve and Surface FittingÂ¶
New in version 5.0.
fitting
module provides functions for interpolating and approximating
Bspline curves and surfaces from data points. Approximation uses least
squares algorithm.
Please see the following functions for details:
Surface fitting generates control points grid defined in u and v
parametric dimensions. Therefore, the input requires number of data
points to be fitted in both parametric dimensions. In other words,
size_u
and size_v
arguments are used to fit curves of the
surface on the corresponding parametric dimension.
Degree of the output spline geometry is important to determine the
knot vector(s), compute the basis functions and build the coefficient
matrix, . Most of the time, fitting to a quadratic (degree = 2
)
or a cubic (degree = 3
) Bspline geometry should be good enough.
In the array structure, the data points on the vdirection come the first and udirection points come. The index of the data points can be found using the following formula:
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:
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.
Note
To get better results with the surface trimming, you need to use a relatively smaller evaluation delta or a bigger sample size value. Recommended evaluation delta is .
Class ReferenceÂ¶
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 (as a dict) Setter: Sets the tessellation arguments (as a dict)

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.

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 (as a dict) Setter: Sets the tessellation arguments (as a dict)

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, tuple) â€“ array of points

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

Trim TessellatorÂ¶
New in version 5.0.

class
geomdl.tessellate.
TrimTessellate
(**kwargs)Â¶ Bases:
geomdl.tessellate.AbstractTessellate
Triangular tessellation algorithm for trimmed 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 (as a dict) Setter: Sets the tessellation arguments (as a dict)

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 w/ trimming curves.
 Keyword Arguments:
size_u
: number of points on the udirectionsize_v
: number of points on the vdirection
Parameters: points (list, tuple) â€“ array of points

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

Quadrilateral TessellatorÂ¶
New in version 5.2.

class
geomdl.tessellate.
QuadTessellate
(**kwargs)Â¶ Bases:
geomdl.tessellate.AbstractTessellate
Quadrilateral 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 (as a dict) Setter: Sets the tessellation arguments (as a dict)

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 quadrilateral 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, tuple) â€“ array of points

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

Function ReferenceÂ¶

geomdl.tessellate.
make_triangle_mesh
(points, size_u, size_v, **kwargs)Â¶ Generates a triangular mesh from an array of points.
This function generates a triangular mesh for a NURBS or BSpline surface on its parametric space. The input is the surface points and the number of points on the parametric dimensions u and v, indicated as row and column sizes in the function signature. This function should operate correctly if row and column sizes are input correctly, no matter what the points are vordered or uordered. Please see the documentation of
ctrlpts
andctrlpts2d
properties of the Surface class for more details on point ordering for the surfaces.This function accepts the following keyword arguments:
vertex_spacing
: Defines the size of the triangles via setting the jump value between pointstrims
: List of trim curves passed to the tessellation functiontessellate_func
: Function called for tessellation. Default:tessellate.surface_tessellate()
tessellate_args
: Arguments passed to the tessellation function (as a dict)
The tessellation function is designed to generate triangles from 4 vertices. It takes 4
Vertex
objects, index values for setting the triangle and vertex IDs and additional parameters as its function arguments. It returns a tuple ofVertex
andTriangle
object lists generated from the input vertices. A default triangle generator is provided as a prototype for implementation in the source code.The return value of this function is a tuple containing two lists. First one is the list of vertices and the second one is the list of triangles.
Parameters:  points (list, tuple) â€“ input points
 size_u (int) â€“ number of elements on the udirection
 size_v (int) â€“ number of elements on the vdirection
Returns: a tuple containing lists of vertices and triangles
Return type: tuple

geomdl.tessellate.
polygon_triangulate
(tri_idx, *args)Â¶ Triangulates a monotone polygon defined by a list of vertices.
The input vertices must form a convex polygon and must be arranged in counterclockwise order.
Parameters:  tri_idx (int) â€“ triangle numbering start value
 args (Vertex) â€“ list of Vertex objects
Returns: list of Triangle objects
Return type: list

geomdl.tessellate.
make_quad_mesh
(points, size_u, size_v)Â¶ Generates a mesh of quadrilateral elements.
Parameters:  points (list, tuple) â€“ list of points
 size_u (int) â€“ number of points on the udirection (column)
 size_v (int) â€“ number of points on the vdirection (row)
Returns: a tuple containing lists of vertices and quads
Return type: tuple
Helper FunctionsÂ¶

geomdl.tessellate.
surface_tessellate
(v1, v2, v3, v4, vidx, tidx, trim_curves, tessellate_args)Â¶ Triangular tessellation algorithm for surfaces with no trims.
This function can be directly used as an input to
make_triangle_mesh()
usingtessellate_func
keyword argument.Parameters: Type: list, tuple
Returns: lists of vertex and triangle objects in (vertex_list, triangle_list) format
Type: tuple

geomdl.tessellate.
surface_trim_tessellate
(v1, v2, v3, v4, vidx, tidx, trims, tessellate_args)Â¶ Triangular tessellation algorithm for trimmed surfaces.
This function can be directly used as an input to
make_triangle_mesh()
usingtessellate_func
keyword argument.Parameters: Returns: lists of vertex and triangle objects in (vertex_list, triangle_list) format
Type: tuple
TrimmingÂ¶
TessellationÂ¶
Please refer to tessellate.TrimTessellate
for tessellating the surfaces with trims.
Function ReferenceÂ¶
Warning
The functions included in the trimming
module are still workinprogress and their
functionality can change or they can be removed from the library in the next releases.
Please contact the author if you encounter any problems.

geomdl.trimming.
map_trim_to_geometry
(obj, trim_idx=1, **kwargs)Â¶ Generates 3dimensional mapping of 2dimensional trimming curves.
Description:
Trimming curves are defined on the parametric space of the surfaces. Therefore, all trimming curves are 2dimensional. The coordinates of the trimming curves correspond to (u, v) parameters of the underlying surface geometry. When these (u, v) values are evaluated with respect to the underlying surface geometry, a 3dimensional representation of the trimming curves is generated.
The resultant 3dimensional curve is described using
freeform.Freeform
class. Using thefitting
module, it is possible to generate the Bspline form of the freeform curve.Remarks:
If trim_idx=1, the function maps all 2dimensional trims to their 3dimensional correspondants.
Parameters:  obj (abstract.SplineGeometry) â€“ spline geometry
 trim_idx (int) â€“ index of the trimming curve in the geometry object
Returns: 3dimensional mapping of trimming curve(s)
Return type:

geomdl.trimming.
fix_multi_trim_curves
(obj, **kwargs)Â¶ Fixes direction, connectivity and similar issues of the trim curves.
This function works for surface trims in curve containers, i.e. trims consisting of multiple curves.
 Keyword Arguments:
tol
: tolerance value for comparing floats. Default: 10e8delta
: evaluation delta of the trim curves. Default: 0.05
Parameters: obj (abstract.BSplineGeometry, multi.AbstractContainer) â€“ input surface Returns: updated surface

geomdl.trimming.
fix_trim_curves
(obj)Â¶ Fixes direction, connectivity and similar issues of the trim curves.
This function works for surface trim curves consisting of a single curve.
Parameters: obj (abstract.Surface) â€“ input surface
SweepingÂ¶
Warning
sweeping
is a highly experimental module. Please use it with caution.
Function ReferenceÂ¶

geomdl.sweeping.
sweep_vector
(obj, vec, **kwargs)Â¶ Sweeps spline geometries along a vector.
This API call generates
 swept surfaces from curves
 swept volumes from surfaces
Parameters:  obj (abstract.SplineGeometry) â€“ spline geometry
 vec (list, tuple) â€“ vector to sweep along
Returns: swept geometry
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 import/export control points or export evaluated points:
The following functions work with single or multiple surfaces:
exchange.import_obj()
exchange.export_obj()
exchange.export_stl()
exchange.export_off()
exchange.import_smesh()
exchange.export_smesh()
The following functions work with single or multiple volumes:
The following functions can be used to import/export rational or nonrational spline geometries:
exchange.import_yaml()
exchange.export_yaml()
exchange.import_cfg()
exchange.export_cfg()
exchange.import_json()
exchange.export_json()
The following functions work with single or multiple curves and surfaces:
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: GeomdlException â€“ 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 2dimensional control point output file using
two_dimensional
.Please see
exchange.import_txt()
for detailed description of the keyword arguments.Parameters:  obj (abstract.SplineGeometry) â€“ a spline geometry 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: GeomdlException â€“ 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: GeomdlException â€“ 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.SplineGeometry) â€“ a spline geometry object
 file_name (str) â€“ output file name
 point_type (str) â€“
ctrlpts
for control points orevalpts
for evaluated points
Raises: GeomdlException â€“ 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 rational spline geometries Return type: list Raises: GeomdlException â€“ 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.SplineGeometry, multi.AbstractContainer) â€“ input geometry
 file_name (str) â€“ name of the output file
Raises: GeomdlException â€“ 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 rational spline geometries Return type: list Raises: GeomdlException â€“ 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.SplineGeometry, multi.AbstractContainer) â€“ input geometry
 file_name (str) â€“ name of the output file
Raises: GeomdlException â€“ 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 rational spline geometries Return type: list Raises: GeomdlException â€“ 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.SplineGeometry, multi.AbstractContainer) â€“ input geometry
 file_name (str) â€“ name of the output file
Raises: GeomdlException â€“ an error occurred writing the file

geomdl.exchange.
import_obj
(file_name, **kwargs)Â¶ Reads .obj files and generates faces.
 Keyword Arguments:
callback
: reference to the function that processes the faces for customized output
The structure of the callback function is shown below:
def my_callback_function(face_list): # "face_list" will be a list of elements.Face class instances # The function should return a list return list()
Parameters: file_name (str) â€“ file name Returns: output of the callback function (default is a list of faces) Return type: list

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 surface points sampled. Default: 2vertex_normals
: if True, then computes vertex normals. Default: Falseparametric_vertices
: if True, then adds parameter space vertices. Default: Falseupdate_delta
: use multisurface evaluation delta for all surfaces. Default: True
Parameters:  surface (abstract.Surface or multi.SurfaceContainer) â€“ surface or surfaces to be saved
 file_name (str) â€“ name of the output file
Raises: GeomdlException â€“ 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: 1update_delta
: use multisurface evaluation delta for all surfaces. Default: True
Parameters:  surface (abstract.Surface or multi.SurfaceContainer) â€“ surface or surfaces to be saved
 file_name (str) â€“ name of the output file
Raises: GeomdlException â€“ 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: 1update_delta
: use multisurface evaluation delta for all surfaces. Default: True
Parameters:  surface (abstract.Surface or multi.SurfaceContainer) â€“ surface or surfaces to be saved
 file_name (str) â€“ name of the output file
Raises: GeomdlException â€“ 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: GeomdlException â€“ 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: GeomdlException â€“ 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: GeomdlException â€“ 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: GeomdlException â€“ an error occurred writing the file

geomdl.exchange.
import_3dm
(file_name, **kwargs)Â¶ Imports curves and surfaces from Rhinoceros/OpenNURBS .3dm files.
Deprecated since version 5.2.2:
rw3dm
Python module is replaced byon2json
. It can be used to convert .3dm files to geomdl JSON format. Please refer to https://github.com/orbingol/rw3dm for more details.Parameters: file_name (str) â€“ input file name

geomdl.exchange.
export_3dm
(obj, file_name, **kwargs)Â¶ Exports NURBS curves and surfaces to Rhinoceros/OpenNURBS .3dm files.
Deprecated since version 5.2.2:
rw3dm
Python module is replaced byjson2on
. It can be used to convert geomdl JSON format to .3dm files. Please refer to https://github.com/orbingol/rw3dm for more details.Parameters:  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, **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
 Keyword Arguments:
point_type
: ctrlpts for control points or evalpts for evaluated pointstessellate
: tessellates the points (works only for surfaces)
Parameters:  obj (abstract.SplineGeometry, multi.AbstractContainer) â€“ geometry object
 file_name (str) â€“ output file name
Raises: GeomdlException â€“ an error occurred writing the file
Geometry GeneratorsÂ¶
The following list contains the geometry generators/managers included in the library:
Knot Vector GeneratorÂ¶
The knotvector
module provides utility functions related to knot vector generation and validation.
Function ReferenceÂ¶

geomdl.knotvector.
generate
(degree, num_ctrlpts, **kwargs)Â¶ Generates an equally spaced knot vector.
It uses the following equality to generate knot vector:
where;
 , degree
 , number of control points
 , 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

geomdl.knotvector.
normalize
(knot_vector, decimals=18)Â¶ Normalizes the input knot vector to [0, 1] domain.
Parameters:  knot_vector (list, tuple) â€“ knot vector to be normalized
 decimals (int) â€“ rounding number
Returns: normalized knot vector
Return type: list

geomdl.knotvector.
check
(degree, knot_vector, num_ctrlpts)Â¶ Checks the validity of the input knot vector.
Please refer to The NURBS Book (2nd Edition), p.50 for details.
Parameters:  degree (int) â€“ degree of the curve or the surface
 knot_vector (list, tuple) â€“ knot vector to be checked
 num_ctrlpts (int) â€“ number of control points
Returns: True if the knot vector is valid, False otherwise
Return type: bool
Control Points ManagerÂ¶
The control_points
module provides helper functions for managing control points. It is a better alternative to
the compatibility module for managing control points. Please refer to the following
class references for more details.
Class ReferenceÂ¶

class
geomdl.control_points.
AbstractManager
(*args, **kwargs)Â¶ Bases:
object
Abstract base class for control points manager classes.
Control points manager class provides an easy way to set control points without knowing the internal data structure of the geometry classes. The manager class is initialized with the number of control points in all parametric dimensions.
All classes extending this class should implement the following methods:
find_index
This class provides the following properties:
This class provides the following methods:

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

find_index
(*args)Â¶ Finds the array index from the given parametric positions.
Note
This is an abstract method and it must be implemented in the subclass.

get_ctrlpt
(*args)Â¶ Gets the control point from the given location in the array.

get_ptdata
(dkey, *args)Â¶ Gets the data attached to the control point.
Parameters:  dkey â€“ key of the attachment dictionary
 dkey â€“ str

reset
()Â¶ Resets/initializes the internal control points array.

set_ctrlpt
(pt, *args)Â¶ Puts the control point to the given location in the array.
Parameters: pt (list, tuple) â€“ control point

set_ptdata
(adct, *args)Â¶ Attaches the data to the control point.
Parameters:  adct â€“ attachment dictionary
 adct â€“ dict

class
geomdl.control_points.
CurveManager
(*args, **kwargs)Â¶ Bases:
geomdl.control_points.AbstractManager
Curve control points manager.
Control points manager class provides an easy way to set control points without knowing the internal data structure of the geometry classes. The manager class is initialized with the number of control points in all parametric dimensions.
Bspline curves are defined in one parametric dimension. Therefore, this manager class should be initialized with a single integer value.
# Assuming that the curve has 10 control points manager = CurveManager(10)
Getting the control points:
# Number of control points in all parametric dimensions size_u = spline.ctrlpts_size_u # Generate control points manager cpt_manager = control_points.SurfaceManager(size_u) cpt_manager.ctrlpts = spline.ctrlpts # Control points array to be used externally control_points = [] # Get control points from the spline geometry for u in range(size_u): pt = cpt_manager.get_ctrlpt(u) control_points.append(pt)
Setting the control points:
# Number of control points in all parametric dimensions size_u = 5 # Create control points manager points = control_points.SurfaceManager(size_u) # Set control points for u in range(size_u): # 'pt' is the control point, e.g. [10, 15, 12] points.set_ctrlpt(pt, u, v) # Create spline geometry curve = BSpline.Curve() # Set control points curve.ctrlpts = points.ctrlpts

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

find_index
(*args)Â¶ Finds the array index from the given parametric positions.
Note
This is an abstract method and it must be implemented in the subclass.

get_ctrlpt
(*args)Â¶ Gets the control point from the given location in the array.

get_ptdata
(dkey, *args)Â¶ Gets the data attached to the control point.
Parameters:  dkey â€“ key of the attachment dictionary
 dkey â€“ str

reset
()Â¶ Resets/initializes the internal control points array.

set_ctrlpt
(pt, *args)Â¶ Puts the control point to the given location in the array.
Parameters: pt (list, tuple) â€“ control point

set_ptdata
(adct, *args)Â¶ Attaches the data to the control point.
Parameters:  adct â€“ attachment dictionary
 adct â€“ dict


class
geomdl.control_points.
SurfaceManager
(*args, **kwargs)Â¶ Bases:
geomdl.control_points.AbstractManager
Surface control points manager.
Control points manager class provides an easy way to set control points without knowing the internal data structure of the geometry classes. The manager class is initialized with the number of control points in all parametric dimensions.
Bspline surfaces are defined in one parametric dimension. Therefore, this manager class should be initialized with two integer values.
# Assuming that the surface has size_u = 5 and size_v = 7 control points manager = SurfaceManager(5, 7)
Getting the control points:
# Number of control points in all parametric dimensions size_u = spline.ctrlpts_size_u size_v = spline.ctrlpts_size_v # Generate control points manager cpt_manager = control_points.SurfaceManager(size_u, size_v) cpt_manager.ctrlpts = spline.ctrlpts # Control points array to be used externally control_points = [] # Get control points from the spline geometry for u in range(size_u): for v in range(size_v): pt = cpt_manager.get_ctrlpt(u, v) control_points.append(pt)
Setting the control points:
# Number of control points in all parametric dimensions size_u = 5 size_v = 3 # Create control points manager points = control_points.SurfaceManager(size_u, size_v) # Set control points for u in range(size_u): for v in range(size_v): # 'pt' is the control point, e.g. [10, 15, 12] points.set_ctrlpt(pt, u, v) # Create spline geometry surf = BSpline.Surface() # Set control points surf.ctrlpts = points.ctrlpts

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

find_index
(*args)Â¶ Finds the array index from the given parametric positions.
Note
This is an abstract method and it must be implemented in the subclass.

get_ctrlpt
(*args)Â¶ Gets the control point from the given location in the array.

get_ptdata
(dkey, *args)Â¶ Gets the data attached to the control point.
Parameters:  dkey â€“ key of the attachment dictionary
 dkey â€“ str

reset
()Â¶ Resets/initializes the internal control points array.

set_ctrlpt
(pt, *args)Â¶ Puts the control point to the given location in the array.
Parameters: pt (list, tuple) â€“ control point

set_ptdata
(adct, *args)Â¶ Attaches the data to the control point.
Parameters:  adct â€“ attachment dictionary
 adct â€“ dict
