https://github.com/felipe-sant/maps
π Development of an application that generates two random points in Brazil and simulates a flight between these points, taking into account the curvature of the Earth. It uses an IBGE API to control the coordinates and identify the state of Brazil through which the plane is passing.
https://github.com/felipe-sant/maps
ibge-api maps typescript
Last synced: about 1 year ago
JSON representation
π Development of an application that generates two random points in Brazil and simulates a flight between these points, taking into account the curvature of the Earth. It uses an IBGE API to control the coordinates and identify the state of Brazil through which the plane is passing.
- Host: GitHub
- URL: https://github.com/felipe-sant/maps
- Owner: felipe-sant
- License: mit
- Created: 2024-12-05T20:56:51.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-27T13:38:33.000Z (over 1 year ago)
- Last Synced: 2025-02-08T15:31:45.202Z (over 1 year ago)
- Topics: ibge-api, maps, typescript
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# π Maps πΊοΈ

Development of an application that generates two random points in Brazil and simulates a flight between these points, taking into account the curvature of the Earth. It uses an IBGE API to control the coordinates and identify the state of Brazil through which the plane is passing.
> [Visit the website here!](https://front-maps.vercel.app/)
## βοΈ How to run
1. Clone the repository and start the submodules.
git clone https://github.com/felipe-sant/Maps.git
cd Maps
git submodule update --init --recursive
2. Download the dependencies in both repositories.
cd Back
npm install
cd ..
cd Front
npm install
3. Run both repositories with the command:
npm start
## π Contents covered
- Calculation of geodesic lines;
- Implementation of external APIs.
- Map rendering;
Calculation of geodesic lines
#### 1. Conversion to Radians
The latitude and longitude angles, given in degrees, are converted to radians:
latβ = startPoint.lat Γ Ο/180
lonβ = startPoint.lon Γ Ο/180
latβ = endPoint.lat Γ Ο/180
lonβ = endPoint.lon Γ Ο/180
#### 2. Calculation of the Angle Between Points (ΞΟ)
The central angle (ΞΟ) between the two points on the sphere is computed using the dot product in 3D space:
ΞΟ = arccos(sin(latβ) β
sin(latβ) + cos(latβ) β
cos(latβ) β
cos(lonβ - lonβ))
if ΞΟ = 0, the points are identical, and the function directly returns the starting point.
#### 3. Interpolation Coefficients (π and π)
The coefficients π and π determine the contribution of each point in the interpolation, using trigonometric functions:
π = sin((1 - π‘) β
ΞΟ) / sin(ΞΟ)
π = sin(π‘ β
ΞΟ) / sin(ΞΟ)
Here:
- π‘ is the interpolation parameter (0 corresponds to the starting point, and 1 corresponds to the ending point).
- sin(Ξπ) normalizes the coefficients to ensure correct interpolation along the spherical arc.
#### 4. Interpolation in 3D Space
The points are treated as 3D vectors projected onto the sphere, with coordinates:
π₯ = π β
cos(latβ) β
cos(lonβ) + π β
cos(latβ) β
cos(lonβ)
π¦ = π β
cos(latβ) β
sin(lonβ) + π β
cos(latβ) β
sin(lonβ)
π§ = π β
sin(latβ) + π β
sin(latβ)
#### 5. Conversion Back to Latitude and Longitude
The interpolated coordinates (π₯, π¦, π§) are converted back to latitude and longitude:
lat = arctan2(π§, β(π₯Β² + π¦Β²))
lon = arctan2(π¦, π₯)
Finally, the values are converted from radians to degrees:
lat = lat Γ 180/Ο
lon = lon Γ 180/Ο
#### Mathematical Summary of the Function
The interpolation calculates the intermediate point π‘ along the spherical arc between two points on the Earth's surface, with:
1. ΞΟ determining the angular distance between the points.
2. π and π weighting the vectors of the start and end points.
3. The resulting 3D vectors being converted back into geographic coordinates.
This enables smooth movement of a point between two locations while maintaining the geodesic trajectory.
Implementation of external APIs
In this project, I used an external API from **IBGE** to implement geographic meshes. The API was utilized to identify geographic coordinates and retrieve information about the state or municipality a specific coordinate references. This integration ensured accurate mapping of coordinates to administrative regions.
Map rendering
One of the key topics covered in this project was map rendering, using the **Leaflet** library. With Leaflet, it was possible not only to render interactive maps but also to manage the coordinates of points on the map, ensuring precise control over the location and interaction of geographic elements. This approach enabled the creation of dynamic and functional visualizations for efficiently exploring spatial data.