旋转插补 [英] Rotation Interpolation

查看:88
本文介绍了旋转插补的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我将纯粹以简单度,弧度,度,不同的零轴承为单位提出这个问题,这个问题本质上是相同的.

NB: I'll present this question in degrees purely for simplicity, radians, degrees, different zero-bearing, the problem is essentially the same.

有人对旋转插值背后的代码有任何想法吗?给定一个线性插值函数:Lerp(from,to,amount),其中amount为0 ... 1,该值返回一个介于from和to之间的值(按数量).如何将相同的函数应用于0到360度之间的旋转插值?鉴于度数不应在0和360之外返回.

Does anyone have any ideas on the code behind rotational interpolation? Given a linear interpolation function: Lerp(from, to, amount), where amount is 0...1 which returns a value between from and to, by amount. How could I apply this same function to a rotational interpolation between 0 and 360 degrees? Given that degrees should not be returned outside 0 and 360.

给出该单位圆的度数:

其中从= 45到= 315,算法应采用最短的角度路径,即应该经过零,然后到达360,然后到达315-而不是一直绕90、180、270到315

where from = 45 and to = 315, the algorithm should take the shortest path to the angle, i.e. it should go through zero, to 360 and then to 315 - and not all the way round 90, 180, 270 to 315.

是否有实现此目的的好方法?还是将if()块弄得一团糟?我是否错过了一些很好理解的标准方法? 任何帮助将不胜感激.

Is there a nice way to achieve this? Or is it going to just be a horrid mess of if() blocks? Am I missing some well understood standard way of doing this? Any help would be appreciated.

推荐答案

我知道这已经2岁了,但是最近我一直在寻找相同的问题,如果没有ifs发布,我不会看到一个优雅的解决方案在这里,就这样:

I know this is 2 years old, but I've recently been looking around for the same problem and I don't see an elegant solution without ifs posted in here, so here it goes:

    shortest_angle=((((end - start) % 360) + 540) % 360) - 180;
    return start + (shortest_angle * amount) % 360;

就这样

ps:当然,%表示模,而shortest_angle是保存整个插值角的变量

ps: of course, % is meaning modulo and shortest_angle is the variable that holds the whole interpolation angle

这篇关于旋转插补的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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