From a86bcf92ae109bdfcac6a231977cb88ef74eced3 Mon Sep 17 00:00:00 2001 From: Onur Rauf Bingol Date: Fri, 31 Aug 2018 23:00:33 -0500 Subject: [PATCH] Add torodial surface example --- surface/ex_torus.cptw | 9 ++++++++ surface/ex_torus.py | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 surface/ex_torus.cptw create mode 100644 surface/ex_torus.py diff --git a/surface/ex_torus.cptw b/surface/ex_torus.cptw new file mode 100644 index 0000000..f006f02 --- /dev/null +++ b/surface/ex_torus.cptw @@ -0,0 +1,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 +-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 +-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 +-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 +-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 +-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 +-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 +-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 +-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 diff --git a/surface/ex_torus.py b/surface/ex_torus.py new file mode 100644 index 0000000..637d706 --- /dev/null +++ b/surface/ex_torus.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" + Examples for the NURBS-Python Package + Released under MIT License + Developed by Onur Rauf Bingol (c) 2018 + + Toroidal surface is contributed by Harshil Shah (@harshilsofeshah) +""" + +import os +from geomdl import NURBS +from geomdl import exchange +from geomdl.visualization import VisMPL + + +# Fix file path +os.chdir(os.path.dirname(os.path.realpath(__file__))) + +# Create a NURBS surface instance +surf = NURBS.Surface() + +# Set degress +surf.degree_u = 2 +surf.degree_v = 2 + +# Set control points +surf.set_ctrlpts(*exchange.import_txt("ex_torus.cptw", two_dimensional=True)) + +# Set knot vectors +surf.knotvector_u = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1] +surf.knotvector_v = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1] + +# Set sample size and evaluate surface +surf.sample_size = 25 +surf.evaluate() + +# Import colormaps +from matplotlib import cm + +# Plot the surface +vis_config = VisMPL.VisConfig(ctrlpts=True, axes=True, legend=False) +vis_comp = VisMPL.VisSurfTriangle(vis_config) +surf.vis = vis_comp +surf.render(colormap=cm.coolwarm) + +# Good to have something here to put a breakpoint +pass