Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

Connect points to create a smooth curve

I have a list of X and Y coordinates where the peak of each "hill" should be. The end result will be a graph of sorts that will have a line tracing through and hitting each point exactly. Each pair of values will also have one number specifying the steepness of its respective hill. Where there are no points, the graph will stay at zero.

I have been experimenting with many ideas, and the most developed one that I have come up with is this: Say there is only one point specified. The graph will stay at zero until the bottom of the curve, where there will be a cosine wave that travels upward, passes through the specified point, and then continues steadily down to zero again. Where there are two hills that are close to each other, there should be a smooth transition from the hill of one point to the hill of another (this is where I have the issues). If I pick out the point where the two waves clash, then pick an interval immediately surrounding that point and mark it off, I can find the slopes of the two waves at those specific points, and then find a quadratic equation that meets at those points and splice it in between.

If you are having trouble understanding what I am trying to do, please post a comment about what is unclear in my post.

The end result should be somewhat like the equalizer in WinAmp. As you drag the sliders up and down, a curve is generated right above that passes through each slider's respective point and then moves on toward the next point, never breaking the smooth curve from before.

Any help would be greatly appreciated. I am only taking a pre-calculus course, so any advanced mathematics will have to be explained. This question is not urgent, but the sooner you can get back with a response, the better.

Thank you in advance!

~Tom

(Sorry for any misspellings or other errors.. I have no time to check over my post. ;)
0
VBTom
Asked:
VBTom
  • 3
  • 2
1 Solution
 
ozoCommented:
It sounds like what you want are cubic splines
0
 
VBTomAuthor Commented:
Do you have any references or examples of code that does this?

~Tom
0
 
ozoCommented:
Given the points (x(-1),y(-1)) (x(0),y(0)) (x(1),y(1)) (x(2),y(2))
the curve between (x(0),y(0)) (x(1),y(1)) is given by
a(x-x0)^3 + b(x-x0)^2 + c(x-x0) + d
where
d = y(0)
c = y(1)/2-y(-1)/2
b = -y(2)/2 + 2y(1) - 5y(0)/2 + y(-1)
a = y(2)/2 - 3y(1)/2 + 3y(0)/2 - y(-1)/2
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ozoCommented:
in C
#include <stdio.h>
float interpolate(float y[], float s){
    float u0,u1,u2,u3;;
    float t;
    u0=y[0];
    u1=y[0]+(y[1]-y[-1])/3;
    u2=y[1]+(y[0]-y[2])/3;
    u3=y[1];
    t=1.0-s;
    return
      t*t*t*u0+
      3*t*t*s*u1+
      3*t*s*s*u2+
      s*s*s*u3;
 }
/*float y[]={0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0};*/
float y[]={0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0};
main(){
    int i;
    for( i=1;i<(sizeof(y)/sizeof(y[0]))-2; i++ ){
        int s;
        for(s=0;s<10;s++){
            printf("%6.3f ",interpolate(&y[i],s/10.0));
        }
        printf("\n");
    }
}
0
 
CleanupPingCommented:
VBTom:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
VBTomAuthor Commented:
I'm really sorry about taking so long. Apparently there was a period where I wasn't receiving EE e-mails. :(

~Tom
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now