计算累积海拔增益给我带来了奇怪的结果 [英] Calculating Cumulative elevation gain give me wierd results

查看:280
本文介绍了计算累积海拔增益给我带来了奇怪的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用 CoreLocation 并跟踪用户移动。

当用户步行或驾驶时,我将每个坐标保存到本地数据库( lat / lng / alt)所以我可以根据保存的坐标绘制路线。

几天前我添加了累积海拔增益我使用此代码

I have the app that use CoreLocation and track user movement.
When user is walking or driving I save each coordinate to local database (lat/lng/alt) so I can draw route based on saved coordinates.
A few days ago I have added Cumulative elevation gain and I use this code in

didLocationUpdate:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    netElevationGain += MAX(0, oldLocation.altitude - newLocation.altitude);
}

但是有些事情是错的。

我开始了应用程序,并开始步行和走动几英里,我得到 netElevationGain 将近500米。这是不正确的。

这是每个点在数据库中保存的 netElevation 列表:

But something is just wrong.
I started the application and start walking and walking around for a few miles and I get netElevationGain almost 500 meters. Which no way it's correct.
This is the list of netElevation saved in database for each point:

0,41,43,44,47,52,55,62,73,80,91,100,114,140,146,153,159,180,199,208,228,240,259,275,320,329,349,359,366,375,381,392,408,419,428,437,446,449,462,469,478,486

海拔高度b
0.000000,181.678055,181.891495,182.786850,179.315399,177.035721,182.636307,181.259399,178.653015 ,192.552551,185.398819,182.693436,181.369766,154.306747,157.031693,159.748871,185.080856,198.080673,176.473877,178.646851,175.784424,178.184128,181.237488,188.956894,177.713181,193.673019,188.470184,182.749054,181.966507,181.547592,191.638657,198.713989,188.582977,197.977921 ,203.184540,205.108856,198.304123


要显示增益,我使用简单的从表中选择最大值(增益)...

更多更新



UPDATE

现在我的值越来越差(按降序排列):

替代:

Now I get worse values (in descending order):
Alt:

200.334869,200.594666,196.293945,195.240234,191.800446,192.622375,179.951385,179.185577,179.681122,177.843719,183.459595,174.170502,0.000000

获利:

307,301,294,285,275,269,252,246,234,227,217,202,0


推荐答案

我使用了您列出的值并运行它们如下:

I took the values you've listed and ran them as follows:

NSArray *altitudes = @[ @(0.000000), @(181.678055), @(181.891495), @(182.786850), @(179.315399), 
                        @(177.035721), @(182.636307), @(181.259399), @(178.653015), @(192.552551), 
                        @(185.398819), @(182.693436), @(181.369766), @(154.306747), @(157.031693), 
                        @(159.748871), @(185.080856), @(198.080673), @(176.473877), @(178.646851), 
                        @(175.784424), @(178.184128), @(181.237488), @(188.956894), @(177.713181), 
                        @(193.673019), @(188.470184), @(182.749054), @(181.966507), @(181.547592), 
                        @(191.638657), @(198.713989), @(188.582977), @(197.977921), @(203.184540), 
                        @(205.108856), @(198.304123) ];

float netAlt = 0.0f;

// Start with the third value as we're only interesting in net gain
for (NSInteger i = 2; i < altitudes.count; i++) {
    float oldAlt = [altitudes[i-1] floatValue];
    float newAlt = [altitudes[i] floatValue];

    // newAlt - oldAlt because we're interested in the 
    // difference between current and previous
    float diff = newAlt - oldAlt;

    netAlt += MAX(0, diff);
    printf("%.0f,", netAlt);
}

这产生了以下输出:


0,1,1,1,7,7,7,21,21,21,21,21,23,26,51,64,64,67,67, 69,72,80,80,96,96,96,96,96,106,113,113,122,127,129,129

0,1,1,1,7,7,7,21,21,21,21,21,23,26,51,64,64,67,67,69,72,80,80,96,96,96,96,96,106,113,113,122,127,129,129

这对我来说似乎是合理和现实的。目前还不清楚你如何设法获得你拥有的价值。他们毫无意义。

This seems reasonable and realistic to me. It's not at all clear how how you managed to get the values you have. They make no sense.

这篇关于计算累积海拔增益给我带来了奇怪的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆