{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example usage\n", "\n", "To use `karney` in a project:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1.0.2\n" ] } ], "source": [ "import karney\n", "\n", "print(karney.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Surface distance\n", " \n", "Find the surface distance sAB (i.e. great circle distance) between two\n", "positions A and B. The heights of A and B are ignored, i.e. if they don't have\n", "zero height, we seek the distance between the points that are at the surface of\n", "the Earth, directly above/below A and B. Use Earth radius 6371e3 m.\n", "Compare the results with exact calculations for the WGS-84 ellipsoid.\n", "\n", "In geodesy this is known as \"The second geodetic problem\" or\n", "\"The inverse geodetic problem\" for a sphere/ellipsoid.\n", "\n", "### Solution for a sphere:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Ex5: Great circle = 332.46 km'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "from karney.geodesic import rad, sphere_distance_rad, distance\n", "\n", "latlon_a = (88, 0)\n", "latlon_b = (89, -170)\n", "latlons = latlon_a + latlon_b\n", "r_Earth = 6371e3 # m, mean Earth radius\n", "s_AB = sphere_distance_rad(*rad(latlons))[0]*r_Earth\n", "s_AB = distance(*latlons, a=r_Earth, f=0, degrees=True)[0] # or alternatively\n", "\n", "\"Ex5: Great circle = {:5.2f} km\".format(s_AB / 1000)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exact solution for the WGS84 ellipsoid:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Ellipsoidal distance = 333.95 km'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s_12, azi1, azi2 = distance(*latlons, degrees=True)\n", "\"Ellipsoidal distance = {:5.2f} km\".format(s_12 / 1000)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A and azimuth/distance to B\n", " \n", "We have an initial position A, direction of travel given as an azimuth\n", "(bearing) relative to north (clockwise), and finally the\n", "distance to travel along a great circle given as sAB.\n", "Use Earth radius 6371e3 m to find the destination point B.\n", "\n", "In geodesy this is known as \"The first geodetic problem\" or\n", "\"The direct geodetic problem\" for a sphere.\n", "\n", " \n", "### Greatcircle solution" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Ex8, Destination: lat, lon = 79.9915 deg, -90.0177 deg'" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from karney.geodesic import reckon\n", "lat, lon = 80, -90\n", "\n", "lat2, lon2, azi_b = reckon(lat, lon, distance=1000, azimuth=200, a=6371e3, f=0, degrees=True)\n", "\n", "msg = \"Ex8, Destination: lat, lon = {:4.4f} deg, {:4.4f} deg\"\n", "msg.format(lat2, lon2)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.allclose(azi_b, -160.0174292682187)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exact solution:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Ex8, Destination: lat, lon = 79.9916 deg, -90.0176 deg'" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lat_b, lon_b, azi_b = reckon(lat, lon, distance=1000, azimuth=200, degrees=True)\n", "msg.format(lat_b, lon_b)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.allclose(azi_b, -160.01742926820506)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.13" } }, "nbformat": 4, "nbformat_minor": 4 }