以下所展示的🦶本,用于根据输入的gps轨迹指北角,给出gps轨迹绘制打点的位置。在保障轨迹绘制曲线基本圆滑的前提下,减少打点数量,降低数据载负担。
function gpsRoutePoints (var deg2North)
{
/* Add your code here
以数据起始点为锚,以gps轨迹指向角度为判定条件,输出gps点序列
*/
unsigned long pointsNo=1;
unsigned long framesCount = 0;
//! 指向角差门限,deg
double degThd=5;
double deg2NorthOfPrePoint;
double degDeltToPrePoint;
framesCount++;
if (framesCount == 2)
{
// 初始化
deg2NorthOfPrePoint = deg2North;
}
if (framesCount > 2)
{
if (abs(deg2NorthOfPrePoint + deg2North) !=abs(deg2NorthOfPrePoint) + abs(deg2North))
{
// 两个角度异号
degDeltToPrePoint = abs(deg2NorthOfPrePoint + deg2North);
}
else
{
// 两个角度同号
degDeltToPrePoint = abs(deg2NorthOfPrePoint - deg2North);
}
if (degDeltToPrePoint >= abs(degThd))
{
if (degDeltToPrePoint < 100) //如果角度差大于100度,则说明gps发生了回跳
{
// 重置
deg2NorthOfPrePoint = deg2North;
pointsNo ++;
}
}
}
return pointsNo;
}
以上脚本中,每一个进行pointsNo++的位置,即为打点位置。根据以上脚本所计算的打点位置,在轨迹发生弯曲时(即在弯道内),打点会密集些,在直线位置,打点会稀疏。下图是根据以上脚本打点绘制出的一个轨迹效果图。
上图中的三角箭头,出现在两个打点的中间位置,箭头的疏密,反映了打点的疏密。