8000 Double-check NURBS logic · Issue #142 · ufbx/ufbx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Double-check NURBS logic #142
Open
Open
@bqqbarbhg

Description

@bqqbarbhg

This loop seems quite suspicious:

weights[0] = 1.0f;
for (size_t p = 1; p <= degree; p++) {

    ufbx_real prev = 0.0f;
    ufbx_real g = 1.0f - ufbxi_nurbs_weight(&knots, knot - p + 1, p, u);
    ufbx_real dg = 0.0f;
    if (derivatives && p == degree) {
        dg = ufbxi_nurbs_deriv(&knots, knot - p + 1, p);
    }

    for (size_t i = p; i > 0; i--) {
        ufbx_real f = ufbxi_nurbs_weight(&knots, knot - p + i, p, u);
        ufbx_real weight = weights[i - 1];
        weights[i] = f*weight + g*prev;

        if (derivatives && p == degree) {
            ufbx_real df = ufbxi_nurbs_deriv(&knots, knot - p + i, p);
            if (i < num_derivatives) {
                derivatives[i] = df*weight - dg*prev;
            }
            dg = df;
        }

        prev = weight;
        g = 1.0f - f;
    }

    weights[0] = g*prev;
    if (derivatives && p == degree) {
        derivatives[0] = -dg*prev;
    }
}

this would seem to be correct theoretically:

weights[0] = 1.0f;
for (size_t p = 1; p <= degree; p++) {

    ufbx_real prev = 0.0f;
    ufbx_real g = 1.0f - ufbxi_nurbs_weight(&knots, knot, p, u);
    ufbx_real dg = 0.0f;
    if (derivatives && p == degree) {
        dg = ufbxi_nurbs_deriv(&knots, knot - p + 1, p);
    }

    for (size_t i = p; i > 0; i--) {
        ufbx_real f = ufbxi_nurbs_weight(&knots, knot - p + i - 1, p, u);
        ufbx_real weight = weights[i - 1];
        weights[i] = f*weight + g*prev;

        if (derivatives && p == degree) {
            ufbx_real df = ufbxi_nurbs_deriv(&knots, knot - p + i - 1, p);
            if (i < num_derivatives) {
                derivatives[i] = df*weight - dg*prev;
            }
            dg = df;
        }

        prev = weight;
        g = 1.0f - f;
    }

    weights[0] = g*prev;
    if (derivatives && p == degree) {
        derivatives[0] = -dg*prev;
    }
}

However, the previous formulation does pass all tests, which is curious. Ideally would need to make a test case that would break the old implementation, assuming that it is in fact broken.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0