A Math Question

A Math Question

February 5, 2020
Math

On CodeProject site I found the following question:

Hi all,

I need help in a math issue:

Let’s say I have 3 measuring devices which give me a distance. Mechanically those 3 sensors are mounted more or less in the right position, but we can’t be sure of the angle neither position the measuring devices are mounted. I have 3 Mastering parts (3 circumferences of a known radius) that I can mount into the machine at any moment and that I want to use to calibrate the system. The measuring error of the 3 measuring devices can be dismissed. This is a small diagram to represent the problem:

2 known master circumferences give me a distance [d1] between circumferences (d1 = radius 1 - radius 2). For each circumference the sensor will give me a different measure m1 and m2. Given the difference between r1-r2 and m2-m1 could I find the angle in which the measuring device is mounted?

Summarizing:

2 master circumferences mounted in the same center. 3 external measuring devices mounted completely unaligned with the center. I don’t know the measuring devices position. The red lines in the drawing are the vector lines the measuring device measures would be placed into. The real measures (in this drawing) would be the distance from the sensor to the position where the red line crosses a circle. Any help will be welcome… Thank you all…

Solution #

If sensor has coordinates $(x_0, y_0)$ and measures along a line with slope $s$, the equation of measuring line is:

$$ y-y_0 = s(x-x_0) \tag{ 1 } $$
or
$$ y = s(x-x_0)+y_0 \tag{ 2 } $$
The equation of the mastering piece of radius $R$ is:
$$ x^2 + y^2 = R^2 \tag{ 3 } $$
The $x$ coordinate of intersection point can be found by replacing $y$ in the previous equation:
$$ x^2+[s(x-x_0)+y_0]^2=R^2 \tag{ 4 } $$
or
$$ x^2 + (s\,x+y_0-s\,x_0)^2 = R^2 \tag{ 5 } $$
Basic algebraic manipulations give:
$$ (s^2+1)x^2+2(s\,y_0-s^2x_0)x+(s\,x_0-y_0)^2-R^2 = 0 \tag{ 6 } $$
The distance measured by sensor is: $d^2 = (x-x_0)^2 + (y-y_0)^2$ Where $x$ and $y$ are the coordinates of the intersection point between circle and measuring line. Because the point is on the line given by equation (2), we can replace $y$:
$$ (x-x_0)^2+[s(x-x_0)+y-y_0]^2 = d^2 \tag{ 7 } $$
which simplifies to:
$$ (x-x_0)^2(s^2+1)=d^2 \tag{ 8 } $$
giving
$$ x=x_0\pm\frac{d}{\sqrt{s^2+1}} \tag{ 9 } $$
Depending on the quadrant where the senor is installed, the sign is taken as negative in quadrants I and IV or positive in quadrants II and III. Here we assume the sensor is in first quadrant and we choose the negative sign.

Replacing this solution in equation (6) we write the magic formula:

$$ \begin{align} F(x_0,y_0, s, d, R) = &(s^2+1)\left(x_0-\frac{d}{\sqrt{s^2+1}}\right)^2+2s(y_0-s\,x_0)\left(x_0-\frac{d}{\sqrt{s^2+1}}\right) \cr &+(s\,x_0-y_0)^2-R^2 \end{align} \tag{ 10 } $$

Numerical example #

First lets make a CAD drawing: And these are the numerical values: $s = \tan(32.44^\circ)$; $x_0=2.531$; $y=1.609$; $R_1=1$; $R_2=1.5$; $R_3=2$; $d_1=1.999$; $d_2=1.499$; $d_3=0.999$

Our magic formula evaluates indeed to values close to 0 within the limits of our CAD tolerances:

$$ \begin{align} F(x_0, y_0, s, d_1, R_1) = 2.805\times10^{-4} \cr F(x_0, y_0, s, d_2, R_2) = 4.207\times10^{-4} \cr F(x_0, y_0, s, d_3, R_3) = 5.609\times10^{-4} \end{align} $$
We can use the Mathcad solver to get something more accurate:

Given

$$ \begin{align} F(x_0, y_0, s, d_1, R_1) = 0 \cr F(x_0, y_0, s, d_2, R_2) = 0 \cr F(x_0, y_0, s, d_3, R_3) = 0 \end{align} $$

$$ \begin{align} \pmatrix{X \cr Y \cr S} = Find(x_0,y_0,s) \end{align} $$

$$ \begin{align} X = 2.53096325 \cr Y = 1.60879645 \cr S = 0.63564596 \end{align} $$
The accuracy has increased dramatically:
$$ \begin{align} F(x_0, y_0, s, d_1, R_1) = -1.587\times10^{-12} \cr F(x_0, y_0, s, d_2, R_2) = -2.385\times10^{-12}\cr F(x_0, y_0, s, d_3, R_3) = -3.184\times10^{-12} \end{align} $$