Line data Source code
1 : import 'dart:math';
2 :
3 : import 'package:great_circle_distance/src/formula/harvesine.dart';
4 : import 'package:great_circle_distance/src/formula/spherical_lawofcosines.dart';
5 : import 'package:great_circle_distance/src/formula/vincenty.dart';
6 :
7 : /// The great-circle is shortest distance between two points on the surface of a sphere
8 : /// See [Great-circle distance](https://en.wikipedia.org/wiki/Great-circle_distance)
9 : class GreatCircleDistance {
10 :
11 : double latitude1;
12 : double longitude1;
13 :
14 : double latitude2;
15 : double longitude2;
16 :
17 : GreatCircleDistance.fromRadians(
18 0 : {this.latitude1, this.longitude1, this.latitude2, this.longitude2});
19 :
20 : GreatCircleDistance.fromDegrees(
21 2 : {this.latitude1, this.longitude1, this.latitude2, this.longitude2}) {
22 6 : this.latitude1 = _radiansFromDegrees(latitude1);
23 6 : this.longitude1 = _radiansFromDegrees(longitude1);
24 :
25 6 : this.latitude2 = _radiansFromDegrees(latitude2);
26 6 : this.longitude2 = _radiansFromDegrees(longitude2);
27 : }
28 :
29 : double _radiansFromDegrees(final double degrees) {
30 4 : return degrees * (PI / 180.0);
31 : }
32 :
33 : /// Calculate distance using the Haversine formula
34 : /// The haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes
35 : /// See [Haversine formula](https://en.wikipedia.org/wiki/Haversine_formula)
36 : double haversineDistance() {
37 0 : return Haversine.distance(this.latitude1, this.longitude1, this.latitude2, this.longitude2);
38 : }
39 :
40 : /// Calculate distance using Spherical law of cosines
41 : /// See [Spherical law of cosines](https://en.wikipedia.org/wiki/Spherical_law_of_cosines)
42 : double sphericalLawOfCosinesDistance() {
43 0 : return Spherical_LawOfCosines.distance(this.latitude1, this.longitude1, this.latitude2, this.longitude2);
44 : }
45 :
46 : /// Calculate distance using Vincenty formula
47 : /// Vincenty's formulae are two related iterative methods used in geodesy to calculate the distance between two points on the surface of a spheroid
48 : /// They are based on the assumption that the figure of the Earth is an oblate spheroid, and hence are more accurate than methods that assume a spherical Earth, such as great-circle distance
49 : /// See [Vincenty's formulae](https://en.wikipedia.org/wiki/Vincenty%27s_formulae)
50 : double vincentyDistance() {
51 10 : return Vincenty.distance(this.latitude1, this.longitude1, this.latitude2, this.longitude2);
52 : }
53 :
54 : }
|