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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:14:13+00:00 2026-05-29T07:14:13+00:00

Say I have a vector polygon with holes. I need to flood fill it

  • 0

Say I have a vector polygon with holes. I need to flood fill it by drawing connected segments. Of course, since there are holes, I can’t fill it using a single continous polyline: I’ll need to interrupt my path sometimes, then move to an area which was skipped and start another polyline there.

My goal is to find a set of polylines needed to fill the whole polygon. Better if I can find the smallest set (that is, the way I can fill the polygon with the minimum number of interruptions).

Bonus question: how could I do that for partial density fills? Say, I don’t want to fill at 100% density but I want a 50% (this will require that fill lines, supposing they’re parallel each other and have a single-unit width, are put at a distance of two units).

I couldn’t find a similar question here, although there are many related to flood-fill algorithms.

Any ideas or pointers?

Update: this picture from Wikipedia shows a good hypotetical flood path. I believe I could do that using a bitmap. However I’ve got a vector polygon. Should I rasterize it?

Path example

  • 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-29T07:14:15+00:00Added an answer on May 29, 2026 at 7:14 am

    I’m assuming here that the distance between lines is 1 unit.
    A crude implementation, with no guarantee to find the minimum number of polyline, is:

    1. Start with an empty set of polylines.
    2. Determine minx and maxx of the polygon.
    3. Loop x from xmin to xmax, with a step of 1. Line L is the vertical line at x.
      • Intersect vertical line L with your polygon (quick algorithm, easy to find). That will give you a set of segments: {(x,y1)-(x,y2)}.
      • For all polylines, and all segments, merge segment + end of polylines (see note 1 below). When you merge a segment and a polyline, append a small stretch at the end of the polyline (to joint it to the segment), and the segment itself. For all segments that you can’t merge using that, add a new polyline in the global set.
    4. At the end, try to merge again polylines if possible (ends close together).

    Optimal algorithm for merging new segments to existing polylines should be easy to find (hashing on y), or a brute force algorithm may suffice:

    1. number of new segments per line scan should not be too high if your polygons do not have zillions of holes,
    2. number of global polylines at every step should not be too large,
    3. you compare only with the end segment of each polylines, not the whole of it.

    Added note (1): To cover the case where your polygon has nearly-vertical edges, the merge process should not look only at y-delta, but allow a merge if any two y range overlaps (that means end of polyline y-range overlap segment y-range).

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

Sidebar

Related Questions

Say, I have a std::vector<SomeClass *> v; in my code and I need to
Say I have a vector in R: x <- c(1,2,3) is there a concise
Say I have a vector: (def data [Hello World Test This]) And I want
Say I have a vector which has thousands of elements. What is the R
Say I have a vector (x,y) and it is aligned to the origin by
Lets say if I have a vector V, which has 10 elements. If I
Say you have a simple class with some storage data structure (list, vector, queue,
Let's say i have 2 classes: class Class1 { public: std::vector<CustomClass3*> mVec; public: Class1();
I have a 3-vector, let's say v = vec3(-4, 2, 3) I would like
I have a randomly generated vector, say A of length M . Say: A

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.