Euclidean graph with 2D coordinates.
Graph where nodes have 2D positions and arc weights are Euclidean distances automatically computed from node positions. A copy of the graph keeps the positions of its nodes.
- Example: City network with geographic positions
using EG = Euclidian_Graph<Euclidian_Node<std::string>, Euclidian_Arc<Empty_Class>>;
EG city_map;
auto nyc = city_map.insert_node("NYC", Point(40.7128, -74.0060));
auto boston = city_map.insert_node("Boston", Point(42.3601, -71.0589));
auto dc = city_map.insert_node("DC", Point(38.9072, -77.0369));
auto arc = city_map.insert_arc(nyc, boston);
mpq_class Geom_Number
Numeric type used by the geometry module.
- Example: Nearest neighbor search
const Point query(41.0, -73.0);
EG::Node * nearest = nullptr;
for (EG::Node_Iterator it(city_map); it.has_curr(); it.next_ne())
{
auto node = it.get_curr();
const Geom_Number d2 = query.distance_squared_to(node->get_position());
if (nearest == nullptr or d2 < min_dist2)
{
min_dist2 = d2;
nearest = node;
}
}
- See also
- point_utils.H Point utilities
- Author
- Leandro Rabindranath León
Definition in file tpl_euclidian_graph.H.