两个数字之间的obj-c线性插值 [英] obj-c linear interpolation between two numbers

查看:60
本文介绍了两个数字之间的obj-c线性插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

它存在吗?

推荐答案

不,但它很简单:

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;
}

这篇关于两个数字之间的obj-c线性插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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