Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > General > Chit Chat
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Chit Chat The place for open discussions.


Math question RE: GPS track


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-03-2009, 05:55 PM
Junior Member
 
Join Date: May 2009
Posts: 11
Default Math question RE: GPS track

I want to calculate rate of change of track acorss ground (in degrees). You could call it rate of turn.

OK, it's simple....all you do is subtract the incoming reading from the privious one. Well not quite.......all is dandy until you sweep over the 360 degrees line. If you were turning clockwise you could get 359 - 1 = 358, where what you really want is '2'.

Any ideas how you do this would be appriciated.

Many thanks, Ben
Reply With Quote
  #2 (permalink)  
Old 07-03-2009, 08:56 PM
derez's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Posts: 565
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default

The problem happens only for one reading, until you reach the next time around.
You can ignore this specific reading by a simple test:

if abs(new_track - old_track) < x then
.....
end if

where X must be larger than the maximum expected turn per second.

for continuity of display use for this specific "non reading" the previous value.

Edit:
If you do want that reading, since you know by using the test above that you have the difference of 360 degrees to the result, add or subtract according to the sign of the difference, the value 360.
__________________
David Erez
Ramat Hasharon, Israel

Last edited by derez : 07-03-2009 at 09:00 PM.
Reply With Quote
  #3 (permalink)  
Old 07-03-2009, 09:10 PM
Junior Member
 
Join Date: May 2009
Posts: 11
Default

Thanks derez

Sounds like a good idea. I'll give it a try.

Ben
Reply With Quote
  #4 (permalink)  
Old 07-04-2009, 10:18 AM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Switzerland
Posts: 1,556
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

If you take the difference of the incoming reading - previous reading you get a value.
Clockwise turning is positive and counterclockwise turning is negative.
In your example:
incoming reading 1°
previous reading 359°
so 1 - 359 = -358°
This means a counterclockwise turning of 358°
But this also means a clockwise turning of 2°
The following code will give you the turn in +/- 180°

Code:
DeltaDir = Direction(i) - Direction(i-1)
If Abs(DeltaDir) > 180 Then
 If DeltaDir < 0 Then
  DeltaDir = DeltaDir + 360
 Else
  DeltaDir = DeltaDir - 360
 End If
End If
Best regards.
__________________
Klaus
Switzerland
Reply With Quote
  #5 (permalink)  
Old 07-05-2009, 07:46 AM
Junior Member
 
Join Date: May 2009
Posts: 11
Default

Thanks Klaus

That's exactly what I ended up with!

Cheers, Ben
Reply With Quote
  #6 (permalink)  
Old 07-06-2009, 07:08 AM
Junior Member
 
Join Date: Jul 2009
Location: Derbyshire, UK
Posts: 19
Default

you don't need the Abs() line, and extra 'If' level; just use:

If DeltaDir < 180 Then
DeltaDir = DeltaDir + 360
ElseIf DeltaDir > 180 Then
DeltaDir = DeltaDir - 360
End If
Reply With Quote
  #7 (permalink)  
Old 07-06-2009, 10:00 AM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Switzerland
Posts: 1,556
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Are you really shure ?

In the case when
incoming reading 150°
previous reading 120°
DeltaDir=150-120=30

in your example DeltaDir<180 Then
DeltaDir = DeltaDir + 360 = 390
Do you want that ?

That's not what I want, I want results between -180 to + 180

In my code the result remains 30 because Abs(DeltaDir) is less than 180

Best regards.
__________________
Klaus
Switzerland

Last edited by klaus : 07-06-2009 at 10:02 AM.
Reply With Quote
  #8 (permalink)  
Old 07-06-2009, 10:27 AM
Junior Member
 
Join Date: Jul 2009
Location: Derbyshire, UK
Posts: 19
Default

sorry, should have been < -180
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Math help please cdeane Chit Chat 2 04-02-2009 05:45 PM
db2000 math functions maXim Italian Forum 0 12-01-2008 11:24 AM
Small math-trainer token Share Your Creations 3 07-17-2008 07:29 PM
Fixed Point Math im4retro Questions & Help Needed 3 05-31-2008 07:13 AM
Help with Math function go4saint Questions & Help Needed 2 03-31-2008 10:15 AM


All times are GMT. The time now is 12:25 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0