Surface Generator
NURBS-Python 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 B-Spline surface generator:
1from geomdl import CPGen
2from geomdl import BSpline
3from geomdl import utilities
4from geomdl.visualization import VisMPL
5from matplotlib import cm
6
7# Generate a plane with the dimensions 50x100
8surfgrid = CPGen.Grid(50, 100)
9
10# Generate a grid of 25x30
11surfgrid.generate(50, 60)
12
13# Generate bumps on the grid
14surfgrid.bumps(num_bumps=5, bump_height=20, base_extent=8)
15
16# Create a BSpline surface instance
17surf = BSpline.Surface()
18
19# Set degrees
20surf.degree_u = 3
21surf.degree_v = 3
22
23# Get the control points from the generated grid
24surf.ctrlpts2d = surfgrid.grid
25
26# Set knot vectors
27surf.knotvector_u = utilities.generate_knot_vector(surf.degree_u, surf.ctrlpts_size_u)
28surf.knotvector_v = utilities.generate_knot_vector(surf.degree_v, surf.ctrlpts_size_v)
29
30# Set sample size
31surf.sample_size = 100
32
33# Set visualization component
34surf.vis = VisMPL.VisSurface(ctrlpts=False, legend=False)
35
36# Plot the surface
37surf.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_extentis 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.