Skip to content

Commit

Permalink
why cant the earth be flat and the units in meters
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander James Wallar committed Jan 23, 2014
1 parent 27a400c commit 099454a
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions locaudio/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ def distance_from_sound(r_ref, l_ref, l_current):
@param lCurrent Newly measured sound pressure level
@return The predicted radius from a node event that the sound will be
located at given the current sound pressure level
located at given the current sound pressure level.
"""

return r_ref * math.pow(10, (l_ref - l_current) / 20)
return r_ref * math.pow(10, (l_ref - l_current) / float(20))


def meters_to_lat_lng_dist(meters):
return meters / float(111 * 1000)


def distance_from_detection_event(x, y, node_event):
Expand All @@ -82,10 +86,20 @@ def distance_from_detection_event(x, y, node_event):
"""

return math.sqrt(
math.pow(x - node_event.x, 2) +
math.pow(y - node_event.y, 2)
)
earth_radius = 6373 * 1000
degrees_to_radians = math.pi / 180.0

phi1 = (90.0 - x) * degrees_to_radians
phi2 = (90.0 - node_event.x) * degrees_to_radians

theta1 = y * degrees_to_radians
theta2 = node_event.y * degrees_to_radians

cos = (math.sin(phi1) * math.sin(phi2) * math.cos(theta1 - theta2) +
math.cos(phi1) * math.cos(phi2))
arc = math.acos(cos)

return earth_radius * arc


def normal_distribution(x):
Expand Down Expand Up @@ -172,8 +186,12 @@ def position_evaluation(x, y, r_ref, l_ref, node_events):
[
normal_distribution(
(
distance_from_detection_event(x, y, n) -
distance_from_sound(r_ref, l_ref, n.spl)
meters_to_lat_lng_dist(
distance_from_detection_event(x, y, n)
) -
meters_to_lat_lng_dist(
distance_from_sound(r_ref, l_ref, n.spl)
)
) / n.get_std()
) / n.get_std() for n in node_events
]
Expand Down Expand Up @@ -432,7 +450,6 @@ def plot_detection_events(res, r_ref, l_ref, d_events, filename):
ax = fig.add_subplot(111)
ax.set_xlabel("X Location")
ax.set_ylabel("Y Location")

v_min = -10
v_max = 10
v_step = 0.1
Expand Down

0 comments on commit 099454a

Please sign in to comment.