How to plot an adjustable curve between two points (x axis integer, y axis is float) via C/C++ code

230 views Asked by At

I got two data points, x axis is an integer, and y axis needs to be a float within a set limit, say from 0.00f to 1.00f.

I would love to plot an adjustable curve between the two points, with the default adjusting parameter (say at 1.0f) resulting in just a straight line.

So for example I got any two data points such as;

int x1 = 0; float y1 = 0.25f;
int x2 = 49; float y2 = 0.75f;

float yDiff = (y2 - y1) / (x2 - x1);

float dataPointArray[50];

for (int i = x1; i <= x2; i++)
{
  y1 += yDiff;

  dataPointArray[i] = y1; // This just plots a straight line

  dataPointArray[i] = atan (y1); // This plots a set curved line, although it 
                                 // does go out of bounds,
                                 // which I can easily adjust (center) after.

  dataPointArray[i] = pow (y1, ac); // Had hoped this would plot an adjustable
                                    // curve, with ac of 1 being no curve, 
                                    // and ac of 0.5f and ac of 2.0f being
                                    // curves, but float values goes WAY out of bounds
}

I figure I probably have to mathematically adjust the variable yDiff during the loop, with a "curve parameter" so it either starts to increment slow, then faster, and faster, or vice-versa, or starts slows, fast in the middle, then slow again, or vice-versa.

0

There are 0 answers