# geometry – Given distance between cars, how to calculate the relative position and identify if the car is on my left or right?

I am doing decentralized control of vehicles. Assume I am a car with $$2$$ sensors, sensor $$A$$ in front of me and sensor $$B$$ behind. Using this sensors I can measure the distance from me to other vehicles $$C,D$$ and $$E$$. Apart from that I don’t have any other information and I cannot communicate with other cars.

Objective:

1. Calculate the distance between the other cars and their relative position.
2. To figure out if the other cars are behind or in front of me.
3. To figure out if the other cars are on my left or right.

Given length of $$AC$$, I know that finding relative position of car $$C$$ is a right triangle problem. $$AC$$ is hypotenuse, I need to find this right triangles legs. All possible right triangles lie in circle with diameter $$AC$$. However, without defining axis, it is not clear which tringle to choose. So using only sensor $$A$$ we cannot find the relative position.

Now we draw another circle with diameter $$BC$$. And now the two circles will intersect at $$J$$ and that intersection is a point we need to calculate the relative position. Moreover, the intersection of these circles lie on the extension of line $$AB$$. This is very good, we can use line $$AB$$ as $$y$$ axis. Then to find a relative position of car $$C$$ we need to solve two equations with two unknowns:

begin{align} AJ^2+JC^2=AC^2\ (AJ+AB)^2+JC^2=BC^2 end{align}

where we assume $$AB$$ is known in priori.

We can do this for all cars on our right, i.e., $$C$$ and $$D$$. We know their relative position and using this information, we can even calculate the distance between them. However, we need to be careful, we need to know if they are in front of us or behind to be able to calculate the distance between them. But that can be checked comparing $$AC$$ vs $$BC$$. Since $$AC, we know that car $$B$$ is on front, and since $$AD>BD$$, car $$D$$ is behind. Now we have achieved objectives $$1$$ and $$2$$.

However, I have a problem with a left side. I can calculate the car’s $$E$$ relative position, but I don’t know if it is on my right or left. So I cannot calculate distance $$CE$$ or $$DE$$ correctly, there is always two possible answers. Axis $$y$$ is well defined, comparing the distance from $$A$$ and $$B$$ to other cars, we can know if the other car is in $$+y$$ or $$-y$$ side. Axis $$x$$ is not well defined, from distance information we are not able to identify if the car is on our right or left. Is there any smart way to achieve the last objective without adding any additional sensors?