前言
遇到一个Kinect捕捉到的现实人坐标转换到Unity场景坐标,需要一个将数据重映射的过程,记录下来。
参考:https://blog.csdn.net/toopoo/article/details/103687809
公式
将[Omin,Omax]上每个数映射到区间[Nmin,Nmax]上, O x , y O_{x,y} Ox,y为[Omin,Omax]上的数字。
N x , y = N max − N min O max − O min × ( O x , y − O min ) + N min N_{x,y}\; =\; \frac{N_{\max }-N_{\min }}{O_{\max }-O_{\min }}\times \left( O_{x,y}-O_{\min } \right)+N_{\min } Nx,y=Omax−OminNmax−Nmin×(Ox,y−Omin)+Nmin
源码
public float ReMapNumber(float oXY, float oMin, float oMax, float nMin, float nMax)
{
float result = 0;
result = (nMax - nMin) / (oMax - oMin) * (oXY - oMin) + nMin;
return result;
}
LaTeX公式代码
//CSDN中代码前后要添加$
N_{x,y}\; =\; \frac{N_{\max }-N_{\min }}{O_{\max }-O_{\min }}\times \left( O_{x,y}-O_{\min } \right)+N_{\min }