Code Monkey home page Code Monkey logo

splines-lib's People

Contributors

andrewwillmott avatar racethemase avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

splines-lib's Issues

Typo causes infinite loop

I found a little typo which causes an infinitely look when I do interesections of 3D splines that are on the z-plane. (eg Z=0)

inline bool Larger(const Bounds3f& bb, float t) { Vec3f d = bb.max - bb.min; return d.x > t || d.y > t || d.z < t; }

The check should be d.z > t;

Spline example

Can you show an example simply computing f.e. a cubic spline from points? Accoring to the test example there come always wrong results with index = -1 during the query:

int cnt = getcount(); // point count
Vec2f* in = new Vec2f[cnt]; // input points
cSpline2* splines = new cSpline2[cnt + 1]; // splines

// Make vector
for (int i = 0; i < cnt; i++) {  in[i].x = pt[i].getx(); in[i].y = p[i].gety(); }

// Splines
int numSplines = SplinesFromPoints(cnt, in, cnt + 1, splines);

// Query points from vector
for(int i = 0; i < cnt; i++)
{
  int index;
  float t = FindClosestPoint(in[i], cnt, splines, &index);
  Vec2f cp = Position(splines[index], t);
}

delete[] in;
delete[] splines;

How can I divide multiple spline by length

How can I divide multiple spline by length? I came up this code, but it seems not correct.
I divide splines by t, but Len(spline, 0.0f, 0.1f) != Len(spline, 0.1f, 0.2f), because t and length are not linear.
Please help.

float lengths[numSplines];
float remainLengths[numSplines];

for (int i = 0; i < numSplines; ++i) {
    lengths[i] = SplineLib::Length(splines[i], 0.01f);
    remainLengths[i] = lengths[i];
}

int splineIndex = 0;
float ts = 0.0f;

auto pushPoint = [&]() {
    dstPoints.emplace_back(Position(splines[splineIndex], ts));
    dstTangents.emplace_back(Velocity(splines[splineIndex], ts));
};

// push start point
pushPoint();

while (splineIndex < numSplines) {
    float step = space;
    loop:

    if (remainLengths[splineIndex] - step > 0) {
        remainLengths[splineIndex] -= step;
        ts += step / lengths[splineIndex];
        pushPoint();
    } else {
        step = step - remainLengths[splineIndex];
        ts = 0.0f;
        splineIndex++;
        if (splineIndex >= numSplines) {
            break;
        } else {
            goto loop;
        }
    }
}

Edit:

I use SplineLib::SubdivideForT to make t and length close to linear. It produce much many splines and reduce performance a lot. Is there a better way to achieve this? Best regards!

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.