Skip to content

Commit ee99cbf

Browse files
committed
m
1 parent 548c98f commit ee99cbf

File tree

5 files changed

+148
-3
lines changed

5 files changed

+148
-3
lines changed

.github/ISSUE_TEMPLATE.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Here you can report bugs, or request a new feature. Please use [Stack Overflow](https://stackoverflow.com) for "how-to" questions.
2+
3+
When reporting a bug, please include a *minimal, self-contained, reproducible example* that illustrates the problem and test it with the development version of "terra", or at least with the current version on CRAN. "self-contained" means that, whenever possible, your example does not rely on a particular file or yours. Instead use example data created with code, or data that ships with R (see the terra help files for examples).
4+
5+
Please also report your operating system and the output of `packageVersion("terra")` and of `terra::gdal(lib="all")`.
6+
7+
Except when discussing plots, do not include screen-shots. Instead, copy and paste the R code and responses from the R console.

.github/workflows/recheck.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on:
2+
workflow_dispatch:
3+
inputs:
4+
which:
5+
type: choice
6+
description: Which dependents to check
7+
options:
8+
- strong
9+
- most
10+
11+
name: Reverse dependency check
12+
13+
jobs:
14+
revdep_check:
15+
name: Reverse check ${{ inputs.which }} dependents
16+
uses: r-devel/recheck/.github/workflows/recheck.yml@v1
17+
with:
18+
which: ${{ inputs.which }}

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: geosphere
22
Type: Package
33
Title: Spherical Trigonometry
4-
Version: 1.5-19
5-
Date: 2023-08-26
4+
Version: 1.5-20
5+
Date: 2024-10-02
66
LinkingTo: Rcpp
77
Imports: Rcpp, sp
88
Depends: R (>= 3.0.0)

src/Geodesic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <cmath>
3131
#include <limits> // std::numeric_limits
3232
#include <memory> // std::swap
33-
#include <__math/traits.h> // std::__math::isnan
33+
//#include <__math/traits.h> // std::__math::isnan
3434
#include "Geodesic.h"
3535
#include "GeodesicLine.h"
3636

src/intersect.cpp

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
3+
// https://sourceforge.net/p/geographiclib/discussion/1026621/thread/21aaff9f/?page=1#51e7
4+
5+
// Find intersection of two geodesics
6+
7+
#include <iostream>
8+
#include <iomanip>
9+
#include <GeographicLib/Gnomonic.hpp>
10+
#include <GeographicLib/Geodesic.hpp>
11+
12+
class vector3 {
13+
public:
14+
double _x, _y, _z;
15+
vector3(double x, double y, double z = 1) throw()
16+
: _x(x)
17+
, _y(y)
18+
, _z(z) {}
19+
vector3 cross(const vector3& b) const throw() {
20+
return vector3(_y * b._z - _z * b._y,
21+
_z * b._x - _x * b._z,
22+
_x * b._y - _y * b._x);
23+
}
24+
void norm() throw() {
25+
_x /= _z;
26+
_y /= _z;
27+
_z = 1;
28+
}
29+
};
30+
31+
int intersect(double lata1, double lona1, double lata2, double lona2, double latb1, double lonb1, double latb2, double lonb2) {
32+
const GeographicLib::Geodesic& geod = GeographicLib::Geodesic::WGS84();
33+
const GeographicLib::Gnomonic gn(geod);
34+
double
35+
lat0 = (lata1 + lata2 + latb1 + latb2)/4,
36+
// Possibly need to deal with longitudes wrapping around
37+
lon0 = (lona1 + lona2 + lonb1 + lonb2)/4;
38+
std::cout << std::setprecision(16);
39+
std::cout << "Initial guess " << lat0 << " " << lon0 << "\n";
40+
for (int i = 0; i < 10; ++i) {
41+
double xa1, ya1, xa2, ya2;
42+
double xb1, yb1, xb2, yb2;
43+
gn.Forward(lat0, lon0, lata1, lona1, xa1, ya1);
44+
gn.Forward(lat0, lon0, lata2, lona2, xa2, ya2);
45+
gn.Forward(lat0, lon0, latb1, lonb1, xb1, yb1);
46+
gn.Forward(lat0, lon0, latb2, lonb2, xb2, yb2);
47+
// See Hartley and Zisserman, Multiple View Geometry, Sec. 2.2.1
48+
vector3 va1(xa1, ya1); vector3 va2(xa2, ya2);
49+
vector3 vb1(xb1, yb1); vector3 vb2(xb2, yb2);
50+
// la is homogeneous representation of line A1,A2
51+
// lb is homogeneous representation of line B1,B2
52+
vector3 la = va1.cross(va2);
53+
vector3 lb = vb1.cross(vb2);
54+
// p0 is homogeneous representation of intersection of la and lb
55+
vector3 p0 = la.cross(lb);
56+
p0.norm();
57+
double lat1, lon1;
58+
gn.Reverse(lat0, lon0, p0._x, p0._y, lat1, lon1);
59+
std::cout << "Increment " << lat1-lat0 << " " << lon1-lon0 << "\n";
60+
lat0 = lat1;
61+
lon0 = lon1;
62+
}
63+
std::cout << "Final result " << lat0 << " " << lon0 << "\n";
64+
double azi1, azi2;
65+
geod.Inverse(lata1, lona1, lat0, lon0, azi1, azi2);
66+
std::cout << "Azimuths on line A " << azi2 << " ";
67+
geod.Inverse(lat0, lon0, lata2, lona2, azi1, azi2);
68+
std::cout << azi1 << "\n";
69+
geod.Inverse(latb1, lonb1, lat0, lon0, azi1, azi2);
70+
std::cout << "Azimuths on line B " << azi2 << " ";
71+
geod.Inverse(lat0, lon0, latb2, lonb2, azi1, azi2);
72+
std::cout << azi1 << "\n";
73+
}
74+
75+
76+
77+
// Find interception of a geodesic from a point
78+
79+
int intercept(double lata1, lona1, lata2, lona2, double latb1, lonb1) {
80+
const GeographicLib::Geodesic& geod = GeographicLib::Geodesic::WGS84();
81+
const GeographicLib::Gnomonic gn(geod);
82+
double
83+
lat0 = (lata1 + lata2)/2,
84+
// Possibly need to deal with longitudes wrapping around
85+
lon0 = (lona1 + lona2)/2;
86+
std::cout << std::setprecision(16);
87+
std::cout << "Initial guess " << lat0 << " " << lon0 << "\n";
88+
for (int i = 0; i < 10; ++i) {
89+
double xa1, ya1, xa2, ya2;
90+
double xb1, yb1;
91+
gn.Forward(lat0, lon0, lata1, lona1, xa1, ya1);
92+
gn.Forward(lat0, lon0, lata2, lona2, xa2, ya2);
93+
gn.Forward(lat0, lon0, latb1, lonb1, xb1, yb1);
94+
// See Hartley and Zisserman, Multiple View Geometry, Sec. 2.2.1
95+
vector3 va1(xa1, ya1); vector3 va2(xa2, ya2);
96+
// la is homogeneous representation of line A1,A2
97+
vector3 la = va1.cross(va2);
98+
vector3 vb1(xb1, yb1);
99+
// lb is homogeneous representation of line thru B1 perpendicular to la
100+
vector3 lb(la._y, -la._x, la._x * yb1 - la._y * xb1);
101+
// p0 is homogeneous representation of intersection of la and lb
102+
vector3 p0 = la.cross(lb);
103+
p0.norm();
104+
double lat1, lon1;
105+
gn.Reverse(lat0, lon0, p0._x, p0._y, lat1, lon1);
106+
std::cout << "Increment " << lat1-lat0 << " " << lon1-lon0 << "\n";
107+
lat0 = lat1;
108+
lon0 = lon1;
109+
}
110+
std::cout << "Final result " << lat0 << " " << lon0 << "\n";
111+
double azi1, azi2;
112+
geod.Inverse(lat0, lon0, lata1, lona1, azi1, azi2);
113+
std::cout << "Azimuth to A1 " << azi1 << "\n";
114+
geod.Inverse(lat0, lon0, lata2, lona2, azi1, azi2);
115+
std::cout << "Azimuth to A2 " << azi1 << "\n";
116+
geod.Inverse(lat0, lon0, latb1, lonb1, azi1, azi2);
117+
std::cout << "Azimuth to B1 " << azi1 << "\n";
118+
}
119+
120+
*/

0 commit comments

Comments
 (0)