Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6969439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:34:53+00:00 2026-05-27T16:34:53+00:00

We have some set of points (each point has its X and Y) and

  • 0

We have some set of points (each point has its X and Y) and a multy map of roots [point, point]. We can move via roots from any point to any in any possible direction. We are given some path of 2d points we want to follow as close to as possible:

map

how to calculate a path like this:

enter image description here

that would look as alike as possible to given path? What are usefull algorithms that can do such thing (and are thay implemented in Boost Geometry or Graph or any other common opensource C++ library)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:34:53+00:00Added an answer on May 27, 2026 at 4:34 pm

    This is a really cute little problem. If your graph is well connected a greedy approach might work quite well. As in: (1) set current position to be the node closest to the start of the path, (2) move to the adjacent node which is closest to the next point in the path until there is no closer point, (3) select next point in path and goto (2) if not finished.

    #include <assert.h>
    #include <stddef.h>
    #include <iostream>
    #include <iterator>
    #include <vector>
    #include <limits>
    
    double sq(double const d)
    {
        return d * d;
    }
    
    size_t min_dist_point(
        std::vector<double> const& x,
        std::vector<double> const& y,
        std::vector<bool> const& adjacent,
        double const fx,
        double const fy
    )
    {
        size_t const points = x.size();
    
        double min_dist_sq = std::numeric_limits<double>::max();
        size_t min_point;
    
        for (size_t j = 0; j < points; ++j) {
            if (!adjacent[j]) { continue; }
            double const dist_sq = sq(x[j] - fx) + sq(y[j] - fy);
    
            if (dist_sq < min_dist_sq) {
                min_point = j;
                min_dist_sq = dist_sq;
            }
        }
        assert(min_dist_sq != std::numeric_limits<double>::max());
    
        return min_point;
    }
    
    template <class out_t>
    out_t f(
        std::vector<double> const& x,
        std::vector<double> const& y,
        std::vector<std::vector<bool> > adjacent,
        std::vector<double> const& follow_x,
        std::vector<double> const& follow_y,
        out_t out
    )
    {
        size_t const points = x.size();
        size_t const follow_len = follow_x.size();
        for (size_t i = 0; i < points; ++i) {
            adjacent[i][i] = 1;
        }
    
        std::vector<bool> const all (points, true);
        size_t pos = min_dist_point(x, y, all, follow_x[0], follow_y[0]);
        *out++ = pos;
    
        for (size_t i = 1; i < follow_len; ++i) {
            for (;;) {
                size_t const next = min_dist_point(x, y, adjacent[pos], follow_x[i], follow_y[i]);
                if (next == pos) { break; }
                *out++ = (pos = next);
            }
        }
    
        return out;
    }
    

    If this algorithm gets stuck in cycles you will need A* search.

    http://www.boost.org/doc/libs/1_47_0/libs/graph/doc/astar_search.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some set of xml generated via xmlserialization of some WCF messages. Now
I have a usercontrol wit some textboxes on it. Each text box has a
I have some scenes set up and already embedded them in the navigation stack
I have some content set to be in 3 columns, but as it wraps
Do you have some predefined set of targets which all build.xml files you create
I'm working on a Rails application where I have some a set of two
In my init I have set some variables and one animate that uses those
I have one AlertDialog which is working fine.I have set some background images to
I have some markup for a set of fields within a form: <ul> <li>
I have some jquery/php interaction set up on a page. It submits some data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.