obj-c 两个数字之间的线性插值

发布于 2024-08-13 04:03:01 字数 267 浏览 3 评论 0原文

只是想知道是否已经实现了一些方法来处理基础/Xcode 附带的其他内容中两个数字之间的线性插值?自己实现并不是一件高级的事情,但我通常发现自己重新实现已经实现的东西,并且使用已经存在的功能很好(而且它更加标准化)。

所以我想要的是这样的:

lerp(number1, number2, numberBetween0And1);

// Example:
lerp(0.0, 10.0, .5); // returns 5.0

它存在吗?

Just wondering if there are methods already implemented for handling linear interpolation between two numbers in foundation/something else that comes with Xcode? It's hardly an advanced thing to implement yourself, but I usually find myself reimplementing things that have already been implemented, and it's nice to use functionality that already exists (plus it's more standardized).

So what I'd like is something like this:

lerp(number1, number2, numberBetween0And1);

// Example:
lerp(0.0, 10.0, .5); // returns 5.0

Does it exist?

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

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

发布评论

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

评论(1

短叹 2024-08-20 04:03:01

不,但这是一句简单的话:

inline double lerp(double a, double b, double t)
{
    return a + (b - a) * t;
}

inline float lerpf(float a, float b, float t)
{
    return a + (b - a) * t;
}

No, but it's an easy one-liner:

inline double lerp(double a, double b, double t)
{
    return a + (b - a) * t;
}

inline float lerpf(float a, float b, float t)
{
    return a + (b - a) * t;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文