Re: polygon buffering algorithms
by thor (Priest) on Feb 08, 2005 at 17:39 UTC
|
If you have a set of lines that represents a closed polygon, the following pseudo-code should work
foreach edge (edges in polygon, clockwise)
construct parallel line distance d from edge, store it in an array
done
foreach parallel line
find intersection with next line in array, allowing for wrap around
store intersection in an array
done
#intersections are the vertexes of your new polygon
If you need more, let us know.
thor
Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come
| [reply] [d/l] |
|
|
...................................
...................................
...................................
...................................
.....!!!!!!!!!!!!!!!!!!!!!!!!!.....
.....!!!!!!!!!!!!!!!!!!!!!!!!!.....
.....!!!!!!!!!!!!!!!!!!!!!!!!!.....
.....!!!!!!!!!!!!!!!!!!!!!!!!!.....
...............!!!!!!!!!!!!!!!.....
...............!!!!!!!!!!!!!!!.....
.....!!!!!!!!!!!!!!!!!!!!!!!!!.....
.....!!!!!!!!!!!!!!!!!!!!!!!!!.....
.....!!!!!!!!!!!!!!!!!!!!!!!!!.....
.....!!!!!!!!!!!!!!!!!!!!!!!!!.....
...................................
...................................
...................................
...................................
The above with $d == 3 gives a weird polygon, but that's ok as long you're expecting it.
| [reply] [d/l] [select] |
|
|
You're right...the algorithm that I outlined works for convex polygons. In order to deal with polygons with concavities, I believe that you need to allow for overlap and take the union of all points that lie in the interior. In the case of the polygon that you gave, it would then be a square. Just for my own edification, what is the $d that you're referring to?
thor
Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come
| [reply] |
|
|
Re: polygon buffering algorithms
by TedPride (Priest) on Feb 08, 2005 at 16:50 UTC
|
How do you want corners handled? With curves? Does the distance only matter between two lines? | [reply] |
|
|
How do you want corners handled? With curves? Does the distance only matter between two lines?
Frankly, I really don't know. In the case of certain corners (such as the vertex of a square or a triangle, it is intuitively quite simple. Ordinarily, every point on the outer polygon should be 'd' distance from the corresponding point in the inner polygon. Of course, a triangle's vertex creates an interesting problem. However, the vertex of the outer polygon can be 'd' distance from the vertex of the inner polygon in two different directions, with some kind of smoothing curve in between. This is geography, so accuracy is not as important as reliability. As long as we intuitively know that the resulting buffer is more or less correct, no one is going to quibble.
| [reply] |
|
|
accuracy is not as important as reliability
I understand the difference between accuracy and precision, but could you please explain what you mean by accuracy vs. reliability? (Google is not as helpful here.)
Update: added links to definition
--Solo
--
You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.
| [reply] |
|
|
|
|
|
Re: polygon buffering algorithms
by tall_man (Parson) on Feb 08, 2005 at 21:15 UTC
|
| [reply] |
Re: polygon buffering algorithms
by Anonymous Monk on Feb 09, 2005 at 10:51 UTC
|
And a buffer for a point would be nothing but a circle.
Yes, but that's not a polygon. If you take a line segment, and you take the set of points that at distance d, you get two half circles joined by two line segments - not a polygon either.
Anyway, the problem shouldn't be too hard. Just walk along the original polygon, and create the new 'polygon' piece by piece. For each line segment, it's easy to find the corresponding line segment. Consecutive line segments are joined by arcs, whose origin lies on the vertex of the original polygon. For convex polygons, this is all you need to do. For concave polygon, you might get self-intersections this way. But they are reasonably easy to fix by maintaining a stack of 'polygon' pieces (line segments and arcs), and either deleting the top piece(s), or intersecting with it.
| [reply] |
|
|
>>And a buffer for a point would be nothing but a circle.
>Yes, but that's not a polygon. If you take a line
>segment, and you take the set of points that at
>distance d, you get two half circles joined by two
>line segments - not a polygon either.
Interesting. Why is that, may I ask? As far as I can see (and I've been working in the GIS field for about 20 yrs believing it to be so), a circle is indeed a polygon as much as a buffer of line is. Btw, in your description above, the buffer is of a single straight-line segment. Of course, a line can be made of any number of line segments, or arcs. A line is nothing but a series of x,y pairs that don't end up where they started. While a polygon is the same as above except the first and the last pair are the same.
In any case, the problem actually is surprisingly hard. That is because of all the different manners in which a polygon or a line can be configured. One has to determine the inside vs. the outside worlds wrt the polygon (of course, for buffering, one would want to remain on the outside), which can differ based on the slope of that particular line segment and the direction of one's travel (clockwise vs. counter-clockwise). Then there is the thorny issue of vertices, as brought up above.
When all is said and done, it has to be fast.
Now, I know there are algorithms out there... well established, because the solution exists in commercial software. I am simply unable to find references to the darn algorithms in published literature so I can start exploring the possibility of building one as an open source solution.
| [reply] |
|
|
| [reply] |
Re: polygon buffering algorithms
by BrowserUk (Patriarch) on Feb 08, 2005 at 17:21 UTC
|
| [reply] |
|
|
How is your polygon represented? A set of vertecies? A Bezier spline?
A set of verticies
| [reply] |