SINTEF / Splipy

Spline modelling made easy.
GNU General Public License v3.0
102 stars 18 forks source link

SurfaceFactory Sweep #12

Closed VikingScientist closed 7 years ago

VikingScientist commented 7 years ago

Allows for sweeping curves along other curves to generate a surface. This is a short example showing the potential uses for this where we sweep a circle around a trefoil knot

from splipy import *                                                           
from splipy.IO import *                                                        
from numpy import pi, cos, sin                                                 
import numpy as np                                                             
import splipy.curve_factory   as curves                                        
import splipy.surface_factory as surfaces                                      

def trefoil_knot(resolution=100):                                              
  u = np.linspace(0, 2*pi, resolution)                                         
  x = [41*cos(u) - 18*sin(  u) -  83*cos(2*u) - 83*sin(2*u) - 11*cos(3*u) + 27*sin(3*u), 
       36*cos(u) + 27*sin(  u) - 113*cos(2*u) + 30*sin(2*u) + 11*cos(3*u) - 27*sin(3*u), 
       45*sin(u) - 30*cos(2*u) + 113*sin(2*u) - 11*cos(3*u) + 27*sin(3*u)]        
  x = np.transpose(np.array(x))                                                
  return curves.cubic_curve(x, curves.Boundary.PERIODIC)                       

path  = trefoil_knot()                                                         
# shape = curves.circle(r=16)                                                  
shape = 16*curves.n_gon(4)                                                     
srf = surfaces.sweep(path, shape)                                              

with G2('trefoil.g2') as f:                                                    
    f.write(srf)                                                               

Sweeping a circle

sweep_circle

Sweeping a square

sweep_square