Finding angle based on distance data

geometry

I have a robot with 2 ultrasonic sensors per side on all 4 sides (so a total of 8 sensors) which are 200mm apart from each other like the picture below:
enter image description here

The dashed lines represent the distance of the sensor to the sides of the walls when the robot is near a corner (all of the sensors are measuring distance perpendicular to the side they're mounted on). Is it possible to calculate the angle that the robot is making with respect to the walls based on this data?

I thought about it and if we consider this like a line intersection problem (line going through an origin) and then try to calculate m (slope) and then use tan-1 to convert into angles but I'm not sure if this is a valid approach.

Best Answer

Sensors compared to the wall

You basically have the right idea. The diagram above represents the bottom sensors, with the one on the left indicating a distance of $d1$ and the one on the right indicating a distance of $d2$. Add the labels shown, and the line $DC$ which is parallel to the line $AB$. Note that $ABCD$ is a rectangle, so $\angle DCE = 90^{\circ}$. Also, I believe you want to determine $\angle CDE$ as being the angle the robot is making wrt to the bottom wall. If so, then using the $\triangle DCE$, you have

$$\tan(\angle CDE) = \frac{d2 - d1}{200} \implies \angle CDE = \tan^{-1}\left(\frac{d2 - d1}{200}\right) \tag{1}\label{eq1A}$$

Based on my understanding of what you mean by the angle wrt the wall, the result from \eqref{eq1A} also gives the angle of the robot compared to the right wall.

Related Question