473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

evaluating a simple b-spline function

I've searched the net all over.
All I want to do is generate a cubic b-spline function from a set of 2-d points and evaluate it at different x. I need the kind where the curve runs through the control points (knots). I want to use it for interpolating a cumulative distribution function. I'm looking for two simple c/c++ functions:

Expand|Select|Wrap|Line Numbers
  1. void calculateBSpline(some_simple_data_type* bspline, double** source_points, int num_points);
  2.  
  3. double evaluateBSpline(some_simple_data_type* bspline, int num_points, double x);
  4.  
Where the double** is an array of points such that the x coordinate of point n is points[n][0], and the y coordinate is points[n][1]. The first function would create the spline from "source_points" and pass it back in "bspline", and the second would evaluate "bspline" at a given point "x". I imagine I can generate the inverse function just by swapping the x and y coordinates of the source_points, so that would provide me with a way of evaluating the spline at y. If not, an inverse eval would also be helpful.

In sum, my question is simple:

Expand|Select|Wrap|Line Numbers
  1. void calculateBSpline(some_simple_data_type* bspline, double** source_points, int num_points) {
  2.    <what goes here?>
  3. }
  4.  
  5. double evaluateBSpline(some_simple_data_type* bspline, int num_points, double x) {
  6.    <and what goes here?>
  7. }
  8.  
Thanks.
Dec 14 '07 #1
5 9922
Laharl
849 Expert 512MB
Note that a double** is not a 2D array. It's a pointer to a pointer, or a pointer to a 1D array. A double*[] is a 2D array. There's a good article in the Howtos on this.
Dec 14 '07 #2
To be more precise, I'm looking for how to create and evaluate a "natural cubic spline".
Dec 15 '07 #3
sicarie
4,677 Expert Mod 4TB
To be more precise, I'm looking for how to create and evaluate a "natural cubic spline".
1. Solve a specific "natural cubic spline" problem and document the steps
2. Create a general algorithm to solve any regular "natural cubic spline" problems using the documentation from the first step
3. create pseudocode from the algorithm in step 2
4. Code the pseudocode from step 3.
Dec 15 '07 #4
1. Solve a specific "natural cubic spline" problem and document the steps
2. Create a general algorithm to solve any regular "natural cubic spline" problems using the documentation from the first step
3. create pseudocode from the algorithm in step 2
4. Code the pseudocode from step 3.
Very funny.

I think step 1 is completely unnecessary, as is step 3 (why code twice?). And step 4 is essentially the same as step 2. So essentially what you're saying is "create a general algorithm to solve any regular "natural cubic spline" problems", which is obvious enough, as that's what I'm trying to do in the first place. These are the steps I would take:

1. Find the formulas necessary to solve the problem.
2. Code up the solution in C/C++.
3. Optimize the code.

The last step is unnecessary, strictly speaking, but I like to do it anyways.

In any case, I found what I was looking for on Wikipedia: http://en.wikipedia.org/wiki/Spline_interpolation . Apparently I just had to get a better idea of exactly what it was that I was looking for. For anyone else looking to solve this problem, just take the "Definition" section at the top of the article and combine it with the "Interpolation using natural cubic spline" section. That should give you enough information to code up a solution.

Thanks all for your help.
Dec 16 '07 #5
sicarie
4,677 Expert Mod 4TB
Glad you got it figured out. If you have a question with the implementation (as we are a Programming Forum...), please feel free to post that question.

Very funny.

I think step 1 is completely unnecessary, as is step 3 (why code twice?).
And I completely disagree. While you would seem to be of the more intelligent percentage of people in the world who can make the jump, it actually helps develop skills initially to break down the steps.

Anyway, as I said, if you run into a coding problem, please feel free to post it.
Dec 16 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Brian Peyton | last post by:
I need to somehow merge two separate web programs written in php together (from the user's perspective). This solution won't be perminant, I just need something done quickly. I was thinking of...
6
by: Michael L. Labbe | last post by:
Hello. I'm an experienced programmer who is evaluating learning Python if it is applicable to a few projects. The programs I am going to list are production software - they are not throwaway toy...
4
by: GGarramuno | last post by:
I have a program that expects its input in a specific format. Mainly, it expects floating-point values to be formatted in the form: 1.32 1. 3. 3.2345 In case you missed it, all floating...
3
by: DeerGuy | last post by:
This is a really, really simple question, but I so new to VBA, that I have to ask. I have an integer variable that I want to perform some actions on depending upon its value. Is the following...
2
by: main() | last post by:
Hi all, If 'a' is an array of ten characters , say char a; whenever i say 'a' in my code it means &a. (except in sizeof operator). Then why is &a is same as &a and not &(&a) ?
4
by: pinkfloydhomer | last post by:
We might use the normal preprocessor something like this #define WIDTH 42 #define HEIGHT 100 #define AREA (WIDTH*HEIGHT) To have "42*100" is inserted in the code whereever AREA is used. But...
7
by: bvdp | last post by:
Is there a simple/safe expression evaluator I can use in a python program. I just want to pass along a string in the form "1 + 44 / 3" or perhaps "1 + (-4.3*5)" and get a numeric result. I can...
7
by: bvdp | last post by:
I'm finding my quest for a safe eval() quite frustrating :) Any comments on this: Just forget about getting python to do this and, instead, grab my set of values (from a user supplied text file)...
3
by: Stef Mientki | last post by:
hello, I'm trying to create a high level debugger, based on rpd2. So when the debugger enters a breakpoint, I want to display the values of all variables in the, let's say, 5 lines above the...
25
by: Brian | last post by:
I have a datetimepicker formated for just time, the user selects the time. I want to compare if that time is between midnight and 8 am dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM# this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.