Skip to content

Commit

Permalink
Merge pull request #89 from JohnMarzulli/breadcrumb_tracker
Browse files Browse the repository at this point in the history
Add TronTrail/Breadcrumb Position Overlay
  • Loading branch information
JohnMarzulli authored Aug 7, 2021
2 parents 0d1f6b3 + 8c547f4 commit a41285c
Show file tree
Hide file tree
Showing 12 changed files with 471 additions and 64 deletions.
36 changes: 27 additions & 9 deletions common_utils/fast_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
TWO_PI = 2.0 * math.pi

# Fill the quick trig look up tables.
for __degrees__ in range(0, 361):
for __degrees__ in range(361):
__radians__ = math.radians(__degrees__)

__RADIANS_BY_DEGREES__[__degrees__] = __radians__
Expand All @@ -24,7 +24,7 @@
COS_BY_DEGREES[__degrees__] = math.cos(__radians__)
TAN_BY_DEGREES[__degrees__] = math.tan(__radians__)

for __indexed_radians__ in range(0, int(TWO_PI * 100)):
for __indexed_radians__ in range(int(TWO_PI * 100)):
__actual_radians__ = __indexed_radians__ / 100.0
__DEGREES_BY_RADIANS___[
__indexed_radians__] = math.degrees(__actual_radians__)
Expand Down Expand Up @@ -129,8 +129,8 @@ def interpolatef(
float -- The number that is the given amount between the left and right.
"""

true_left_value = left_value if left_value < right_value else right_value
true_right_value = right_value if left_value < right_value else left_value
true_left_value = min(left_value, right_value)
true_right_value = max(left_value, right_value)

proportion = clamp(0.0, proportion, 1.0)

Expand Down Expand Up @@ -251,9 +251,7 @@ def get_circle_points(
arc_radians = (angle_chunks / radius)
arc_radians = max(0.1, arc_radians)

points = [[int(x + (radius * math.sin(radian))), int(y + (radius * math.cos(radian)))] for radian in rangef(0, TWO_PI, arc_radians)]

return points
return [[int(x + (radius * math.sin(radian))), int(y + (radius * math.cos(radian)))] for radian in rangef(0, TWO_PI, arc_radians)]


@lru_cache(maxsize=360)
Expand Down Expand Up @@ -431,10 +429,30 @@ def rotate_points(
rotated_points = [[point[0] * rotation_cos - point[1] * rotation_sin,
point[0] * rotation_sin + point[1] * rotation_cos] for point in detranslated_points]

translated_points = translate_points(rotated_points, rotation_center)
return translate_points(rotated_points, rotation_center)


def distance(
start: list,
end: list
) -> float:
"""
Returns the distance between a start and ending x,y
Args:
start (list): The starting position
end (list): The ending position
Returns:
float: the distance between the two points
"""

return translated_points
a = end[0] - start[0]
a *= a
b = end[1] - start[1]
b *= b

return math.sqrt(a + b)

if __name__ == '__main__':
import doctest
Expand Down
85 changes: 85 additions & 0 deletions common_utils/geo_math.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""
Module for handling math around coordinates
"""

import math

EARTH_RADIUS_NAUTICAL_MILES = 3440
EARTH_RADIUS_STATUTE_MILES = 3956
EARTH_RADIUS_KILOMETERS_MILES = 6371


def get_bearing(
starting_pos: list,
ending_pos: list
) -> float:
"""
Returns the bearing to the second GPS coord from the first.
Arguments:
starting_pos {(float,float)} -- The starting lat/long
ending_pos {(float,float)} -- The ending lat/long
Returns:
float -- The bearing to lat2/lon2
"""
lat = starting_pos[0]
lon = starting_pos[1]

lat2 = ending_pos[0]
lon2 = ending_pos[1]

teta1 = math.radians(lat)
teta2 = math.radians(lat2)
delta2 = math.radians(lon2-lon)

y = math.sin(delta2) * math.cos(teta2)
x = math.cos(teta1)*math.sin(teta2) - math.sin(teta1)*math.cos(teta2)*math.cos(delta2)
brng = math.atan2(y, x)
brng = math.degrees(brng)
brng = ((int(brng) + 360) % 360)

return brng


def get_distance(
starting_pos: list,
ending_pos: list
) -> float:
"""
Returns the distance to the traffic from the given point.
Arguments:
starting_pos {(float,float)} -- The starting lat/long
ending_pos {(float,float)} -- The ending lat/long
Returns:
float -- The distance in STATUTE MILES between the given GPS points.
"""

lat1 = starting_pos[0]
lon1 = starting_pos[1]

lat2 = ending_pos[0]
lon2 = ending_pos[1]

# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2])

# haversine formula
delta_lon = lon2 - lon1
delta_lat = lat2 - lat1
a = math.sin(delta_lat / 2) ** 2 + math.cos(lat1) * \
math.cos(lat2) * math.sin(delta_lon / 2) ** 2
c = 2 * math.asin(math.sqrt(a))
# Radius of earth. Can change with units
r = EARTH_RADIUS_STATUTE_MILES

return c * r


# Expected is around 85
#kawo = [47.5, -122.2]
#kosh = [44.0, -88.5]
#print(get_bearing_close(kawo, kosh))
#print(get_bearing(kawo, kosh))
22 changes: 0 additions & 22 deletions configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ def get_json_from_config(
Configuration.MAX_MINUTES_BEFORE_REMOVING_TRAFFIC_REPORT_KEY: self.max_minutes_before_removal,
Configuration.DISTANCE_UNITS_KEY: self.get_units(),
Configuration.ENABLE_DECLINATION_KEY: self.__is_declination_enabled__,
Configuration.DECLINATION_KEY: self.get_declination(),
Configuration.DEGREES_OF_PITCH_KEY: self.get_degrees_of_pitch(),
Configuration.PITCH_DEGREES_DISPLAY_SCALER_KEY: self.get_pitch_degrees_display_scaler(),
Configuration.AITHRE_KEY: self.aithre_enabled,
Expand Down Expand Up @@ -280,12 +279,6 @@ def set_from_json(
self.__is_declination_enabled__ = bool(json_config[Configuration.ENABLE_DECLINATION_KEY])
self.__configuration__[Configuration.ENABLE_DECLINATION_KEY] = self.__is_declination_enabled__

if Configuration.DECLINATION_KEY in json_config:
self.declination = float(
json_config[Configuration.DECLINATION_KEY])
self.__configuration__[
Configuration.DECLINATION_KEY] = self.declination

if Configuration.DEGREES_OF_PITCH_KEY in json_config:
self.degrees_of_pitch = int(
json_config[Configuration.DEGREES_OF_PITCH_KEY])
Expand Down Expand Up @@ -367,18 +360,6 @@ def set_declination_enabled(

self.__is_declination_enabled__ = is_enabled

def get_declination(
self
) -> float:
"""
Returns the magnetic variance (true to magnetic)
Returns:
float -- The number of degrees to adjust the heading displayed by.
"""

return self.declination

def get_traffic_manager_address(
self
) -> str:
Expand Down Expand Up @@ -617,9 +598,6 @@ def __init__(
self.__is_declination_enabled__ = self.__get_config_value__(
Configuration.ENABLE_DECLINATION_KEY,
True)
self.declination = self.__get_config_value__(
Configuration.DECLINATION_KEY,
0.0)
self.aithre_enabled = self.__get_config_value__(
Configuration.AITHRE_KEY,
True)
Expand Down
Loading

0 comments on commit a41285c

Please sign in to comment.