No announcement yet.

Need a little help with Splines/Curves

  • Filter
  • Time
  • Show
Clear All
new posts

  • Need a little help with Splines/Curves

    Hey Guys,

    I was wondering if someone could help me out with Splines/Curves. First off, I'm not exactly what you would call a math wiz

    Ok so this is what I need:

    A function that returns the Y coordinate for a given X coordinate and a variable list of control points. The function definition would look something like this:

    Y = Spline(X, XControlPoints(), YControlPoints(), Tension)

    It would be really great if the returned Y coordinates would pass through each control point instead of swinging past them like a bezier curve does.

    I'm not asking anyone to write this for me but rather just point me in the right direction. If however you already have a function that does this I would be very grateful if you could share it.

    Like I wrote above, I'm not very good with math so most of these math websites don't make much sense to me.

    Start as you mean to go on.

  • #2
    Look up polynomial interpolation.
    Last edited by Mark Hunter; 17 Oct 2007, 01:09 PM. Reason: Link removed.
    Algorithms - interesting mathematical techniques with program code included.


    • #3

      Hey Mark,

      Thanks for the link, I really appreciate your effort.

      The problem is, I'm not very good with math. I spent the past few hours reading and I just don't get it. All these math terms and symbols are WAY over my head. I can't even begin to think of translating this stuff from "math" syntax to basic.

      Anyone else have any links or advise?

      Start as you mean to go on.


      • #4
        Cubic Spline Library

        Mark, try this one. I don't know if it contains exactly what you want, but there are examples.
        (Don Lancaster's Guru's Lair Cubic Spline Library)

        [Added later]This article seems close to what you want:
        Don Lancaster tutorial and demo shows how to find y values for x values of a cubic spline.

        regards, Ian
        Last edited by Ian Cairns; 17 Oct 2007, 11:35 AM.
        :) IRC :)


        • #5

          If you are generating a spline curve through multiple points the way to do this is to construct a piecewise composite curve that is in reality a bunch of smaller curves strung together. To do this you must make certain that continuity is maintained at your control points from the previous curve to the next curve. By continuity I mean that the curve flows from one control point to another without a sharp jog at any control point. Normally this is done by defining a vector at the end of the previous curve that is also used as the beginning vector for the next curve.


          "When governments fear the people there is liberty. When people fear the government there is tyranny." - Thomas Jefferson


          • #6
            To get the actual theory, many good engineering texts have it, and there is always the excellent reference "Numercal Recipies".

            Failing that, I will try to dig out one of my spline codes.


            andrew dot lindsay at westnet dot com dot au


            • #7
              Still here

              Hey guys,

              Thanks for the links and ideas so far. I'm still here and investigating them. My wife and I are expecting within the next couple of weeks so time is a little on the short side.

              If you have any other ideas please keep them coming as I can't be the only one who would find this interesting

              Start as you mean to go on.


              • #8
                Yes, you need a Cubic Spline Interpolation. I have a great Powerbasic implementation of one I wrote a few years ago.
                I posted it here so I can attach the executable to the post

                The Demo uses the excellent native PB graphing tools to draw the spline between 4 points on a graph.
                The points are chosen such that the spline has to change direction rapidly forcing it to exhibit its mechanical bending properties.

                Perhaps one fo the ASM guys might even speed it up.


                • #9
                  Thanks Mike

                  Hey Mike,

                  Thanks for the source/demo. I had a look at it last night and it looks pretty good. I'm going to play around with it a bit later today again.

                  Thanks again everyone
                  Start as you mean to go on.