gpt4 book ai didi

c++ - 平滑步函数

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:19:18 26 4
gpt4 key购买 nike

我正在尝试通过使用 AMD 提供的 Smoothstep 函数获得一些结果以绘制在图表上,该函数位于此维基百科页面 Smoothstep .使用;

A C/C++ example implementation provided by AMD[4] follows.

float smoothstep(float edge0, float edge1, float x)
{
// Scale, bias and saturate x to 0..1 range
x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
// Evaluate polynomial
return x*x*(3 - 2 * x);
}

问题是由于 static method clamp 不可用,我无法使用此方法。

我已经导入了以下内容;

#include <math.h> 
#include <cmath>
#include <algorithm>

但是还没有定义clamp方法。

我的数学能力不是最好的,但是有没有办法像实现 LERP 函数 一样实现 Smoothstep 函数

float linearIntepolate(float currentLocation, float Goal, float time){

return (1 - time) * currentLocation + time * Goal;
}

最佳答案

也许只是缺少命名空间“std”:这是我编译的代码:

#include <algorithm>

float smoothstep(float edge0, float edge1, float x) {
// Scale, bias and saturate x to 0..1 range
x = std::clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
// Evaluate polynomial
return x * x * (3 - 2 * x);
}

关于c++ - 平滑步函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28889210/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com