Re: Extracting polygons from a given set of lines



ivan wrote:
hi,
is there an algorithm that you could recommend, which could extract
all polygons from a given set of lines?
polygons are 2D quads. to be precise, we could define them as a part
of the surface enclosed by four different lines from each side (each
line can be longer than the coresponding side of a quad).

here's an image to clarify what i mean:
http://www.nequamstudios.com/ivan/poligoni.jpg
('lines' are drawn in thin green, and polygons in thick blue. there
are exactly 3 polygons in this picture: two smaller ones, and a big
one the size of both of them)

i've written a function that does what i need, but the algorithm
complexity is far too great, and thus isn't practical for almost any
use (O(n^4)).
so that's why i need to know if there's anything that i can search for
to help me... :-)

thanks,
ivan

Looks like a job for Sweepline:

use a Priority Queue to hold Vertices and process each vertex from
bottom to top of your environment

Initially, load the PQ with the LOWER endpoint of each line segment (Note: figure out how to handle horizontal lines). Then, start processing vertices in the PQ as follows:

When you process the LOWER endpoint of each line:

a) make the line segment ACTIVE
b) look for intersections of this line segment with all other ACTIVE
line segments (insert those intersections into the PQ)

When you process an intersection:

a) CLOSE the polygon below the intersection (if there is one)
b) OPEN a new polygon above the intersection (you don't know if this
polygon will complete, or not

When you process the UPPER endpoint of each line:

a) make the line segment INACTIVE

When the PQ is empty - discard all of the open polygons

Note that I have assumed that an intersection will never be exactly AT a line segment endpoint. If that can happen - figure out how to handle it.

For well-behaved scenes, this should be <<O(n^4).

--
Kenneth Sloan KennethRSloan@xxxxxxxxx
Computer and Information Sciences +1-205-932-2213
University of Alabama at Birmingham FAX +1-205-934-5473
Birmingham, AL 35294-1170 http://KennethRSloan.com/
.



Relevant Pages

  • booleans
    ... i've been trying to implement boolean operators (like intersection, ... subtraction) for 3D polygonal objects ... since certain polygons collide with more polygons ... ...
    (comp.graphics.algorithms)
  • Re: Crossing between PATCH and plane
    ... I have the following problem...I have a 3D object, defined by a patch structure, and I want to obtain the intersection between these object and a planar surface. ... The actual problem is a patch describing a ship hull. ... the shape of the hull, there could be more than 1 closed polygons, due ...
    (comp.soft-sys.matlab)
  • Re: Intersecting Polygons
    ... don't use polygons much so I can't help you out there. ... I should have asked about the intersection of 2 POLYGONS, ... >> places the coordinates of the intersection rectangle into the destination ... >> Doug. ...
    (microsoft.public.vb.general.discussion)
  • Re: Intersection line/plane
    ... It is possible that the quad intersects the object, ... One approach is to compute the intersection of the object ... For the polygons, ... the BV of the root of the tree, it does not intersect the object. ...
    (comp.graphics.api.opengl)
  • Re: Distance between two polylines
    ... measuring orthogonal distance from the ... lies within the line segment. ... I haven't included the third for-loop because ... The polygons need not be closed paths. ...
    (comp.soft-sys.matlab)

Loading