I am creating a radar for loud sounds, which aims to monitor the production of noise that may be harmful to specific regions of a city. To carry out this project, I developed an arduino prototype, which has three microphones and a camera. Basically, my program would have to do a triangulation, based on the data delivered by the microphones, so that we could identify the source of the sound. This is where the program for calculating the intersection of three circles would come in.
The position of each of the circles would be given from the positioning of the microphones, and the radius would be given from the difference in time that each microphone took to identify the loud noise. After receiving this data, the values in seconds would be transformed into meters through a simple conversion.
The biggest problem with this project is that the first microphone that identifies the noise will have a time difference of 0 seconds, as this would be the reference for the other microphones.
To solve this problem, the function developed by rebrid and improved by Jacques Gaudin (In python how to get intersection point of three or more circles with or without error) would run in a while loop while the ans.success variable is equal to False, while the loop will add 0.01m to the radius of each circumference so that at some point it is found a valid solution to the problem. Having said that my code looked like this:
import matplotlib.pyplot as plt
from scipy.optimize import least_squares
def intersectionPoint(p1,p2,p3):
x1, y1, dist_1 = (p1[0], p1[1], p1[2])
x2, y2, dist_2 = (p2[0], p2[1], p2[2])
x3, y3, dist_3 = (p3[0], p3[1], p3[2])
def eq(g):
x, y = g
return (
(x - x1)**2 + (y - y1)**2 - dist_1**2,
(x - x2)**2 + (y - y2)**2 - dist_2**2,
(x - x3)**2 + (y - y3)**2 - dist_3**2)
guess = (x1, y1 + dist_1)
ans = least_squares(eq, guess, ftol=None, xtol=None)
return ans
def pltC():
figure, ax = plt.subplots()
C1 = plt.Circle((ca[0], ca[1]), r1, fill = False)
C2 = plt.Circle((cb[0], cb[1]), r2, fill = False)
C3 = plt.Circle((cc[0], cc[1]), r3, fill = False)
Ci = plt.Circle((ans.x[0], ans.x[1]), 0.1)
ax.set_aspect(1)
ax.set_xlim([0, 10])
ax.set_ylim([0, 10])
ax.add_artist(C1)
ax.add_artist(C2)
ax.add_artist(C3)
ax.add_artist(Ci)
plt.title("Exemplo Intersecção de Circluos com o Calculo")
plt.show()
r1 = 2
r2 = 0
r3 = 4
ca = (0, 0)
cb = (0, 6)
cc = (8, 0)
ans = intersectionPoint((ca[0], ca[1], r1), (cb[0], cb[1], r2), (cc[0], cc[1], r3))
while ans.success == False:
r1 = round(r1 + 0.01, 2)
r2 = round(r2 + 0.01, 2)
r3 = round(r3 + 0.01, 2)
ca = (0, 0)
cb = (0, 6)
cc = (8, 0)
ans = intersectionPoint((ca[0], ca[1], r1), (cb[0], cb[1], r2), (cc[0], cc[1], r3))
pltC()
print(ans.success)
print(ans.x)
print(r1, r2, r3)
But I'm having a problem as the code is not returning the correct value. It is possible to see in the code that the radius of the first circle (r1
) has a value of 2
m, r2
has a value of 0
m and r3
has a value of 4
m.
The correct result with this information would be a point of positions x = 3
and y = 4
, where r1 = 5
, r2 = 3
and r3 = 7
.
But for some reason the program returns us a point with the coordinates x = 2.50377477
and y = 3.74999764
, where r1 = 4.45
, r2 = 2.45
and r3 = 6.45
.
Upon drawing these circles, it is clear that the circles do not meet at a single point.
I tried to solve this problem by changing the parameters of the guess variable, but that didn't seem to help