How to use the splipy.curve_factory function in Splipy

To help you get started, we’ve selected a few Splipy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sintefmath / Splipy / splipy / utils / image.py View on Github external
knot[i] = (knot[i-1]+knot[i+1])/2.0

        # make C^0 at corners and C^-1 at endpoints by duplicating knots
        knot = sorted(knot + c + c + [0,n-1]) # both c and knot contains a copy of the endpoints

        # make it span [0,1] instead of [0,n-1]
        for i in range(len(knot)):
            knot[i] /= float(n-1)

        # make it periodic since these are all closed curves
        knot[0]  -= knot[-1] - knot[-5]
        knot[-1] += knot[4]  - knot[1]

        basis = BSplineBasis(4, knot, 0)

        c = curve_factory.least_square_fit(np.array(pts), basis, parpt)
        result.append(c)

    return result
github sintefmath / Splipy / splipy / io / grdecl.py View on Github external
if jrange[1] == None: jrange[1] = vol.shape[1]
        if irange[0] == None: irange[0] = 0
        if jrange[0] == None: jrange[0] = 0

        nu = np.diff(irange)
        nv = np.diff(jrange)
        nw = vol.shape[2]

        u = np.linspace(0, 1, nu)
        v = np.linspace(0, 1, nv)
        w = np.linspace(0, 1, nw)

        crvs = []
        crvs.append(curve_factory.polygon(vol[i          ,jrange[0]  , 0,:].squeeze()))
        crvs.append(curve_factory.polygon(vol[i          ,jrange[0]  ,-1,:].squeeze()))
        crvs.append(curve_factory.polygon(vol[i          ,jrange[1]-1, 0,:].squeeze()))
        crvs.append(curve_factory.polygon(vol[i          ,jrange[1]-1,-1,:].squeeze()))
        crvs.append(curve_factory.polygon(vol[irange[0]  ,j          , 0,:].squeeze()))
        crvs.append(curve_factory.polygon(vol[irange[0]  ,j          ,-1,:].squeeze()))
        crvs.append(curve_factory.polygon(vol[irange[1]-1,j          , 0,:].squeeze()))
        crvs.append(curve_factory.polygon(vol[irange[1]-1,j          ,-1,:].squeeze()))
        crvs.append(curve_factory.polygon(vol[irange[0]  ,jrange[0]  , :,:].squeeze()))
        crvs.append(curve_factory.polygon(vol[irange[0]  ,jrange[1]-1, :,:].squeeze()))
        crvs.append(curve_factory.polygon(vol[irange[1]-1,jrange[0]  , :,:].squeeze()))
        crvs.append(curve_factory.polygon(vol[irange[1]-1,jrange[1]-1, :,:].squeeze()))
#        with G2('curves.g2') as myfile:
#            myfile.write(crvs)
#        print('Written curve.g2')


        if method == 'full':
            bottom = l2_fit(vol[i,          j,          0,:].squeeze(), [b1, b2], [u, v])
github sintefmath / Splipy / examples / trefoil.py View on Github external
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


### create a parametric 3D-function
def trefoil(t):
    t = np.array(t)
    return np.array([sin(t) + 2*sin(2*t), cos(t) - 2*cos(2*t), -sin(3*t)]).T

### do an adaptive best cubic spline-fit of this function
path  = curves.fit(trefoil, 0, 2*pi)

### since we know it is a closed curve, enforce this on the path
path  = path.make_periodic(0,0)

### create a sweeping curve (either a circle or square)
shape = curves.circle(r=0.2)
# shape = 16*curves.n_gon(4)

### sweep *shape along *path
srf = surfaces.sweep(path, shape)

### write results to file. Use meshlab (www.meshlab.net) to view stl-files
with STL('trefoil.stl') as f:
    f.write(srf, n=(150,30))