0

我有两个数据点,x 轴是一个整数,y 轴需要是一个设定限制内的浮点数,比如从 0.00f 到 1.00f。

我很想在两点之间绘制一条可调整的曲线,默认的调整参数(比如 1.0f)会产生一条直线。

因此,例如,我得到了任何两个数据点,例如;

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
}

我想我可能必须在循环期间使用“曲线参数”在数学上调整变量 yDiff,因此它要么开始缓慢增加,然后更快,越来越快,反之亦然,或者开始变慢,中间快,然后再次变慢,反之亦然。

4

0 回答 0