use distance between two points to determine relative location

I have a pair of fixed location sensors (infrared) that bounce a signal off of a reflector to a fixed receiver (all 3 devices are on a single PCB, [transmitter, receiver, transmitter]). The data given to me by the API of this device is the range from each sensor to the reflector (hand, table, anything).

My question is this: using the above data, how can I determine a relative X position of the reflector. I am fairly sure this is a trivial problem but my brain is drawing a blank.

The data ranges from 0 to 240 for each sensor.

var pos = 120 + (ranges.left - ranges.right);
pos = 100/240 * pos;
pos = Math.round(pos);

This was my initial attempt, the idea being it gives me an x position from 0 to 100. This sort of works, in a jumpy way - but I'd like a more refined method.

While there are a lot of questions on here regarding finding distances between known points, I've not found one doing the reverse (which is what I want to do).

EDIT:

The two dark circles are the transmitters, the light circle is the receiver. The square is the reflector. The line is the X axis, I would like to know the position of the square along that line. But please note that the line may be closer or further away from the sensor at any given point.


I think this works out by looking at triangles...

Using the diagram... 在这里输入图像描述

S is the separation of the two transmitters, R the range to the target, A,B are the distances measured by the device and 'x' is what we're trying to find.

By Pythagoras: (here A^2 denotes A squared)

A^2 = R^2 + x^2       or   A^2 - x^2 =     R^2

and

B^2 = R^2 + (S+x)^2   or   B^2 - (S+x)^2 = R^2

rearrange this to

     A^2 - x^2 = B^2 - (S+x)^2
     A^2 - x^2 = B^2 - S^2 - 2Sx - x^2      expand (S+x)^2
     A^2       = B^2 - S^2 - 2Sx            lose x^2 from both sides
A^2 - B^2 +S^2 = -2Sx                        rearrange

finally:

   A^2 - B^2 + S^2
   _______________  =  x
        -2S

ta da !

I did a quick check measuring on paper and I think it's correct. Another quick check is if A is the same as B, in which case it boils down to:

  -S^2 / 2S  == -S/2  == 1/2 way between the transmitters, which is right.

Edit: following comment below...

Note that the final formula only involves A,B and S. We need S (the distance between transmitters) because this completes the triangle A/B/S and therefore scales the output value. You could use a fixed value for this but the output would not relate directly to the scale of the A or B values. However, you could use s=100 giving...

         A^2 - B^2 + 10000
 x =     _________________  
              -200

or, in javascript:

var pos= ((ranges.left*ranges.left)-(ranges.right*ranges.right)+10000)/200;

this will give a value between 0..100 for the object being directly somewhere between the two sensors eg if both sensor values are, say 42, we get:

pos = (42*42 - 42*42 + 10000) /200; // answer = 50

If the object is directly in front of sensor A, we could have values:

pos= (100*100 - 140*140 + 10000)/200; // answer = 2

or directly in front of B:

pos= (140*140 - 100*100 + 10000)/200; // answer = 98

Further along your 'x' axis will obviously get larger values in one direction and go -ve in the other direction. I hope that makes it clearer.

链接地址: http://www.djcxy.com/p/84946.html

上一篇: 三维多边测量与未知,但比例,距离

下一篇: 使用两点之间的距离来确定相对位置