使用点生成二次方程来插值数据 [英] Using points to generate quadratic equation to interpolate data

查看:77
本文介绍了使用点生成二次方程来插值数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用二次曲线为游戏提供灵活的衰减评分系统。我可能会粗暴地通过它,但是想知道是否有人可以帮我提出一些灵活的东西,或者可能已经有一些现成的解决方案了!

I'm trying to come up with a flexible decaying score system for a game using quadratic curves. I could probably brute force my way through it but was wondering if anyone can help me come up with something flexible or maybe there are some ready made solutions out there already!

但是基本上我需要能够生成a,b和amp;的值。 c in:

But basically I need the ability to generate the values of a,b & c in:

y = ax^2 + bx + c

从3个点开始(我知道它位于有效的二次曲线上,但是基于可配置的设置和对事件作出反应的最大时间是动态的)例如:( - 1100,0),(200,1),(1500,0)。

from 3 points (which i know fall on a valid quadratic curve, but are dynamic based on configurable settings and maximum times to react to an event) for example: (-1100, 0), (200, 1), (1500, 0).

因此我可以插入x的值来生成Y值,这将决定得分我给用户。

So I can then plugin in values for x to generate values of Y which will determine the score I give the user.

如果我能用一个固定的二次方程式,我会得到但得分是根据用户对特定时间做出多少反应event(X Axis)y轴点始终在0和1之间,0表示最低分,1表示最高分!

If I could get away with a fixed quadratic equation I would but the scoring is based on how much time a user has to react to a particular event (X Axis) the y axis points will always be between 0 and 1 with 0 being minimum score and 1 being maximum score!

如果您需要更多信息,请告诉我!

Let me know if you need more info!

推荐答案

您可以使用拉格朗日多项式插值,曲线​​由

You can use Lagrange polynomial interpolation, the curve is given by

y(x) = y_1 * (x-x_2)*(x-x_3)/((x_1-x_2)*(x_1-x_3))
     + y_2 * (x-x_1)*(x-x_3)/((x_2-x_1)*(x_2-x_3))
     + y_3 * (x-x_1)*(x-x_2)/((x_3-x_1)*(x_3-x_2))

如果您收集系数,则获得

If you collect the coefficients, you obtain

a = y_1/((x_1-x_2)*(x_1-x_3)) + y_2/((x_2-x_1)*(x_2-x_3)) + y_3/((x_3-x_1)*(x_3-x_2))

b = -y_1*(x_2+x_3)/((x_1-x_2)*(x_1-x_3))
    -y_2*(x_1+x_3)/((x_2-x_1)*(x_2-x_3))
    -y_3*(x_1+x_2)/((x_3-x_1)*(x_3-x_2))

c = y_1*x_2*x_3/((x_1-x_2)*(x_1-x_3))
  + y_2*x_1*x_3/((x_2-x_1)*(x_2-x_3))
  + y_3*x_1*x_2/((x_3-x_1)*(x_3-x_2))

这篇关于使用点生成二次方程来插值数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆