All Projects → mapbox → cheap-ruler-cpp

mapbox / cheap-ruler-cpp

Licence: ISC license
Fast approximations for common geodesic measurements

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to cheap-ruler-cpp

Cheap Ruler
Fast approximations for common geodesic measurements 🌐
Stars: ✭ 334 (+943.75%)
Mutual labels:  fast, distance, measurements
erkir
Երկիր (Erkir) - a C++ library for geodesic and trigonometric calculations
Stars: ✭ 26 (-18.75%)
Mutual labels:  distance, geodesy
Vincenty-Excel
Thaddeus Vincenty's Direct and Inverse formulae for geodesic calculations in Excel (distance, azimuth, latitude, longitude).
Stars: ✭ 29 (-9.37%)
Mutual labels:  distance, geodesy
geodesy-php
Geodesy PHP - Port of some known geodesic/math functions for getting distance from a known point A to a known point B given their coordinates. It also supports conversion between units of length, Polar position to Cartesian coordinates, and different Reference Datums.
Stars: ✭ 26 (-18.75%)
Mutual labels:  distance, geodesy
DynAdjust
Least squares adjustment software
Stars: ✭ 43 (+34.38%)
Mutual labels:  fast, geodesy
fastHistory
A python tool connected to your terminal to store important commands, search them in a fast way and automatically paste them into your terminal
Stars: ✭ 24 (-25%)
Mutual labels:  fast
pony-ssh
vscode plugin for fast remote editing over ssh
Stars: ✭ 26 (-18.75%)
Mutual labels:  fast
rawDiag
Brings Orbitrap Mass Spectrometry Data to Life; Multi-platform, Fast and Colorful R package.
Stars: ✭ 29 (-9.37%)
Mutual labels:  fast
nekros
NekRos is an Open-Source Ransomeware, with advanced Features, Which Looks Like Wannacry and Has C&C Server which can be Used to Retrive KEY
Stars: ✭ 84 (+162.5%)
Mutual labels:  fast
distance
Go lib to calculate distance 🗺
Stars: ✭ 16 (-50%)
Mutual labels:  distance
SAGEMCOM-FAST-5370e-TELIA
This is my personal wiki for hacking the router firmware used by (Sagemcom)F@st Version 3.43.2 delivered from Sagemcom
Stars: ✭ 92 (+187.5%)
Mutual labels:  fast
clifm
The shell-like, command line terminal file manager: simple, fast, extensible, and lightweight as hell
Stars: ✭ 825 (+2478.13%)
Mutual labels:  fast
android-gcc-toolchain
Enable you to use NDK's standalone toolchain easily, quickly and magically for cross-compile
Stars: ✭ 49 (+53.13%)
Mutual labels:  fast
fast-loaded-dice-roller
The Fast Loaded Dice Roller: A Near-Optimal Exact Sampler for Discrete Probability Distributions
Stars: ✭ 41 (+28.13%)
Mutual labels:  fast
vertx-start
简单地、快速地启动vert.x的手脚架,保留了vert.x原汁原味的开发方式
Stars: ✭ 102 (+218.75%)
Mutual labels:  fast
tinyrpc
Much fast, lightweight, async, based boost.beast and protobuf.
Stars: ✭ 32 (+0%)
Mutual labels:  fast
geometry-library
PHP Geometry Library provides utility functions for the computation of geometric data on the surface of the Earth. Code ported from Google Maps Android API.
Stars: ✭ 132 (+312.5%)
Mutual labels:  distance
NeuroMorph
The NeuroMorph analysis and visualization toolkit
Stars: ✭ 57 (+78.13%)
Mutual labels:  measurements
betting
Fast and flexibly API wrapper for betfair
Stars: ✭ 45 (+40.63%)
Mutual labels:  fast
placekey-py
placekey.io
Stars: ✭ 49 (+53.13%)
Mutual labels:  distance

cheap-ruler-cpp

Port to C++ of Cheap Ruler, a collection of very fast approximations to common geodesic measurements.

Build Status

Usage

#include <mapbox/cheap_ruler.hpp>

namespace cr = mapbox::cheap_ruler;

All point, line_string, polygon, and box references are mapbox::geometry data structures.

Create a ruler object

CheapRuler(double latitude, Unit unit)

Creates a ruler object that will approximate measurements around the given latitude with an optional distance unit. Once created, the ruler object has access to the methods below.

auto ruler = cr::CheapRuler(32.8351);
auto milesRuler = cr::CheapRuler(32.8351, cr::CheapRuler::Miles);

Possible units:

  • cheap_ruler::CheapRuler::Unit
  • cheap_ruler::CheapRuler::Kilometers
  • cheap_ruler::CheapRuler::Miles
  • cheap_ruler::CheapRuler::NauticalMiles
  • cheap_ruler::CheapRuler::Meters
  • cheap_ruler::CheapRuler::Yards
  • cheap_ruler::CheapRuler::Feet
  • cheap_ruler::CheapRuler::Inches

CheapRuler::fromTile(uint32_t y, uint32_t z)

Creates a ruler object from tile coordinates (y and z integers). Convenient in tile-reduce scripts.

auto ruler = cr::CheapRuler::fromTile(11041, 15);

Methods

distance(point a, point b)

Given two points of the form [x = longitude, y = latitude], returns the distance (double).

cr::point point_a{-96.9148, 32.8351};
cr::point point_b{-96.9146, 32.8386};
auto distance = ruler.distance(point_a, point_b);
std::clog << distance; // 0.388595

bearing(point a, point b)

Returns the bearing (double) between two points in angles.

cr::point point_a{-96.9148, 32.8351};
cr::point point_b{-96.9146, 32.8386};
auto bearing = ruler.bearing(point_a, point_b);
std::clog << bearing; // 2.76206

destination(point origin, double distance, double bearing)

Returns a new point (point) given distance and bearing from the starting point.

cr::point point_a{-96.9148, 32.8351};
auto dest = ruler.destination(point_a, 1.0, -175);
std::clog << dest.x << ", " << dest.y; // -96.9148, 32.8261

offset(point origin, double dx, double dy)

Returns a new point (point) given easting and northing offsets from the starting point.

cr::point point_a{-96.9148, 32.8351};
auto os = ruler.offset(point_a, 10.0, -5.0);
std::clog << os.x << ", " << os.y; // -96.808, 32.79

lineDistance(const line_string& points)

Given a line (an array of points), returns the total line distance (double).

cr::line_string line_a{{ -96.9, 32.8 }, { -96.8, 32.8 }, { -96.2, 32.3 }};
auto line_distance = ruler.lineDistance(line_a);
std::clog << line_distance; // 88.2962

area(polygon poly)

Given a polygon (an array of rings, where each ring is an array of points), returns the area (double).

cr::linear_ring ring{{ -96.9, 32.8 }, { -96.8, 32.8 }, { -96.2, 32.3 }, { -96.9, 32.8 }};
auto area = ruler.area(cr::polygon{ ring });
std::clog << area; //

along(const line_string& line, double distance)

Returns the point (point) at a specified distance along the line.

cr::linear_ring ring{{ -96.9, 32.8 }, { -96.8, 32.8 }, { -96.2, 32.3 }, { -96.9, 32.8 }};
auto area = ruler.area(cr::polygon{ ring });
std::clog << area; // 259.581

pointOnLine(const line_string& line, point p)

Returns a tuple of the form std::pair<point, unsigned> where point is closest point on the line from the given point, index is the start index of the segment with the closest point, and t is a parameter from 0 to 1 that indicates where the closest point is on that segment.

cr::line_string line{{ -96.9, 32.8 }, { -96.8, 32.8 }, { -96.2, 32.3 }};
cr::point point{-96.9, 32.79};
auto pol = ruler.pointOnLine(line, point);
auto point = std::get<0>(pol);
std::clog << point.x << ", " << point.y; // -96.9, 32.8 (point)
std::clog << std::get<1>(pol); // 0 (index)
std::clog << std::get<2>(pol); // 0. (t)

lineSlice(point start, point stop, const line_string& line)

Returns a part of the given line (line_string) between the start and the stop points (or their closest points on the line).

cr::line_string line{{ -96.9, 32.8 }, { -96.8, 32.8 }, { -96.2, 32.3 }};
cr::point start_point{-96.9, 32.8};
cr::point stop_point{-96.8, 32.8};
auto slice = ruler.lineSlice(start_point, stop_point, line);
std::clog << slice[0].x << ", " << slice[0].y; // -96.9, 32.8
std::clog << slice[1].x << ", " << slice[1].y; // -96.8, 32.8

lineSliceAlong(double start, double stop, const line_string& line)

Returns a part of the given line (line_string) between the start and the stop points indicated by distance along the line.

cr::line_string line{{ -96.9, 32.8 }, { -96.8, 32.8 }, { -96.2, 32.3 }};
auto slice = ruler.lineSliceAlong(0.1, 1.2, line);

bufferPoint(point p, double buffer)

Given a point, returns a bounding box object ([w, s, e, n]) created from the given point buffered by a given distance.

cr::point point{-96.9, 32.8};
auto box = ruler.bufferPoint(point, 0.1);

bufferBBox(box bbox, double buffer)

Given a bounding box, returns the box buffered by a given distance.

cr::box bbox({ 30, 38 }, { 40, 39 });
auto bbox2 = ruler.bufferBBox(bbox, 1);

insideBBox(point p, box bbox)

Returns true (bool) if the given point is inside in the given bounding box, otherwise false.

cr::box bbox({ 30, 38 }, { 40, 39 });
auto inside = ruler.insideBBox({ 35, 38.5 }, bbox);
std::clog << inside; // true

Develop

# create targets
cmake .

# build
make

# test
./cheap_ruler

# or just do it all in one!
cmake . && make && ./cheap_ruler
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].