-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support of loading global map origin from yaml
Signed-off-by: ktro2828 <[email protected]>
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .color import * # noqa | ||
from .geography import * # noqa | ||
from .viewer import * # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
import math | ||
from typing import TYPE_CHECKING | ||
|
||
import numpy as np | ||
|
||
if TYPE_CHECKING: | ||
from t4_devkit.typing import TranslationType | ||
|
||
|
||
__all__ = ["calculate_geodetic_point"] | ||
|
||
EARTH_RADIUS_METERS = 6.378137e6 | ||
FLATTENING = 1 / 298.257223563 | ||
|
||
|
||
def calculate_geodetic_point( | ||
position: TranslationType, | ||
origin: tuple[float, float], | ||
) -> tuple[float, float]: | ||
"""Transform a position in a map coordinate system to a position in a geodetic coordinate system. | ||
Args: | ||
position (TranslationType): 3D position in a map coordinate system. | ||
origin (tuple[float, float]): Map origin position in a geodetic coordinate system, | ||
which is (latitude, longitude). | ||
Returns: | ||
tuple[float, float]: Transformed position in a geodetic coordinate system, | ||
which is (latitude, longitude). | ||
""" | ||
x, y, _ = position | ||
bearing = math.atan2(x, y) | ||
distance = math.hypot(x, y) | ||
|
||
latitude, longitude = np.radians(origin) | ||
angular_distance = distance / EARTH_RADIUS_METERS | ||
|
||
target_latitude = math.asin( | ||
math.sin(latitude) * math.cos(angular_distance) | ||
+ math.cos(latitude) * math.sin(angular_distance) * math.cos(bearing) | ||
) | ||
target_longitude = longitude + math.atan2( | ||
math.sin(bearing) * math.sin(angular_distance) * math.cos(latitude), | ||
math.cos(angular_distance) - math.sin(latitude) * math.sin(target_latitude), | ||
) | ||
|
||
return math.degrees(target_latitude), math.degrees(target_longitude) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters