How to use the splipy.Curve 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 / curve_factory.py View on Github external
if normalized:
                        v /= norm(v)
                    argv[j] = v
                elif arg_names[j] == 'a':
                    a = crv.derivative(t1, 2)
                    if b.continuity(t1) < 2:
                        a += crv.derivative(t1, 1, above=False)
                        a /= 2.0
                    if normalized:
                        a /= norm(a)
                    argv[j] = a
            destination[i] = f(*argv)

    N = b(t, sparse=True)
    controlpoints = splinalg.spsolve(N, destination)
    return Curve(b, controlpoints)
github sintefmath / Splipy / splipy / curve_factory.py View on Github external
:return: Interpolated curve
    :rtype: Curve
    """
    # wrap input into an array
    x = np.array(x)

    # evaluate all basis functions in the interpolation points
    if t is None:
        t = basis.greville()
    N = basis.evaluate(t, sparse=True)

    # solve interpolation problem
    cp = splinalg.spsolve(N, x)
    cp = cp.reshape(x.shape)

    return Curve(basis, cp)
github sintefmath / Splipy / splipy / curve_factory.py View on Github external
"""
    if r <= 0:
        raise ValueError('radius needs to be positive')
    if n < 3:
        raise ValueError('regular polygons need at least 3 sides')

    cp = []
    dt = 2 * pi / n
    knot = [-1]
    for i in range(n):
        cp.append([r * cos(i * dt), r * sin(i * dt)])
        knot.append(i)
    knot += [n, n+1]
    basis = BSplineBasis(2, knot, 0)

    result =  Curve(basis, cp)
    return flip_and_move_plane_geometry(result, center, normal)
github sintefmath / Splipy / splipy / io / spl.py View on Github external
orders = [int(k) for k in islice(lines, pardim)]
        ncoeffs = [int(k) for k in islice(lines, pardim)]
        totcoeffs = int(np.prod(ncoeffs))
        nknots = [a + b for a, b in zip(orders, ncoeffs)]

        next(lines) # Skip spline accuracy

        knots = [[float(k) for k in islice(lines, nkts)] for nkts in nknots]
        bases = [BSplineBasis(p, kts, -1) for p, kts in zip(orders, knots)]

        cpts = np.array([float(k) for k in islice(lines, totcoeffs * physdim)])
        cpts = cpts.reshape(physdim, *(ncoeffs[::-1])).transpose()

        if pardim == 1:
            patch = Curve(*bases, controlpoints=cpts, raw=True)
        elif pardim == 2:
            patch = Surface(*bases, controlpoints=cpts, raw=True)
        elif pardim == 3:
            patch = Volume(*bases, controlpoints=cpts, raw=True)
        else:
            patch = SplineObject(bases, controlpoints=cpts, raw=True)

        return [patch]
github sintefmath / Splipy / splipy / Surface.py View on Github external
# clone basis since we need to augment this by knot insertion
        b    = self.bases[direction].clone()

        # compute mapping matrix C which is the knotinsertion operator
        mult = min(b.continuity(knot), b.order-1)
        C    = np.identity(self.shape[direction])
        for i in range(mult):
            C = b.insert_knot(knot) @ C

        # at this point we have a C0 basis, find the right interpolating index
        i  = max(bisect_left(b.knots, knot) - 1,0)

        # compute the controlpoints and return Curve
        cp = np.tensordot(C[i,:], self.controlpoints, axes=(0, direction))
        return Curve(self.bases[1-direction], cp, self.rational)
github sintefmath / Splipy / splipy / curve_factory.py View on Github external
if r <= 0:
        raise ValueError('radius needs to be positive')

    if type == 'p2C0' or type == 'C0p2':
        w = 1.0 / sqrt(2)
        controlpoints = [[1, 0, 1],
                         [w, w, w],
                         [0, 1, 1],
                         [-w, w, w],
                         [-1, 0, 1],
                         [-w, -w, w],
                         [0, -1, 1],
                         [w, -w, w]]
        knot = np.array([-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5]) / 4.0 * 2 * pi

        result = Curve(BSplineBasis(3, knot, 0), controlpoints, True)
    elif type.lower() == 'p4c1' or type.lower() == 'c1p4':
        w = 2*sqrt(2)/3
        a = 1.0/2/sqrt(2)
        b = 1.0/6 * (4*sqrt(2)-1)
        controlpoints = [[ 1,-a, 1],
                         [ 1, a, 1],
                         [ b, b, w],
                         [ a, 1, 1],
                         [-a, 1, 1],
                         [-b, b, w],
                         [-1, a, 1],
                         [-1,-a, 1],
                         [-b,-b, w],
                         [-a,-1, 1],
                         [ a,-1, 1],
                         [ b,-b, w]]
github sintefmath / Splipy / splipy / io / svg.py View on Github external
else:                          # scale by x-coordinate
            marginPixels = self.width*self.margin
            self.scale   = self.width*(1-2*self.margin) / (boundingbox[2]-boundingbox[0])
            self.height  = self.width*geometryRatio + 2*marginPixels
        self.center      = [boundingbox[0], boundingbox[1]]
        self.offset      = [marginPixels, marginPixels]

        # create xml root tag
        self.xmlRoot = etree.Element('svg',  {'xmlns':'http://www.w3.org/2000/svg',
                                              'version':'1.1',
                                              'width':str(self.width),
                                              'height':str(self.height)})

        # populate tree with all curves and surfaces in entities
        for entry in self.all_objects:
            if isinstance(entry, Curve):
                self.write_curve(self.xmlRoot, entry)
            elif isinstance(entry, Surface):
                self.write_surface(entry)

        # if no objects are stored, then we've most likely only called read()
        if len(self.all_objects) > 0:
            rough_string = etree.tostring(self.xmlRoot) # entire xml-file on one line
            reparsed     = minidom.parseString(rough_string)
            result       = reparsed.toprettyxml(indent="  ") # adds newline and inline
            f = open(self.filename, 'w')
            f.write(result)
github sintefmath / Splipy / splipy / utils / NACA.py View on Github external
for i in range(n):
        if t[i] <= P:
            if order > 4:
                x[i, 0] = t[i]**2 / P
            else:
                x[i, 0] = t[i]
            x[i, 1] = M / P / P * (2 * P * x[i, 0] - x[i, 0] * x[i, 0])
        else:
            if order > 4:
                x[i, 0] = (t[i]**2 - 2 * t[i] + P) / (P - 1)
            else:
                x[i, 0] = t[i]
            x[i, 1] = M / (1 - P) / (1 - P) * (1 - 2 * P + 2 * P * x[i, 0] - x[i, 0] * x[i, 0])
    N = basis.evaluate(t)
    controlpoints = np.linalg.solve(N, x)
    return Curve(basis, controlpoints)
github sintefmath / Splipy / splipy / curve_factory.py View on Github external
"""
    if quadratic:
        p = 3
    else:
        p = 4
    # compute number of intervals
    n = int((len(pts)-1)/(p-1))
    # generate uniform knot vector of repeated integers
    knot = list(range(n+1)) * (p-1) + [0, n]
    knot.sort()
    if relative:
        pts = copy.deepcopy(pts)
        for i in range(1, len(pts)):
            pts[i] = [x0 + x1 for (x0,x1) in zip(pts[i-1], pts[i])]
    return Curve(BSplineBasis(p, knot), pts)