将360角映射到255的公式,但坐标x->y是翻转的。

问题描述 投票:0回答:1

我的数学很烂,感觉这应该很简单,但我希望它是优雅的,而不是一个黑客。

我有一个360度的角度,需要计算到一个255度的旋转自由度.人输入角度,准确输出到一个255度的圆。

int north = 90;
float outputNorth = north/360f * 255f; //Results: 90 angle-> 63 angle

但它需要是。

int north = 90;
float outputNorth = north/xf* yf; //Results: 90 angle -> 128 angle

问题是255度的旋转自由度的坐标有点怪异 不知道怎么翻译。

Should be the following:
//90 -> 128

//0 -> 192

//270 -> 0

//180 -> 64

SEE THIS PICTURE!!! -> 360 coords mapped to 255 cords, but it needs to be the resulting cords

java algorithm math rotation algebra
1个回答
0
投票

你的数学有一些四舍五入的问题。我会使用不同的映射,其中360度将是。256 -> 0 而不是 255. 否则你的8位值会有相同的角度。0 存储两次,很可能会引起其他问题。

在这里使用 线性插值:

int i;     // angle [deg int]
int o;     // 0..255 [8bit uint]

o=(192-((i<<8)/360))&255;

i=((192-o)*360)>>8;

这里的数值。

  i   o
  0 192
 90 128
180  64
270   0
360 192

价值: i 可以是任何甚至负的或大于360度的转换仍将工作... ...


-1
投票
float outputNorth = (north+90)/360f * 255f;

是我要找的答案... ... -.-

© www.soinside.com 2019 - 2024. All rights reserved.