gpt4 book ai didi

math - 计算 > 360 度的旋转。情况

转载 作者:行者123 更新时间:2023-12-01 13:06:52 26 4
gpt4 key购买 nike

我正在尝试解决我在学位方面遇到的问题。我的数据是角度列表,采用标准度数表示法——例如26 度。

通常在处理角度时,如果角度超过 360 度,则该角度继续旋转并有效地“重置”——即角度“重新开始”,例如357 度、358 度、359 度、0 度、1 度等。我想要的是度数继续增加——即 357 度、358 度、359 度、360 度、361 度等。我想要修改我的数据,以便我在其中包含此转换后的数据。

当数字接近 0 度极限时,我希望它们变为负数——即 3 度、2 度、1 度、0 度、-1 度、-2 度等。

对于 360 度的倍数(正和负),我希望度数继续,例如720度等

关于采取什么方法有什么建议吗?毫无疑问,有一种令人沮丧的简单方法可以做到这一点,但我目前的解决方案至少可以说是笨拙的……!我迄今为止最好的尝试是查看角度 n 和角度 n - 1 之间的百分比差异。如果这是一个很大的差异——例如> 60% -- 那么这需要修改,根据先前的角度值,通过在当前值上加上或减去 360 度。即如果前一个角度为负,则减去360,如果前一个角度为正,则加360。

有什么改进建议吗?有什么改进吗?

最佳答案

您所说的是一个unwrap 算法,它可以概括(不特定于数字 360...您可以用 m=2*pi 以弧度表示)。这是 javascript 中的一个:

/*  symmetric modulo: 
* y = smod(x,m) = x+k*m where k is an integer,
* and y is always in the range [-0.5,0.5)*m
*/
function smod(x, m)
{
return x-((Math.floor(x/m + 0.5))*m);
}

/* unwrap:
* for all i, y[i] = x[i] + k*m where k is an integer,
* and for i > 0, the increment y[i]-y[i-1] is in the
* range [-0.5,0.5)*m as in smod().
*
* the "init" parameter is optional (default to 0)
* and specifies the starting value for the unwrap state.
*/

function unwrap(x, m, init)
{
var yi = init || 0;
var y = [];
for (i = 0; i < x.length; ++i)
{
yi += smod(x[i]-yi, m);
y[i] = yi;
}
return y;
}

这是一个示例输出:

js>unwrap([100, 200, 348, 359, 23, 37, 46, 10, 350, 190], 360)
100,200,348,359,383,397,406,370,350,190

另一个 m=100 的:

js>unwrap([99,1,7,60,80,22,30,20,90,88,61,23,2,87,50,12], 100, 1000)
999,1001,1007,960,980,1022,1030,1020,990,988,961,923,902,887,850,812

仅供引用:在 C/Java/等中。对于位扩展存在类似的算法,其中输入为 16 位,输出为 32 位,环绕模数 m = 65536 = 输入值的跨度。您不需要“smod”函数,只需使用带符号的数学:

typedef short int16_t;
typedef long int32_t;
// do typedefs as appropriate on your CPU

int32_t unwrap_extend(int32_t prev, int16_t input)
{
int16_t delta = input - prev;
return prev + delta;
}

关于math - 计算 > 360 度的旋转。情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2500430/

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