MathHelper.Lerp C#(线性插值)

发布于 2025-01-07 07:16:31 字数 522 浏览 5 评论 0原文

我在使用这个函数时遇到一个小问题,MathHelper.Lerp(float f1, float f2, float amount)。我想要完成的是:我的程序中有一个数据表,其中包含角度和与该角度值相对应的值。当您选择表中不存在的角度时,我想使用线性插值来管理它。我想要一些东西来替换我的第一个实现,如下所示:

else if(angle >= 50 && marklast < 65)
        {
            DataRow row1 = table.Rows.Find(50);
            DataRow row2 = table.Rows.Find(65);
            someVariable = SomeMethod(row1, row2);
        }

所以现在我有很多这样的 If 语句,并且想要使用 MathHelper.Lerp 的其他方法来执行此操作,问题是我我很难获得该功能,金额是多少?您会为了我的实施而以一种好的方式修改它吗?

I'm having a small problem with this function, MathHelper.Lerp(float f1, float f2, float amount). What I'm trying to accomplish is this: I'm having a DataTable in my program with angles and a value correspinding towards this angle value. When you choose an angle not present in the Table I want to use Linear Interpolation to manage this. I want something to replace my first implementation of this which looked like this:

else if(angle >= 50 && marklast < 65)
        {
            DataRow row1 = table.Rows.Find(50);
            DataRow row2 = table.Rows.Find(65);
            someVariable = SomeMethod(row1, row2);
        }

So now I have a lot of these If statments and would like an other way of doing this with the MathHelper.Lerp, problem is I'm having a hard time getting the function, what is amount? And would you modify this in a good way for my implementation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶气 2025-01-14 07:16:31

金额是 0..1 范围内的值。

if it is 0 lerp return source value, 
if it is 1 lerp return target value, 
if it is a value between 0..1 lerp will return a linear interpolated value between the source and the target values. 

我不确定你想要做什么...我认为是这样的:

Amount = (angle - 50)/(65-50);
InterpolatedValue = MathHelper.Lerp(row1.Value, row2.Value, Amount);

Amount is a value in 0..1 range.

if it is 0 lerp return source value, 
if it is 1 lerp return target value, 
if it is a value between 0..1 lerp will return a linear interpolated value between the source and the target values. 

I'm not sure you want to do... I think is something like this:

Amount = (angle - 50)/(65-50);
InterpolatedValue = MathHelper.Lerp(row1.Value, row2.Value, Amount);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文