FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
geometry/example/c10_custom_cs_example.cpp at develop · boostorg/geometry · GitHub
boostorg
geometry
Repository navigation
Code
Issues
145
(145)
Pull requests
14
(14)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
geometry
/
example
/
c10_custom_cs_example.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
87 lines (67 loc) · 3.1 KB
Breadcrumbs
geometry
/
example
/
c10_custom_cs_example.cpp
Copy path
File metadata and controls
87 lines (67 loc) · 3.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
Boost.Geometry (aka GGL, Generic Geometry Library)
//
Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
//
Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
//
Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
//
Use, modification and distribution is subject to the Boost Software License,
//
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
//
http://www.boost.org/LICENSE_1_0.txt)
//
//
Example: Custom coordinate system example
#
include
<
iostream
>
#
include
<
boost/geometry/geometry.hpp
>
//
1: declare a coordinate system. For example for Mars
//
Like for the Earth, we let the use choose between degrees or radians
//
(Unfortunately, in real life Mars has two coordinate systems:
//
http://planetarynames.wr.usgs.gov/Page/MARS/system)
template
<
typename
DegreeOrRadian>
struct
martian
{
using
units = DegreeOrRadian;
};
//
2: give it also a family
struct
martian_tag
;
//
3: register to which coordinate system family it belongs to
//
this must be done in namespace boost::geometry::traits
namespace
boost
{
namespace
geometry
{
namespace
traits
{
template
<
typename
DegreeOrRadian>
struct
cs_tag
<martian<DegreeOrRadian> >
{
using
type = martian_tag;
};
}}}
//
namespaces
//
5: not worked out. To implement a specific distance strategy for Mars,
//
e.g. with the Mars radius given by default,
//
you will have to implement (/register) several other metafunctions:
//
tag, return_type, similar_type, comparable_type,
//
and structs:
//
get_similar, get_comparable, result_from_distance
//
See e.g. .../boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp
int
main
()
{
using
mars_point = boost::geometry::model::point
<
double
,
2
, martian<boost::geometry::degree>
>;
//
Declare two points
//
(Source: http://nssdc.gsfc.nasa.gov/planetary/mars_mileage_guide.html)
//
(Other sources: Wiki and Google give slightly different coordinates, resulting
//
in other distance, 20 km off)
mars_point
const
viking1
(-
48.23
,
22.54
);
//
Viking 1 landing site in Chryse Planitia
mars_point
const
pathfinder
(-
33.55
,
19.33
);
//
Pathfinder landing site in Ares Vallis
//
To calculate distance, declare and construct a strategy with Mars mean radius, in KM
//
(Source: http://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html)
boost::geometry::strategies::distance::spherical<>
const
spherical
(
3389.5
);
double
d =
boost::geometry::distance
(viking1, pathfinder, spherical);
std::cout <<
"
Distance between Viking1 and Pathfinder landing sites:
"
<< d <<
"
km
"
<< std::endl;
//
We would get 832.616 here, same order as the 835 (rounded on 5 km) listed
//
on the mentioned site
//
The distance can be calculated more accurately by an Ellipsoidal approach,
//
giving 834.444 km
boost::geometry::srs::spheroid<
double
>
spheroid
(
3396.2
,
3376.2
);
boost::geometry::strategy::distance::geographic<>
const
ellipsoidal
(spheroid);
d =
boost::geometry::distance
(viking1, pathfinder, ellipsoidal);
std::cout <<
"
Ellipsoidal distance:
"
<< d <<
"
km
"
<< std::endl;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL