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 7409413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:04:47+00:00 2026-05-29T06:04:47+00:00

I am trying to determine whether a ring is contained by another ring using

  • 0

I am trying to determine whether a ring is contained by another ring using the Boost.Geometry library.

I wrote the following code:

#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>

using namespace boost::geometry;

int main (int argc, const char * argv[])
{
    typedef model::d2::point_xy<double> P;
    model::ring<P> ring1, ring2;

    read_wkt("polygon((0 0,0 3,3 3,3 0,0 0))", ring1);
    read_wkt("polygon((1 1,1 2,2 2,2 1,1 1))", ring2);

    bool b = within(ring1, ring2);
    std::cout << "Within: " << (b ? "YES" : "NO") << std::endl;

    return 0;
}

But it does not compile (with Boost 1.48.0), because it fails a static assertion of within:

NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE

It seems that within only supports checking whether a point is within another geometry (according to the documentation).

I was thinking about treating the rings as linestrings, then check whether they intersect, and if not – check if the first point of the ring is within the other ring; but I don’t know if it’s possible to avoid copying each ring to a linestring.

Is there any way to achieve the functionality of within for two rings (with reasonable performance)?

  • 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-29T06:04:48+00:00Added an answer on May 29, 2026 at 6:04 am

    I ended up implementing the idea I suggested in the question:

    using namespace boost::geometry;
    
    template <typename Point>
    bool within(const model::ring<Point>& ring1, const model::ring<Point>& ring2)
    {
        return within(ring1.front(), ring2) &&
               disjoint(model::linestring<Point>(ring1.begin(), ring1.end()),
                        model::linestring<Point>(ring2.begin(), ring2.end()));
    }
    

    Seems to good enough for me, but I’d still be glad to get some suggestions.

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

Sidebar

Related Questions

I have written the following code where I am trying to determine whether a
I'm trying to determine whether Object1 will collide with Object2 given the following information:
I'm trying to determine whether an object is already contained within a std::set .
I am trying to figure out from my code whether the Ring/Silent switch is
We are trying to determine whether we are using Service Broker appropriately and getting
I'm changing the img src on click using javascript. I'm trying to determine whether
I am trying to write Prolog code to determine whether the bound variable X
I am trying to determine whether a company has websites built with ASP.NET MVC
I'm trying to diff two strings to determine whether or not they solely vary
I'm trying to figure out the best way to determine whether I'm in the

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.