简体   繁体   中英

Algorithm to recognize enclosed areas

When I draw freehand lines, curves, circles or any other strokes on a touch screen, I need an algorithm to tell if any enclosed area is formed in a stroke. For example if a lowercase 'e' is drawn, there's an enclosed area in it, but letters like 'm', 'w' don't have any enclosed areas in them.

  1. For already existing lines you can pick a pixel on the screen and then expand it in all directions stopping at a line until the whole area is covered.
  2. If you do not consider the screen's borders as an area boundary: You can tell if it's an enclosed area by just checking if it hits the screen's borders.
  3. If you do consider the screen's borders as an area boundary: Then it is an enclosed area.
  4. Subtract the area you just checked. And pick a new pixel. Repeat until no pixels are left.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM