Jump to content

Mathematical/programming Problem


Anonymouse
 Share

Recommended Posts

I'm trying to interpolate one value into another using a sine function in a specified number of steps. Could anyone help me with this? I'm going to write it in C, so C, pseudocode or an explanation (best because it'll help me solve problems like this myself in future) will both do :)

Thanks in advance for any help or hints you can give me :)

Link to comment
Share on other sites

Could you give more information on what exactly you are trying to do... Because interpolation is a statistical tool, and why you are using a sine function doesn't hit me. Interpolation (generally) happens with 2 or more values.

If you need it for a 3D coordinate system I probably can't be of any help.

Link to comment
Share on other sites

I have two values. A and B, say. I want to interpolate A into B with x steps. Get it, sort of? I'm not really savvy with the correct vocabulary here, sorry >_>

Link to comment
Share on other sites

You mean like combine 2 values into one with a certain amount of steps? And find a way to split the value into 2 again depending on the number of steps?

Is that what you're asking, or no? Interpolation is when you have a set of data (like x-y coordinates), and you have a value (like, say 1 x-coordinate) and you can use the trend to find its y-coordinate.

Link to comment
Share on other sites

You mean like combine 2 values into one with a certain amount of steps? And find a way to split the value into 2 again depending on the number of steps?

Is that what you're asking, or no? Interpolation is when you have a set of data (like x-y coordinates), and you have a value (like, say 1 x-coordinate) and you can use the trend to find its y-coordinate.

Let me explain what I mean by interpolation, using an example because I couldn't really do it any other way.

Linear interpolation between 0 and 10, in 5 steps, all the steps would be:

0

2

4

6

8

Problem is, I want to interpolate the values with a sine function and not linearly. For linear interpolation, the function is rather simple:

value = (end_value/step_number)*current_step

And so the line would be straight if steps were graphed against value. I want to do pretty much the same but have upwards portion after 0 of a sine curve.

Link to comment
Share on other sites

if you are wanting a sharp increase in a number, you could you use x squared, if that is any help

That would be Square interpolation, I think... But that's not what I'm looking for. I want the value to change fastest halfway through the interpolation.

Link to comment
Share on other sites

Well, you can calculate it linearly like this:

data = {1,5}

steps = 5

output = {data[1], data[1]*((steps-1)/steps) + data[2]*(1/steps), ....}

and so on (messy, and could probably do better in a loop, but whatever)

but instead of multiplying by fractions of steps, use (-cos(steps)+1) after scaling the steps linearly to be from 0 to pi.

Link to comment
Share on other sites

Well, you can calculate it linearly like this:

data = {1,5}

steps = 5

output = {data[1], data[1]*((steps-1)/steps) + data[2]*(1/steps), ....}

and so on (messy, and could probably do better in a loop, but whatever)

but instead of multiplying by fractions of steps, use (-cos(steps)+1) after scaling the steps linearly to be from 0 to pi.

I only want a function to calculate the value at a specific step, rather than pregenerating the data and calling it up later (though I'm considering doing that too, later, for even more speed :af:. Thanks for the help!

Link to comment
Share on other sites

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.