Click to See Complete Forum and Search --> : I'm lost in translation
Shaggy Hiker
May 20th, 2007, 10:30 PM
It's late and I'm tired, so this may prove to be a D'OH kind of a question, but here it is (and yes, it's related to something I started on a couple months back):
If I have an object at the origin with a heading of H, and I have a bearing B and a distance D to a different object N, how do I get the x,y coordinates of that other object. I see a way to do it by figuring out which quadrant N is in, and doing the trig depending on that quadrant. That's really not all that difficult, but I was thinking there might be something slicker than a series of If statements to figure the quadrant, then a bit of trig.
opus
May 21st, 2007, 01:28 AM
If you have the bearing in 360 degrees and the position in two Single vars (not in degrees and minutes, X increases to the right/East, Y increases to the top/North) you can use this:
Public Point_Type
X as Single
Y as Single
End Type
Public Const PIDiv180= 3.14159265358979/180
Public Function EndPoint (StartPoint as Point_Type, Bearing as Single, Distance as Single) as Point_Type
EndPoint.X = Sin(Bearing*PIDiv180)*Distance+StartPoint.X
EndPoint.Y= Cos(Bearing*PIDiv180)*Distance+StartPoint.Y
End Function
zaza
May 21st, 2007, 03:54 AM
If you're at the origin, then your coordinates have no impact on those of the object N. All that matters is your heading.
Since the relative bearing is B and your heading is H, then the actual bearing of N relative to 0o (i.e. due East) is just B + H (mod 360, and assuming that there is a proper 360 degree or negative convention). If your bearing is taken from a different point, just include the offset from your "local" 0o as a constant, e.g. if bearing is from "straight ahead", then add on 90o.
Now that you've got the angle from 0o (true East) and the distance from the origin, you just want the sin and cos to get x and y.
zaza
opus
May 21st, 2007, 04:03 AM
Hi zaza, did I miss something, as far as I undeerstood B stands for bearing and not relative bearing!
Also I have to state that my code goes for bearings 0 to 360 degrees, where 0 is North and 90 is East!!!
BTW: I'm an old fashioned airborne-navigator, I was trained using an sextant to shoot the stars and using Loran, so please don't make me change this habbit!
zaza
May 21st, 2007, 04:44 AM
My understanding is that bearing is with respect to the direction in which you are travelling, hence you need to account for heading. I normally take coordinates and angles with respect to the x-axis, which is why I included the bit about accounting for your "local" 0o.
Shaggy's a smart bloke though, I'm sure he already knows all this.
opus
May 21st, 2007, 06:32 AM
I normally take coordinates and angles with respect to the x-axis, which is why I included the bit about accounting for your "local" 0o.
Note that you probably count from 0 (east) to 90 (north), whereas I'm counting from 0 (north) to 90 (east), which is the otherway around! (I had to learn this kind of "false" directions the hard way at a time!)
Shaggy's a smart bloke though, I'm sure he already knows all this.
I know that, I've read enough of his post's.
It's always a pleasure to help (or to try to help) one of the guru's of this forum!
BTW. What's the meaning of "D'OH"?
zaza
May 21st, 2007, 08:11 AM
Note that you probably count from 0 (east) to 90 (north), whereas I'm counting from 0 (north) to 90 (east), which is the otherway around! (I had to learn this kind of "false" directions the hard way at a time!)
Correct, but to be honest that's only a fixed 90 degree offset. It doesn't require any more complex a calculation.
BTW. What's the meaning of "D'OH"?
Ask Homer Simpson.
Shaggy Hiker
May 21st, 2007, 10:36 PM
Man, I'm tired. I really want to get back to this.....but I can't for a couple of days. You both made good points, however, here's my perspective on it: I'm an old navigator, too, but map and compass on ground work, so 0 is North, and 90 is east for me, as well. Also, this is my robot project, and the robot has a compass, so 0 will generally be north.
However, to wander off onto a totally irrelevant tangent, I am wondering how well my navigation will even work (I hope to find out in the next month). The compass is a sensitive electronic one. I will have to be watching to see whether things like the refrigerator cause my perceived heading to begin veering. It would be interesting to make a map of magnetic deviation around the house, but it will be a heckuva challenge doing navigation if every sensor has variable, non-random, error over the course of a straight line. I'm fairly eager to find out whether this will be a problem, but right now I'm still throwing a track whenever I turn a corner. More parts in the mail, might have a workable solution this weekend. Pictures in a month or so.
Then getting back to the topic at hand:
In this case, I do have only a relative bearing (and a true heading), but converting that to an absolute bearing in my 0 degrees N frame of reference is pretty simple math.
Yeah, it turns out it is a D'OH moment, and yes, that is a Homer Simpsonism. I think I'm no less sleepy now than I was when I wrote that first post, but even as fogged as I am I realize that once I get the true bearing the position of the point is simple.
By the way, I think there is already a Point structure tucked somewhere into .NET. I may find it, or I may not bother. In any event, I will be doing everything in integers ultimately, because the error in all of my measurements is such that even a single decimal place is pseudo-precision.
Thanks for the help, though, it was useful to me.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.