Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / interpolate curved line through a series of points?

Author
Message
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Apr 2011 12:38 Edited at: 25th Apr 2011 12:39
The red line represents a typical way to connect dots together. The green line represents how I would like to draw a curve line approximately through those points. Any thoughts?



TechLord
23
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 25th Apr 2011 14:36 Edited at: 25th Apr 2011 14:38
Google Bezier Curve. I'll see if I can find a user friendly tut.

Morcilla
23
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 25th Apr 2011 17:34
DBPro has commands for that. Take a look to the 'hermite vector2' documentation.
Here is an example by Hamish McHaggis: Hermite Spline Interpolation

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 25th Apr 2011 18:36 Edited at: 25th Apr 2011 18:36
If I'm not mistaking, then Bezier Curves, as well as the Hermite Vector2 example need the tangents at the all points to draw. It is possible to make some kind of algorithm that tries to find the best tangents, but if you want to find a true approximation, you're up to quite a challenge.

In any case, finding the best curve through a series of points and interpolation are two (pretty much completely) separate things. In your example image, the curve doesn't go through the points, which would mean you're trying to find some kind of best curve. Using interpolation algorithms will make the curve always go through the points.

Interpolation
Interpolation allows you to approximate values between two measured points. In other words, the problem we're trying to solve when dealing with interpolation is: We have some measured points, how can we approximate the values at unmeasured points (using the measured ones as a reference).

A part from Bezier and Hermite, you can also use
Lagrange Polynomials - They usually don't give good results.
Hermite Polynomials - Give better results, but you need to know the tangents in each point as well.
Cubic Spline Interpolation - The graph that goes through all those points is not given by one equation. It's one cubic polynomial equation per 3 points (if I remember correctly). They usually give the smoothest results. The system of equations is quite large (dimension is the same as the number of points), but the associated matrix is tridiagonal making it much easier to solve.

Finding the best Curve
In this case, we know the equation of the graph that should go through all the points, unless for some parameters. Now we want to know these parameters so that the error (distance of the points to the graph) is minimal. It is usually achieved by using the least square approximation.

I'm not sure how deep I should go in this. The basic solutions are
Linear Regression - The most basic problem for this.
Fourier Transforms (FFT) can also be used to approximate points.

Cheers!
Sven B

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Apr 2011 19:03
I use a C-Spline calculation for my bezier curves (although I don't know if they are technically bezier if I use a C-spline Calc?) The reason being, I can fine-tune the curve by adjusting the 2 points connecting each node on the curve. So you can sharpen or smooth the curve by editing the distance, you can also have a sharp entry, smooth exit, etc by making the points asymmetrical.

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th Apr 2011 01:22
FFT would probably be too slow as the points are constantly changing. I've done bezier and hermite splines before and Sven is right, without calculate the tangents, it wouldn't really work.

I'll look up linear regression and c-spline.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 26th Apr 2011 01:39 Edited at: 26th Apr 2011 01:40
Wow! Some points here I've never have thought of but I was more thinking of the way simple AI path nodes would work. All depending on whether your movement is going towards or away from the next node. You could google path following AI or anything to do with that.

EDIT: Okay so that's not what it was about... he he

Warning! May contain Nuts!
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 26th Apr 2011 07:03 Edited at: 26th Apr 2011 07:07
CUBIC INTERPOLATION!


http://www.youtube.com/watch?v=xdMLNZXw7PY&t=2m50s

[edit]
I don't think it's a function regression you're looking for.


Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th Apr 2011 08:46
Yes, that looks good Neuro, thanks. If you check out my amoeba snippet you might figure out what im doing.

Login to post a reply

Server time is: 2026-07-11 12:20:37
Your offset time is: 2026-07-11 12:20:37