LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-05-2011, 02:36 AM   #1
Cotun
Member
 
Registered: Jan 2009
Location: UK
Distribution: Debian Stable and Unstable
Posts: 61

Rep: Reputation: 21
Calculating new coordinates based on current position, bearing and speed


Hi

I'm writing a program that needs to calculate a new set of coordinates based on the current position, the directional bearing and the speed of movement. The map is simply a flat 2D representation and therefore the Earth's curving axis does not need to be taken into account.

I've searched through Google, but I can only find information on achieving this using lat/long on the Earth's 3D surface (which is a different representation and thus problem).

Does anybody have any idea on what the equation is to achieve this?

Thanks

Cotun
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-05-2011, 03:20 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,376

Rep: Reputation: 147Reputation: 147
Check out Mr Pythagoras' famous idea
 
Old 04-05-2011, 03:26 AM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by Cotun View Post
Hi

I'm writing a program that needs to calculate a new set of coordinates based on the current position, the directional bearing and the speed of movement. The map is simply a flat 2D representation and therefore the Earth's curving axis does not need to be taken into account.

I've searched through Google, but I can only find information on achieving this using lat/long on the Earth's 3D surface (which is a different representation and thus problem).

Does anybody have any idea on what the equation is to achieve this?

Thanks

Cotun
Start from entering

cartesian coordinates
polar coordinates

into your favorite WEB search engine and reading the Wiki articles.
 
Old 04-05-2011, 11:04 AM   #4
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by Cotun View Post
I'm writing a program that needs to calculate a new set of coordinates based on the current position, the directional bearing and the speed of movement. The map is simply a flat 2D representation and therefore the Earth's curving axis does not need to be taken into account.
Define bearing a in radians,
a = (angle in degrees) Pi / 180
Normally we define zero angle as towards the positive x axis, increasing towards the positive y axis.

If at time t=0 you are at (x(0), y(0)), bearing a and velocity v, then you can calculate the position as a function of time t using
x(t) = x(0) + t v cos a
y(t) = y(0) + t v sin a
As long as your units for x, y, v and t match ([x] = [y] = [t v]), and the units are uniform over the entire map, you can use any units you wish.
 
2 members found this post helpful.
Old 04-05-2011, 12:21 PM   #5
Cotun
Member
 
Registered: Jan 2009
Location: UK
Distribution: Debian Stable and Unstable
Posts: 61

Original Poster
Rep: Reputation: 21
Thanks to all of you, particularly Nominal Animal for providing the easy-to-understand reference on the equation. It took me only minutes to implement this into my program and I do appreciate the effort you took.
 
Old 04-05-2011, 01:38 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by Cotun View Post
Thanks to all of you, particularly Nominal Animal for providing the easy-to-understand reference on the equation. It took me only minutes to implement this into my program and I do appreciate the effort you took.
How do you know the provided equation is correct ? I.e. if a number of different posters provide different equations, how will you know which of them to choose ?
 
1 members found this post helpful.
Old 04-05-2011, 04:11 PM   #7
Cotun
Member
 
Registered: Jan 2009
Location: UK
Distribution: Debian Stable and Unstable
Posts: 61

Original Poster
Rep: Reputation: 21
Because I implemented and tested the provided equation on a spreadsheet first. It provides exactly what I needed and works within expected boundaries.
 
Old 04-05-2011, 04:54 PM   #8
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by Sergei Steshenko View Post
How do you know the provided equation is correct ? I.e. if a number of different posters provide different equations, how will you know which of them to choose ?
How do you know the results returned by the search engines are correct? That the equations in Wiki articles are correct? When you see the different equations, how will you know which of them to choose?

Sergei, do you realize how much math you need to actually know and understand to derive the equation? Cotun is obviously unfamiliar with this. Just because you (and I, I admit) think that this is something every programmer should know, does not make it so.

Most of the links you show point to this familiar equation of motion, using vector notation:
x(t) = x(0) + v t + 1/2 a t^2
First, you need to understand vector notation, and that the above is actually equivalent to
x(t) = x(0) + v_x t + 1/2 a_x t^2
y(t) = y(0) + v_y t + 1/2 a_y t^2
Then you need to realize that because the motion in this case is at constant velocity, the acceleration is zero:
x(t) = x(0) + v_x t
y(t) = y(0) + v_y t
Finally, you must be able to convert the bearing from polar coordinates to cartesian coordinates, i.e.
v_x = v cos b
v_y = v sin b
where "total" velocity is v, and bearing b is in radians counterclockwise from positive x axis.

Then, and only then, you can arrive at the final equation,
x(t) = x(0) + v t cos b
y(t) = y(0) + v t sin b
Math is unlike programming in that the end result is almost always easier to understand and apply than the method of arriving at it. In fact, usually the method of finding a solution requires not only experience, but creative leaps (or tedious hours of trial and error). Therefore, I believe, we should point those with math problems towards the equations themselves, and perhaps explain (with references) why and how they work. After all, this is not a theoretical math forum; all math problems we're likely to see are "applied" math.

Don't you agree?
 
1 members found this post helpful.
Old 04-05-2011, 09:01 PM   #9
Cotun
Member
 
Registered: Jan 2009
Location: UK
Distribution: Debian Stable and Unstable
Posts: 61

Original Poster
Rep: Reputation: 21
Quote:
Sergei, do you realize how much math you need to actually know and understand to derive the equation? Cotun is obviously unfamiliar with this. Just because you (and I, I admit) think that this is something every programmer should know, does not make it so.
I don't really agree that every programmer needs to know this kind of thing. I have more than 15 years of experience as a programmer, but have largely ended up working on the business end of the market rather than any computer-science or mathematical modelling in code. Until today, I have never needed this equation to make anything work. Only a few days ago, I came across a need to calculate bearing for the first time. It is quite possible to be a programmer and not be heavily involved in applied mathematics, a field which I fully admit I'm neither experienced or knowledgeable with at present.
 
Old 04-05-2011, 11:57 PM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by Nominal Animal View Post
How do you know ... That the equations in Wiki articles are correct? When you see the different equations, how will you know which of them to choose?

Sergei, do you realize how much math you need to actually know and understand to derive the equation? Cotun is obviously unfamiliar with this. Just because you (and I, I admit) think that this is something every programmer should know, does not make it so.

...

Don't you agree?
No, I don't agree. I was taught at school (yes, a special kind of high school, before the university) trigonometry and kinematics. And when necessary, in simple cases like this one I can really prove (mathematically) formulas from Wiki.

If a programmer is a domain programmer, he/she should know the domain. "Know" means being able to prove what is provable

FWIW, looking up info on Digital Fourier Transform in Wiki I disagreed ((slightly) with their formula for Hanning window (the disagreement is N <-> N - 1 and for large Ns is insignificant, but still).

I was once looking into somebody else's FFT code and did find a significant bug in windowing - significant because quite audible. And mathematically it was a bug - much more significant than the above N <-> N - 1.


More on DFT - other pitfalls are scaled/unscaled and complex exponent imaginary part sign.
 
Old 04-06-2011, 12:05 AM   #11
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by Cotun View Post
Because I implemented and tested the provided equation on a spreadsheet first. It provides exactly what I needed and works within expected boundaries.
This is a lovely nonsense.

I.e. suppose I tell you that linear function is

y(x) = k * x + b + sin(x * pi)

and tell you to check it for x = 0, 1, 2, 3 ...

- though the above function is wrong, it will work for the suggested set of test points exactly as the correct

y(x) = k * x + b

one.

I think in a Niklaus Wirth's book I once read: "Testing never proves absence of bugs, it can only prove their presence" - I don't claim it's the exact quote, but the sense was definitely like this.
 
1 members found this post helpful.
Old 04-06-2011, 08:36 AM   #12
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by Sergei Steshenko View Post
If a programmer is a domain programmer, he/she should know the domain. "Know" means being able to prove what is provable
Here I agree. Prove yes, derive from first principles no. That is why I showed the final formula, not just point at the basic principles.

Quote:
Originally Posted by Sergei Steshenko View Post
FWIW, looking up info on Digital Fourier Transform in Wiki I disagreed ((slightly) with their formula for Hanning window (the disagreement is N <-> N - 1 and for large Ns is insignificant, but still).
That is quite common in Wikipedia (although I believe you mean Discrete Fourier Transform). I did something similar with trilateration (under Simplified solution without extra assumptions), but lost interest when even such an easy simplification raised a controversy. The original article used a number of coordinate system transforms with trigonometric functions. I think the original author was unfamiliar with vector algebra, but familiar with matrices and coordinate transforms with trigonometric functions.
 
Old 04-06-2011, 11:13 AM   #13
Cotun
Member
 
Registered: Jan 2009
Location: UK
Distribution: Debian Stable and Unstable
Posts: 61

Original Poster
Rep: Reputation: 21
Quote:
This is a lovely nonsense.

I.e. suppose I tell you that linear function is

y(x) = k * x + b + sin(x * pi)

and tell you to check it for x = 0, 1, 2, 3 ...

- though the above function is wrong, it will work for the suggested set of test points exactly as the correct

y(x) = k * x + b

one.
I concede that this is of course possible. However, the equation given would have to give results that were good enough to fool my quite comprehensive test cases and yet still be wrong for my application. If this was done, it is much more likely by design than by accident and therefore Nominal Animal would likely have been deceiving me deliberately. I didn't think he was and can't see why he would in all honesty.

Quote:
If a programmer is a domain programmer, he/she should know the domain. "Know" means being able to prove what is provable
If I was working on any job of a safety-critical nature, then of course I should be able to prove all the mathematics or find somebody who works in the same organisation who could for the good of the public. However, I was merely writing a computer game which will be later released as open-source. If there is some minor obscure error that develops due to me using the wrong calculations, the most likely event is that nobody will notice. It would not be a good use of time for me to spend weeks learning about mathematics just to come to what is a relatively simple equation to resolve a problem I have for a basic, unimportant task.

We all depend on things done by others on a daily basis and often build upon those too. You should be able to prove that the water you drink is safe before you actually do, but few people would do that. Most people wouldn't know how to start doing that, just as I don't have presently have the mathematical basis to do what you expected me to do.

I realise of course that you were talking generically about being able to understand what you are implementing, but I think you are being too theoretical and thus harsh when you look at the real-world application.
 
1 members found this post helpful.
Old 04-06-2011, 01:42 PM   #14
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,089

Rep: Reputation: 207Reputation: 207Reputation: 207
This thread reminded me of a joke I read on facebook:

Quote:
There was an engineer, manager and programmer driving down a steep mountain road.

The brakes failed and the car careened down the road out of control.

Half way down the driver managed to stop the car by running it against the embankment narrowing avoiding going over a cliff.

They all got out, shaken by their narrow escape from death, but otherwise unharmed.

The manager said "To fix this problem we need to organize a committee, have meetings, and through a process of continuous improvement, develop a solution."


The engineer said "No that would take too long, and besides that method never worked before. I have my trusty pen knife here and will take apart the brake system, isolate the problem and correct it."

The programmer said "I think your both wrong! I think we should all push the car back up the hill and see if it happens again."
But seriously, I doubt most non-trivial programs can be "proven". If we did that, there would be nothing like for example this forum.
 
Old 04-06-2011, 09:43 PM   #15
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by Guttorm View Post
... I doubt most non-trivial programs can be "proven". ...
The OP's need/formulas he needs are trivial.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vim - string replacement from current position to end of file armandino Linux - General 1 01-24-2011 03:12 PM
[SOLVED] current(21.07) gtkfilechooser position konus Slackware 1 07-22-2009 08:11 AM
Calculating the real internet connection speed KaLPo Programming 6 05-14-2009 10:52 AM
calculating download time/speed juanb Linux - Networking 4 03-19-2004 02:49 PM
New job position at my current workplace.. trickykid General 10 06-26-2003 03:21 AM


All times are GMT -5. The time now is 05:36 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration