Android中计算坐标变换速度的原理
2013-09-03 11:28
323 查看
采用最小二乘法对获取的坐标X,Y时间序列进行回归拟合。
对于X时间序列(xi,ti):xi=b0+b1*ti+b2*ti^2+...+bm*ti^m,可得如下等式
A*B=Y----------(1)
其中,(带t的表示矩阵的转置)
矩阵B为拟合后要求解的系数矩阵(b0 b1 b2 ... bn)t
矩阵A为
1 t0 t0^2 .... t0^m
1 t1 t1^2 .... t1^m
.
.
.
1 tn tn^2 ... tn^m
矩阵Y为(x0 x1 x2 ... xn)
对A进行QR分解,Q是正交矩阵,R是上三角矩阵:具体见http://zh.wikipedia.org/wiki/QR%E5%88%86%E8%A7%A3
则等式(1)变为
Q*R*B=Y=======》R*B = (Qt)*Y 与Android中input.c中函数solveLeastSquares的实现对应。
对X和Y的拟合与Android中函数VelocityTracker::getEstimator中的下列代码对应
// Calculate a least squares polynomial fit.
if (degree > Estimator::MAX_DEGREE) {
degree = Estimator::MAX_DEGREE;
}
if (degree > m - 1) {
degree = m - 1;
}
if (degree >= 1) {
float xdet, ydet;
uint32_t n = degree + 1;
if (solveLeastSquares(time, x, m, n, outEstimator->xCoeff, &xdet)
&& solveLeastSquares(time, y, m, n, outEstimator->yCoeff, &ydet)) {
outEstimator->degree = degree;
outEstimator->confidence = xdet * ydet;
最后要预测的X和Y的的坐标取b1作为对应的速度(忽略掉其他项为xi=b1*ti,正好是位移、速度、时间的表达式),与函数VelocityTracker::getVelocity中的如下代码对应
if (getEstimator(id, DEFAULT_DEGREE, DEFAULT_HORIZON, &estimator)) {
if (estimator.degree >= 1) {
*outVx = estimator.xCoeff[1];
*outVy = estimator.yCoeff[1];
return true;
}
}
根据上面的步骤得到了X方向和Y方向的速度
再应用时,通过VelocityTracker::addMovement添加MotionEvent事件
再需要获取速度信息的时候调用VelocityTracker::computeCurrentVelocity进行计算,
然后调用VelocityTracker::getXVelocity和VelocityTracker::getYVelocity即可。
对于X时间序列(xi,ti):xi=b0+b1*ti+b2*ti^2+...+bm*ti^m,可得如下等式
A*B=Y----------(1)
其中,(带t的表示矩阵的转置)
矩阵B为拟合后要求解的系数矩阵(b0 b1 b2 ... bn)t
矩阵A为
1 t0 t0^2 .... t0^m
1 t1 t1^2 .... t1^m
.
.
.
1 tn tn^2 ... tn^m
矩阵Y为(x0 x1 x2 ... xn)
对A进行QR分解,Q是正交矩阵,R是上三角矩阵:具体见http://zh.wikipedia.org/wiki/QR%E5%88%86%E8%A7%A3
则等式(1)变为
Q*R*B=Y=======》R*B = (Qt)*Y 与Android中input.c中函数solveLeastSquares的实现对应。
对X和Y的拟合与Android中函数VelocityTracker::getEstimator中的下列代码对应
// Calculate a least squares polynomial fit.
if (degree > Estimator::MAX_DEGREE) {
degree = Estimator::MAX_DEGREE;
}
if (degree > m - 1) {
degree = m - 1;
}
if (degree >= 1) {
float xdet, ydet;
uint32_t n = degree + 1;
if (solveLeastSquares(time, x, m, n, outEstimator->xCoeff, &xdet)
&& solveLeastSquares(time, y, m, n, outEstimator->yCoeff, &ydet)) {
outEstimator->degree = degree;
outEstimator->confidence = xdet * ydet;
最后要预测的X和Y的的坐标取b1作为对应的速度(忽略掉其他项为xi=b1*ti,正好是位移、速度、时间的表达式),与函数VelocityTracker::getVelocity中的如下代码对应
if (getEstimator(id, DEFAULT_DEGREE, DEFAULT_HORIZON, &estimator)) {
if (estimator.degree >= 1) {
*outVx = estimator.xCoeff[1];
*outVy = estimator.yCoeff[1];
return true;
}
}
根据上面的步骤得到了X方向和Y方向的速度
再应用时,通过VelocityTracker::addMovement添加MotionEvent事件
再需要获取速度信息的时候调用VelocityTracker::computeCurrentVelocity进行计算,
然后调用VelocityTracker::getXVelocity和VelocityTracker::getYVelocity即可。
相关文章推荐
- android翻书效果实现原理( 贝塞尔曲线绘制原理/点坐标计算)
- android翻书效果实现原理( 贝塞尔曲线绘制原理/点坐标计算)
- android翻书效果实现原理( 贝塞尔曲线绘制原理/点坐标计算)
- android翻书效果实现原理( 贝塞尔曲线绘制原理/点坐标计算)
- android翻书效果实现原理( 贝塞尔曲线绘制原理/点坐标计算)
- Android中图像变换Matrix的原理、代码验证和应用(三)
- Android给定坐标计算距离
- Android OpenGL ES 简明开发教程四:3D 坐标变换
- Android 一个小例子理解实际开发中坐标计算的过程
- Android OpenGL ES 开发教程(14):三维坐标系及坐标变换初步
- 6.22 android计算字符高度宽度,红蓝3D图片的制作原理及NDK生成实现
- opencv 仿射变换 根据眼睛坐标进行人脸对齐 计算变换后对应坐标
- POJ 3301 (坐标变换、三分枚举计算 点集最小正方形覆盖)
- turtlesim用teleport做坐标变换,不用spawn和角速度做坐标变换
- Android-根据两点间经纬度坐标,计算两点间距离
- Android中图像变换Matrix的原理
- opencv 仿射变换 根据眼睛坐标进行人脸对齐 计算变换后对应坐标
- Android中图像变换Matrix的原理、代码验证和应用(一)
- Android中图像变换Matrix 的原理、代码验证和应用
- Android中图像变换Matrix的原理