Click to See Complete Forum and Search --> : Forgot my geometry (Revived)
Shaggy Hiker
Jan 30th, 2007, 08:22 PM
I think I'm overlooking something simple, but I figured somebody here would have a ready answer. Here's the problem:
For a line A-B with point C on the line halfway between A and B, such that AC = BC, and a point N not on the line, what is the formula to find the angle ACN given only the lengths AB, AN, and BN?
Basically, I have two sensors that will be picking up a return echo off of an item that will be somewhere in front of it, and I need to find the bearing to it. The purpose of the point C is that the bearing from either "eye" is not all that meaningful.
superbovine
Jan 30th, 2007, 09:20 PM
http://mathworld.wolfram.com/SSSTheorem.html
i thunked?
opus
Jan 31st, 2007, 04:18 AM
What value are you looking for, and more important, which values did you already calculate?
You should have all the coordinate for the points (A, B, C and N)
You probably have to calculate C, but that's easy (Cx=Ax+ (Bx-Ax)/2, Cy=Ay+ (By-Ay)/2).
Using those coord's you can claculate the direction from one point ot the other. Using those directions, the calculatuion of the angle ACN should be a POC.
Are you looking for a formula to calculate the direction from one point to the other?
Here is my rountine!
Public Const PI = 3.14159265358979
Public Const PiDurch180 = PI / 180
Public Const A180DurchPi = 180 / PI
Public Function Direction(x1, y1, x2, y2) As Single
'Input Coordinates x1, y1, x2, y2
'Note x will increase to the right!
Note y will increase to the top!
'Output Direction (0-360, with 0 or 360 North or to the top, 90 East or to the right)
Dim dx As Single
Dim dy As Single
dx = x2 - x1
dy = y2 - y1
If dy <> 0 Then
Direction = (Atn(dx / dy) * A180DurchPi)
If x2 > x1 Then
If y2 > y1 Then
'Direction = Direction
Else
Direction = 180 + Direction
End If
Else
If y2 > y1 Then
Direction = 360 + Direction
Else
Direction = 180 + Direction
End If
End If
Else
If x1 > x2 Then
Direction = 270
Else
Direction = 90
End If
End Function
jeroen79
Jan 31st, 2007, 05:03 AM
I'm not sure he has the coordinates, he mentions that the sensors returns the distance to the target.
Do the sensors also return the bearing relative to that sensor?
In that case you can easily calculate the coordinates of the target and then the angle relative to the midpoint C using the arctangent.
Shaggy Hiker
Jan 31st, 2007, 07:30 AM
I have no bearings, all I have is the information that point N is x cm away from the sensor, and that N is somewhere "in front" of the sensor. As it turns out, there is some evidence that the sensors only see a fairly narrow angle in front of them, so the chance that A, B, and N are all in the same line are basically zero.
Of course, from this, I don't think I really have any coordinates at all. However, Since I know the distance between the sensors (A-B), which is roughly about 14cm, though I might move the eyes inboard to about 10cm.
I can see that if A-N = B-N, then the point is direcly centered in front of the sensors. Also, if (B-N * B-N) = (A-N * A-N) + 100 (assuming I use the inboard location of the sensors), then the object is directly in front of A. The same calculation could be used to find whether the object is directly in front of B, and between these three calculations, I can figure out whether the object is in front of the sensors, or off to one side or the other. However, I am looking for a way to figure out what angle I'd have to turn the sensors such that A-N = B-N, for any initial bearing from 90 degrees left to 90 degrees right.
By the way, I also know my current bearing, but I believe that shouldn't matter to the calculation. The bearing I will be using will be in degrees, too, because all turns will be guided by a magnetic compass.
opus
Jan 31st, 2007, 08:44 AM
now I get your problem!
I understand you have the distances A to N (DistA), B to N (DistA) and the Distance between A and B(Dist)
I always referring to the angle ACN!
You are correct, when DistA=DistB the angle has to be 90 degrees (you can't look behind!).
The angle would 0 if distA=DistB+ Dist
and 180 if DistA=DistB-Dist, the rest is some trigonomtric calculation.
I can't do it right now, but I'm coming back with an answer!
opus
Jan 31st, 2007, 02:36 PM
You need to solve the triangles.
On the "big" Triangle (A-B-N), you know all the distances (AB, AN, BN). To calculate the angle NAB (which is the same as NAC) use this formula:
Angle NAC = ARCCOS(( BN^2 -AN^2 - AB^2) / (-2 *AN * AB))
For the "small" triangle (A-C-N), you know the distance AC (which is AB/2), distance AN and the angle NAC.
To calculate the missing distance CN usie this formula.
CN= SQR (AN^2+ AC^2-2 *AN *AC*cos(Angle NAC))
Now you have all the distances of the small triangle and you can use the first formula to calculate the missing angle:
Angle ACN= = ARCCOS(( AB^2 -AC^2 - NC^2) / (-2 *AC * NC))
I keep my fingers crossed on that one! :wave:
Shaggy Hiker
Jan 31st, 2007, 08:11 PM
Looks complicated. Good thing I have a computer to do the math for me.
Why do you keep your fingers crossed?
opus
Feb 1st, 2007, 12:21 AM
Why do you keep your fingers crossed?
I hope the formulas are correctly stated :wave:
BTW, what application are you working on ("I have two sensors that will be picking up a return echo off", "all turns will be guided by a magnetic compass"), sounds interesting in my ears.
I made some prog's simulating the use of tactics of a submarine hunting aircraft.
Shaggy Hiker
Feb 1st, 2007, 10:20 PM
I decided to build a robot as a target for some learning concepts I had been working on. The time was pretty much right, though I have had to learn electronics along the way, and am still learning. There are loads of platforms out there, and lots of different kinds of sensors that are useful for the various robot brains. I currently have an SRF08 working on the board. It sends out pings, and counts up to 17 return echoes with a resolution of about +/- 2 cm or so. At first I thought of binocular vision to give me bearing to the various items, since all I get from the sensor is distance, then I thought I might go for a quad array sensor with the sensors approximately 10 cm apart. The initial goal is a robot that will wander around the house learning which items are moveable, transitory, stationary, etc. The next step will be to go for more complex behaviors.
I spent today attending a talk which I paid attention to about half the time, and in the other half, designed a series of classes, programs and modules that will run on two of my computers at home. Communication is via bluetooth, which is working ok now, but I have some tests to do to attempt to streamline the response time to a sensor request. Doesn't look like I will be testing that until this weekend.
As you can see, the equation you gave me (which I can test empirically pretty soon), will not be entirely sufficient, but it WILL be a good start. The equation shoudl work well for a point target, but what kind of a response will I get from a wall seen head on? How about a wall at an oblique angle? The legs of a chair? etc. Plenty of learning to do, but I have the framework for how the different modules will interact with the robot fairly well hammered out now, only the parts that will sift the data and form connections have not been worked out yet, nor can I do so until I get some data to work with. Heck, I don't even know how often I should sample the sensors, nor do I know how fast the robot will travel, or for how long.
As a hobby for a geek, it's a good one.
Shaggy Hiker
May 26th, 2007, 07:18 PM
Got thinking that something might be a bit off with my design, so I put a couple numbers into Excel and tried out those equations. With AN=BN=5, I got about the right value for CN, but I'm not sure quite what I ended up with for angle ACN. It sure wasn't right in degrees, but maybe it wasn't supposed to be in degrees?
However, the reason I went looking was because I'm not sure any of this matters. All of these equations require that AN and BN are at least reasonably accurate, right? However, due to the error associated with each eye, A could be seeing a point up to four centimeters different from B. For an object twenty cm away, this would mean a maximum error of 25% away from where the object really is. It seems to me that this could make the math produce some bogus values. Therefore, I intend to do a little testing to see how great an error I am likely to encounter in the real application.
Andy_P
May 27th, 2007, 08:24 AM
Excel will perform trigonometry in Radians by default, not Degrees.
Assuming the angle to be 30 degrees...
If you do SIN(30), it will give the answer -0.98803,
so you have to convert your given angle to radians: r = (x * Pi) / 180
So, in Excel: =SIN(30*PI()/180) gives the answer 0.5.
or use the RADIANS function: =SIN(RADIANS(30)), also gives the answer 0.5.
Don't know if that helps you, or if you already knew that!
Anyway, good luck with your project, sounds interesting. :thumb:
Shaggy Hiker
May 28th, 2007, 09:48 AM
Actually, it never occured to me to look at how Excel was going to handle it. I'll go back and have another look.
Shaggy Hiker
May 28th, 2007, 10:49 AM
Ok, I have now tested the three equations in post #7. It is apparent that something is a bit off on the third one (angle CAN), because the value is right around 90 for all of them. However, it is also clear that I really don't need either CAN or CN, so I can simplify things greatly by throwing out the second two equations, and just using the calculation for angle NAC, which works fine.
Unfortunately, I have also confirmed that I could easily have problems with the error of the readings. If the error is such that |AN-BN| > AB, then the equation falls down, because ACOS(x) isn't happy with x>1.
Fortunately, I can cheat.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.