Skip to content

Commit a86bcf9

Browse files
author
Onur Rauf Bingol
committed
Add torodial surface example
1 parent c53d16f commit a86bcf9

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

surface/ex_torus.cptw

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-125.0,0.0,0.0,1.0;-125.0,0.0,125.0,1.0;0.0,0.0,125.0,1.0;125.0,0.0,125.0,1.0;125.0,0.0,0.0,1.0;125.0,0.0,-125.0,1.0;0.0,0.0,-125.0,1.0;-125.0,0.0,-125.0,1.0;-125.0,0.0,0.0,1.0
2+
-88.375,70.7,0.0,0.707;-88.375,70.7,88.375,0.707;0.0,70.7,88.375,0.707;88.375,70.7,88.375,0.707;88.375,70.7,0.0,0.707;88.375,70.7,-88.375,0.707;0.0,70.7,-88.375,0.707;-88.375,70.7,-88.375,0.707;-88.375,70.7,0.0,0.707
3+
-225.0,100.0,0.0,1.0;-225.0,100.0,225.0,1.0;0.0,100.0,225.0,1.0;225.0,100.0,225.0,1.0;225.0,100.0,0.0,1.0;225.0,100.0,-225.0,1.0;0.0,100.0,-225.0,1.0;-225.0,100.0,-225.0,1.0;-225.0,100.0,0.0,1.0
4+
-229.775,70.7,0.0,0.707;-229.775,70.7,229.775,0.707;0.0,70.7,229.775,0.707;229.775,70.7,229.775,0.707;229.775,70.7,0.0,0.707;229.775,70.7,-229.775,0.707;0.0,70.7,-229.775,0.707;-229.775,70.7,-229.775,0.707;-229.775,70.7,0.0,0.707
5+
-325.0,0.0,0.0,1.0;-325.0,0.0,325.0,1.0;0.0,0.0,325.0,1.0;325.0,0.0,325.0,1.0;325.0,0.0,0.0,1.0;325.0,0.0,-325.0,1.0;0.0,0.0,-325.0,1.0;-325.0,0.0,-325.0,1.0;-325.0,0.0,0.0,1.0
6+
-229.775,-70.7,0.0,0.707;-229.775,-70.7,229.775,0.707;0.0,-70.7,229.775,0.707;229.775,-70.7,229.775,0.707;229.775,-70.7,0.0,0.707;229.775,-70.7,-229.775,0.707;0.0,-70.7,-229.775,0.707;-229.775,-70.7,-229.775,0.707;-229.775,-70.7,0.0,0.707
7+
-225.0,-100.0,0.0,1.0;-225.0,-100.0,225.0,1.0;0.0,-100.0,225.0,1.0;225.0,-100.0,225.0,1.0;225.0,-100.0,0.0,1.0;225.0,-100.0,-225.0,1.0;0.0,-100.0,-225.0,1.0;-225.0,-100.0,-225.0,1.0;-225.0,-100.0,0.0,1.0
8+
-88.375,-70.7,0.0,0.707;-88.375,-70.7,88.375,0.707;0.0,-70.7,88.375,0.707;88.375,-70.7,88.375,0.707;88.375,-70.7,0.0,0.707;88.375,-70.7,-88.375,0.707;0.0,-70.7,-88.375,0.707;-88.375,-70.7,-88.375,0.707;-88.375,-70.7,0.0,0.707
9+
-125.0,0.0,0.0,1.0;-125.0,0.0,125.0,1.0;0.0,0.0,125.0,1.0;125.0,0.0,125.0,1.0;125.0,0.0,0.0,1.0;125.0,0.0,-125.0,1.0;0.0,0.0,-125.0,1.0;-125.0,0.0,-125.0,1.0;-125.0,0.0,0.0,1.0

surface/ex_torus.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Examples for the NURBS-Python Package
6+
Released under MIT License
7+
Developed by Onur Rauf Bingol (c) 2018
8+
9+
Toroidal surface is contributed by Harshil Shah (@harshilsofeshah)
10+
"""
11+
12+
import os
13+
from geomdl import NURBS
14+
from geomdl import exchange
15+
from geomdl.visualization import VisMPL
16+
17+
18+
# Fix file path
19+
os.chdir(os.path.dirname(os.path.realpath(__file__)))
20+
21+
# Create a NURBS surface instance
22+
surf = NURBS.Surface()
23+
24+
# Set degress
25+
surf.degree_u = 2
26+
surf.degree_v = 2
27+
28+
# Set control points
29+
surf.set_ctrlpts(*exchange.import_txt("ex_torus.cptw", two_dimensional=True))
30+
31+
# Set knot vectors
32+
surf.knotvector_u = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]
33+
surf.knotvector_v = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]
34+
35+
# Set sample size and evaluate surface
36+
surf.sample_size = 25
37+
surf.evaluate()
38+
39+
# Import colormaps
40+
from matplotlib import cm
41+
42+
# Plot the surface
43+
vis_config = VisMPL.VisConfig(ctrlpts=True, axes=True, legend=False)
44+
vis_comp = VisMPL.VisSurfTriangle(vis_config)
45+
surf.vis = vis_comp
46+
surf.render(colormap=cm.coolwarm)
47+
48+
# Good to have something here to put a breakpoint
49+
pass

0 commit comments

Comments
 (0)