GithubHelp home page GithubHelp logo

Comments (9)

carlos-adir avatar carlos-adir commented on May 26, 2024 1

I made a nurbs library which computes the remove_knot by fitting the curve into another.

That is, since we know the knotvector before and after removal, we have the basis functions and we can find the best control points that approximates the curve with more knots.

For this example, the 'approximation' is in fact the original curve before knot insertion.

It's better described here:
https://compmec-nurbs.readthedocs.io/en/latest/rst/theory-fitting.html

from nurbs-python.

carlos-adir avatar carlos-adir commented on May 26, 2024

I made a test function with a random number of insert at random positions

from geomdl import BSpline
from geomdl.operations import insert_knot, remove_knot
import numpy as np

def test_curve_insertremove_oneknot_random():
    ntests = 1000
    dim = 3
    for i in range(ntests):
        p = np.random.randint(1, 6)
        n = np.random.randint(p+1, p+11)
        ctrlpts = np.random.rand(n, dim).tolist()
        curve = BSpline.Curve()
        curve.degree = p
        curve.ctrlpts = ctrlpts
        curve.knotvector = p*[0] + list(np.linspace(0, 1, n-p+1)) + p*[1]

        knot = np.random.rand()
        times = np.random.randint(1, max(2, p))
        insert_knot(curve, [knot], [times])
        remove_knot(curve, [knot], [times])
        np.testing.assert_allclose(curve.ctrlpts, ctrlpts)

from nurbs-python.

cafhach avatar cafhach commented on May 26, 2024

Why should the resulting control points be identical to the initial ones?

from nurbs-python.

portnov avatar portnov commented on May 26, 2024

Well, because knot insertion and knot removal are the opposite processes for one another, so they should cancel each other, shouldn't they? :)

from nurbs-python.

portnov avatar portnov commented on May 26, 2024

As far as I understood, implementation of knot insertion and removal processes in geomdl is taken directly from The NURBS Book. Unfortunately, the book has a number of typos :/

from nurbs-python.

cafhach avatar cafhach commented on May 26, 2024

They appear to be opposite processes, but are they really wrt the control points?

from nurbs-python.

portnov avatar portnov commented on May 26, 2024

IMHO they should be. Refer to The NURBS Book, 2nd ed, p. 5.4.

from nurbs-python.

portnov avatar portnov commented on May 26, 2024

In Sverchok, for example, this test works: https://github.com/nortikin/sverchok/blob/master/tests/nurbs_tests.py#L422
Note that in Sverchok insertion and removal of a knot several times is implemented very straightforward, by repeating the whole procedure several times. In the NURBS Book there is an algorithm which requires less calculations, but as far as I understood there are typos there — at least it did not work correctly for me right away; I tried to debug it for some time, but in the end I just reverted to the dumb but working algorithm.

from nurbs-python.

carlos-adir avatar carlos-adir commented on May 26, 2024

I don't understand why this issue was closed as completed since it still a problem

from nurbs-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.