Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I hope everyone can be as helpful as last time?

Status
Not open for further replies.

karenthestudent

New Member
My newest project requires me to find a direction between to longitude and latitude positions. The two positions are given by two separate Garmin GPS devices. The postion is given in ddmm.mmmm format for both longitude and latitude. I need to be able to compare two positions and work out what direction one is from the other. To do this I need some sort of mathematic equation to work out the angle between two points. This mathematic equation then needs to be put into PIC, which I am using to receive the signal from the GPS.
So does anyone know of someone and somewhere I could try to get help from :?:
 

stevez

Active Member
I'd be inclined to discuss the problem with someone who is familiar with navigation. While I won't argue that it's a "math" problem, there are probably some well established methods - some of which may be more suitable to handling by a PIC.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Yes, I'm certainly not going to 'strain my brain' trying to do the maths :lol: I'm long past that sort of thing!.

However, it shouldn't be too hard to find how to do it, it's simple geometry, but it's a long time since I left school!.

I would suspect that what you are going to need is floating point maths routines - and it's not something that PIC's do terribly well!. If lucky you may be able to reduce parts of it to look-up tables, you can generate the tables from a PC - where floating point is easy.

If you look on the PICLIST there are quite a lot of details about floating point maths, sines, cosines etc.
 

stevez

Active Member
This might be easier that I thought. I presume the GPS gives you the lat/long of each position. The difference between the lat of one position and the other would give you one leg of a triangle - the long differences give the other. Hint: we know the approx dia of the earth and can calc the length of the arc knowing the degrees. Some trig and you have the angle - and you'll also know which quadrant - so you might add 90, 180 or 270 degrees as needed if you plan to anchor yourself to north (or whatever). Curvature of the earth comes into play - I haven't got time to think about it to see if it can be ignored - though for modest distances it probably can be ignored.

A reminder that magnetic north and true north are different and the correction depends on where you are and when (years). None of this does anything to correct for any magnetic errors.
 

Gandledorf

New Member
As mentioned the MATH behind it is very simple, given that the distances are short. A word of warning: The curvature of the earth may be discounted for short distances, but once you start to exceed a few hundred miles, you are going to introduce error which may or may not be significant, depending on how accurate you want your measurement to be. If this is a navigation system for aircraft, it WILL make a difference, enough of one to put you in serious trouble. If you are dealing with such a system, let me know, and I can direct you to an appropriate model for navigable arcs.

Elsewise, assume you are on a simple cartiesian coordinate plane, designate your anchor point, and draw out a right triangle with hypotenuse between the two points, side adjacent equal to the latitudinal distance, side opposite equal to the longitudinal distance (This orients your side adjacent and side opposite as NS, and EW lines). You now have three known sides, so solving for the angles is easy.

tri-1.gif


In the following equations, side opp = o, side adj = a, side hyp = h, angle a = A, angle o = O, angle h = 90 (right triangle)

A = arccos ((o^2 + h^2 - a^2) / (2oh))
O = 180 - 90 - A

The best idea would be either to use a math coprocessor, find code for the math itself, or calculate a lot of values ahead of time, store in a table, and do approximations. Again, it depends on how accurate you need to be. What will this project be used in?
 

karenthestudent

New Member
thank you

That’s excellent, I can see what you mean, and I think that the maths should be ok for me understand. The GPS is to be used a person finder, where by it locates the second person from the first. It is therefore likely to be used on the same ground level, between 30-300 meters apart. From what you have all said it would be fare to ignore any curvature over these distances?
The coordinates will compared to each other at the same moment in time.
One thing I am not sure about is how the angle will be calculated from the Latitude longitude given as degrees and minutes (ddmm.mmmm).
:!:


The GPS states what hemisphere the GPS is in, which for this example both devices are in the N W hemispheres.

If one person is standing at X and the other at Y, then what direction is Y from X.
This is the output from the two GPS devices.

Position X…5126.3711,N (latitude) and 00034.1171,W (longitude)
Position Y…5129.5040,N (latitude) and 00038.4633,W (longitude)
These might not be the best examples?
:?:
 

Attachments

  • xy_copy.jpg
    xy_copy.jpg
    23.1 KB · Views: 313

Gandledorf

New Member
Re: thank you

karenthestudent said:
That’s excellent, I can see what you mean, and I think that the maths should be ok for me understand. The GPS is to be used a person finder, where by it locates the second person from the first. It is therefore likely to be used on the same ground level, between 30-300 meters apart. From what you have all said it would be fare to ignore any curvature over these distances?
The coordinates will compared to each other at the same moment in time.
One thing I am not sure about is how the angle will be calculated from the Latitude longitude given as degrees and minutes (ddmm.mmmm).
:!:

The units of Latitude and Longitude are the same and will cancel out in the formula. Treat them as distances (they are in fact angular coordinates, but on a scale of 30-300 meters, we really don't care, given the scale of the earth, and assuming you aren't at a pole). You can then use the degrees as a compass bearing.


The GPS states what hemisphere the GPS is in, which for this example both devices are in the N W hemispheres.

If one person is standing at X and the other at Y, then what direction is Y from X.
This is the output from the two GPS devices.

Position X…5126.3711,N (latitude) and 00034.1171,W (longitude)
Position Y…5129.5040,N (latitude) and 00038.4633,W (longitude)
These might not be the best examples?
:?:

It's a fine example. One problem, side opposite is always opposite your reference point, side adjacent is always adjacent to your reference point, in my example I assumed a different orientation, so switch yours.

Lets work it out together. First off, it's probably worthwhile to recenter our axis about X for ease of calculations. So X is now at 0,0. Lets adjust Y accordingly to -3.1329, -4.3462. Side adjacent = 4.3462, Side opposite = 3.1329. We get the hypotenues from the distance formula: d = sqrt((x1 - x2)^2 + (y1 - y2)^2) = 5.3576.

A = arccos((3.1329^2 + 5.3576^2 - 4.3462^2) / (2 * 3.1329 * 5.3576))
A = .9462379659 RADIANS (NOT degrees)
To conver to degrees multiple by 180/pi
A = 54.22 degrees
H = 90 degrees
O = 180 - 90 - 54.22
O = 35.78 degrees

Since O is 35.78 degrees and they are in Quadrant IV, We add 90 degrees, and find that they are at 125.78 degrees (compass direction, that is 35.78 degrees south of east).

EDIT: Note if you want distance, the distance is in angular coordinates is given by the hypotenues. For our scale, we assume angular = cartesian for simplicity, and assuming your lattitude is roughly the same as mine (it may not be, so you may need a different number), there are roughly 70 miles per degree, and 60 minutes per degree. So using the hypotenues of 5.3576, we get roughly 6.21 miles.
 

karenthestudent

New Member
yep, that all makes sense. As I mentioned I am happy with maths, but am a complete novice when it comes to PIC. It was suggested to me that I would have to find existing PIC code, for these calculations.

Would any one know how difficult this would be to put into PIC. My aim would be a piece of code that compares the GPS locations to first decide what quadrant the second person is in from the first (i.e. 0-90, 90-180 degrees etc). Then it finds the difference between the locations to give the dimensions as given in example by Gandledorf. This will then give the angle to the next person, which will enable a direction to be stated.
:?:
 

karenthestudent

New Member
also would anyone know of any other chat forum's which are as helpful as this? possibly one that would have more chat rooms for PIC? :)
 

Styx

Active Member
OMG!!!!

and I thought some of my stuff was a headache.

How accurate do you need the angle?
The problem is how you derive the inverse of sin/cos (dependant on what you want)

1) mathematical expansion of the trig function - Be very big for very accurate

2) lookup table - also very big for accurate calculation
 

karenthestudent

New Member
This is the problem, I am not sure if I can just have a general equation/piece of PIC code, to take variables such as longitude etc, at a set time, and the work an angle from that. I think to enable someone to be found using the given direction, it has to have some accuracy, say 5-10 degrees? Otherwise someone would take forever to navigate there way from X to Y!?
Basically any angle given would be to at least the nearest degree, with look up tables probably for set ranges...for example 0-10 degrees, 10-20? I have no idea how optimistic this is.
But if I can get it to work for any angle then I should be able to work towards an acceptable accuracy?
:shock:
 

Nigel Goodwin

Super Moderator
Most Helpful Member
karenthestudent said:
But if I can get it to work for any angle then I should be able to work towards an acceptable accuracy?

I would suggest initially writing a PC program to do the calculations, and test it using that - you can simply invent locations to make sure it all works correctly. Then try and simplify the equations, try using simply lookup tables for the trig functions, see how they affect accuracy.

I'm presuming this is part of your course?, so DOCUMENT EVERYTHING, using a PC to evaluate algorithms should be good for marks!.

Once you have a working PC program, as simple as possible, you can then try to write a PIC version - as I mentioned before, PIC's don't like floating point - if you can scale values to avoid floating point (like instead of multiplying 1.5 by 1.2, multiply 15 by 12, and display the answer with a decimal point moved in two places) it will make it much simpler, and a GREAT deal faster.
 

Gandledorf

New Member
Nigel Goodwin said:
karenthestudent said:
But if I can get it to work for any angle then I should be able to work towards an acceptable accuracy?

I would suggest initially writing a PC program to do the calculations, and test it using that - you can simply invent locations to make sure it all works correctly. Then try and simplify the equations, try using simply lookup tables for the trig functions, see how they affect accuracy.

I'm presuming this is part of your course?, so DOCUMENT EVERYTHING, using a PC to evaluate algorithms should be good for marks!.

Once you have a working PC program, as simple as possible, you can then try to write a PIC version - as I mentioned before, PIC's don't like floating point - if you can scale values to avoid floating point (like instead of multiplying 1.5 by 1.2, multiply 15 by 12, and display the answer with a decimal point moved in two places) it will make it much simpler, and a GREAT deal faster.

Another thing to remember is that, unlike your example, if there really is a 300m cap on the distance, you're not going to see more than 2 whole minutes, so shifting the decimal will really help, without introducing too much inaccuracy.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
karenthestudent said:
ok,thank you, I'll give that a go, and keep my eyes open for any more suggestions! :D .......wish me luck

Good luck 8)

Please keep us informed of your progress, I'm sure we'll all be interested to hear how you get on.

BTW, what Uni are you at?.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top