{"id":15735653,"url":"https://github.com/vahancho/erkir","last_synced_at":"2025-05-06T20:42:00.892Z","repository":{"id":59757672,"uuid":"163296881","full_name":"vahancho/erkir","owner":"vahancho","description":"Երկիր (Erkir) - a C++ library for geodesic and trigonometric calculations","archived":false,"fork":false,"pushed_at":"2024-03-25T10:23:40.000Z","size":138,"stargazers_count":46,"open_issues_count":1,"forks_count":16,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T02:41:14.711Z","etag":null,"topics":["coordinate-systems","coordinates","cpp","cpp11","datum","distance","distance-calculation","earth","ellipsoidal-earth-models","geodesy","geodesy-functions","geodetic","geodetic-aplications","geodetic-datum","geodetic-point","geography","geometry","library","stl","trigonometric-calculations"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vahancho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-27T13:18:46.000Z","updated_at":"2024-11-05T21:56:09.000Z","dependencies_parsed_at":"2023-11-09T15:27:02.857Z","dependency_job_id":"10d4ae1a-48c6-48a8-9cf1-2ba5969d7eb7","html_url":"https://github.com/vahancho/erkir","commit_stats":{"total_commits":134,"total_committers":1,"mean_commits":134.0,"dds":0.0,"last_synced_commit":"6cd7ac27a8a9697cb2310eae9e85d702dc66312a"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vahancho%2Ferkir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vahancho%2Ferkir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vahancho%2Ferkir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vahancho%2Ferkir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vahancho","download_url":"https://codeload.github.com/vahancho/erkir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252768355,"owners_count":21801368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coordinate-systems","coordinates","cpp","cpp11","datum","distance","distance-calculation","earth","ellipsoidal-earth-models","geodesy","geodesy-functions","geodetic","geodetic-aplications","geodetic-datum","geodetic-point","geography","geometry","library","stl","trigonometric-calculations"],"created_at":"2024-10-04T01:14:19.779Z","updated_at":"2025-05-06T20:42:00.864Z","avatar_url":"https://github.com/vahancho.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Երկիր (Erkir) - a C++ library for geodesic and trigonometric calculations\n\n[Erkir (armenian: Երկիր, means Earth)](https://github.com/vahancho/erkir) - is inspired\nby and based on the great work of [Chris Veness](https://github.com/chrisveness),\nthe owner of the [Geodesy functions](https://github.com/chrisveness/geodesy)\nproject - provides a set of comprehensive API for geodesic and trigonometric calculations.\nI would call it a C++ port of JavaScript functions provided by the mentioned Chris Veness' project,\nhowever I designed the library to be more object oriented. Thus the code is organized a\nlittle bit differently, but the implementation itself is preserved.\n\n[![Latest release](https://img.shields.io/github/v/release/vahancho/erkir?include_prereleases)](https://github.com/vahancho/erkir/releases)\n[![Test (CMake)](https://github.com/vahancho/erkir/actions/workflows/cmake.yml/badge.svg)](https://github.com/vahancho/erkir/actions/workflows/cmake.yml)\n[![codecov](https://codecov.io/gh/vahancho/erkir/branch/master/graph/badge.svg)](https://codecov.io/gh/vahancho/erkir)\n\n### Prerequisites\n\nThere are no special requirements and dependencies except *C++11* compliant compiler.\nThe class is tested with *gcc 4.8.4* and *MSVC 15.x* (Visual Studio 2017).\nThe library is written with pure STL without any third party dependencies.\nFor more details see the CI badges (*GitHub Actions*) above.\n\n### Installation\n\nNo installation required. Just incorporate header files from the *include/* and\nsource files from *src/* directories in your project and compile them. All library\nclasses are in *erkir* namespace.\n\n#### Integration with `CMake` projects\n\nHowever, if you use `CMake` and want to integrate the library into your project\nyou might want to install it first by invoking a `CMake` command from the build directory:\n\n```\ncmake --install . --prefix=\u003cinstall_path\u003e --config=Release\n```\n\nOnce the library is installed you can use it from in your project by adjusting its\n`CMake` script. For example:\n\n```\n[..]\nfind_package(erkir REQUIRED)\n\nadd_executable(example main.cpp)\ntarget_link_libraries(example erkir)\n[..]\n```\n\n### The API\n\nThe code is virtually split into three domains (namespaces) that represent spherical\nand ellipsoidal geodetic coordinates and cartesian (x/y/z) for geocentric ones:\n`erkir::spherical`, `erkir::ellipsoidal` and `erkir::cartesian` correspondingly.\nSpherical Earth model based calculations are accurate enough for most cases, however\nin order to gain more precise measurements use `erkir::ellipsoidal` classes.\n\n`erkir::spherical::Point` class implements geodetic point on the basis of a spherical\nearth (ignoring ellipsoidal effects). It uses formulae to calculate distances between\ntwo points (using haversine formula), initial bearing from a point, final bearing to a point, etc.\n\n`erkir::ellipsoidal::Point` class represents geodetic point based on ellipsoidal\nearth model. It includes ellipsoid parameters and datums for different coordinate\nsystems, and methods for converting between them and to Cartesian coordinates.\n\n`erkir::Vector3d` implements 3-d vector manipulation routines. With this class you\ncan perform basic operations with the vectors, such as calculate dot (scalar) product\nof two vectors, multiply vectors, add and subtract them.\n\n`erkir::cartesian::Point` implements ECEF (earth-centered earth-fixed) geocentric\ncartesian (x/y/z) coordinates.\n\n### Usage Examples:\n\n```cpp\n#include \"sphericalpoint.h\"\n#include \"ellipsoidalpoint.h\"\n\nint main(int argc, char **argv)\n{\n  // Calculate great-circle distance between two points.\n  erkir::spherical::Point p1{ 52.205, 0.119 };\n  erkir::spherical::Point p2{ 48.857, 2.351 };\n  auto d = p1.distanceTo(p2); // 404.3 km\n\n  // Get destination point by given distance (shortest) and bearing from start point.\n  erkir::spherical::Point p3{ 51.4778, -0.0015 };\n  auto dest = p3.destinationPoint(7794.0, 300.7); // 51.5135°N, 000.0983°W\n\n  // Convert a point from one coordinates system to another.\n  erkir::ellipsoidal::Point pWGS84(51.4778, -0.0016, ellipsoidal::Datum::Type::WGS84);\n  auto pOSGB = pWGS84.toDatum(ellipsoidal::Datum::Type::OSGB36); // 51.4778°N, 000.0000°E\n\n  // Convert to Cartesian coordinates.\n  auto cartesian = pWGS84.toCartesianPoint();\n\n  // Convert Cartesian point to a geodetic one.\n  auto geoPoint = cartesian-\u003etoGeoPoint();\n\n  return 0;\n}\n```\n\n#### Conversion from/to strings\n\nLibrary supports latitude/longitude coordinates conversion\nin three formats: Degrees Minutes Seconds *(D° M' S\")*,\nDecimal Minutes *(D° M.M')*, and Decimal Degrees *(D.D°)*.\n\n```cpp\nauto lon = Longitude::fromString(\"45° 46’ 47.36” W\");\nauto lat = Latitude::fromString(\"45°46′ 45.36″ N\");\n```\n\n```cpp\nauto lon = Longitude{45.7790};\nauto lonStr = lon.toString(Coordinate::Format::DMS); // 45° 46′ 45.36″ E\n```\n\nFor more usage examples please refer to the unit tests at `/test/test.cpp` file.\n\n### Building and Testing\n\nThere are unit tests. You can find them in the *test/* directory.\nTo run them you have to build and run the test application. For doing that you must invoke the following\ncommands from the terminal, assuming that compiler and environment are already configured:\n\n#### Linux (gcc)\n\n```\nmkdir build \u0026\u0026 cd build\ncmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=True\ncmake --build .\nctest\n```\n\n#### Windows (MSVC Toolchain)\n\n```\nmkdir build \u0026\u0026 cd build\ncmake .. -DENABLE_TESTING=True -A x64\ncmake --build . --config=Release\nctest -C Release\n```\n\nFor x86 builds use `-A Win32` option instead.\n\n### Performance Tests\n\nI measured performance (on Intel Core i5 series processor) for some spherical geodesy\nfunctions (`Point` class). I used similar approach as Chris Veness did in his tests,\ni.e. called functions for 5000 random points or pairs of points. And here are my results:\n\n| Function             | Avg. time/calculation (nanoseconds)|\n| -------------------- |:----------------------------------:|\n| Distance (haversine) | 162                                |\n| Initial bearing      | 190                                |\n| Destination point    | 227                                |\n\n*of course timings are machine dependent*\n\n## See Also\n\n* [Movable Type Scripts Latitude/Longitude Calculations Reference](http://www.movable-type.co.uk/scripts/latlong.html)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvahancho%2Ferkir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvahancho%2Ferkir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvahancho%2Ferkir/lists"}