# paths optimizer

I have three paths that each define a bounding box. Lets just say I have
these three in (x,y) coordinates and all are moveto, lineto, lineto,
lineto, and closepoly:

1: (0, 0), (1.1, 0), (1.1, 1.1), (0, 1.1), (0, 0)
2: (.9, 0), (2, 0), (2, 1.1), (.9, 1.1), (.9, 0)
3: (.9, .9), (2, .9), (2, 2), (.9, 2) (.9, .9)

While my paths have more nodes and are not as cleanly vertical and
horizontal, it does cover the nature of what I am experiencing.

The first thing to note is that each box has overlap at x = 1 and y = 1
and all three boxes overlap at (1,1).

What I am looking for is an optimizer that would be smart enough to say
hey, because of the overlap, we can trim the boxes to:

1: (0,0) (1,0) (1,1) (0,1) (0,0)
2: (1,0) (2,0) (2,1), (1,1), (1,0)
3: (1,1) (2,1) (2,2), (1,2), (1,1)

I am not sure that optimizer is the right word to use either. I have
poked around matplotlib a bit (over many years) and tried searching but
guessing the search terms is not simple either. Hence, I am asking if
anyone is aware of matplotlib functionality that will help me do this
task. Any other tool outside of matplotlib would be just as nice of a
suggestion. One last bit, it has to work for N paths.

···

--
Al Niessner

I have never found the companion that was so companionable as solitude.
- From Walden by Henry David Thoreau

The universe is indifferent, and life is brutal; however, it is man's
choice of behavior that makes them malevolent rather than benevolent.

Some will fall in love with life and drink it from a fountain
That is pouring like an avalanche coming down the mountain.
- From the song Pepper by the Butthole Surfers

Hello Al,

The search terms you are looking for are 'polygon clipping' and 'boolean
operations on polygons'.

Matplotlib can clip one polygon with respect to another, there is a simple
example at
http://stackoverflow.com/questions/22612323/clipping-a-triagle-with-a-circle-in-matplotlib

Alternatively, for more flexibility use shapely. For example:

from shapely.geometry import Polygon
a = Polygon([(0, 0), (1.1, 0), (1.1, 1.1), (0, 1.1)])
b = Polygon([(.9, 0), (2, 0), (2, 1.1), (.9, 1.1)])
c = Polygon([(.9, .9), (2, .9), (2, 2), (.9, 2)])
d = a.intersection(b).intersection(c)
print(d)

which outputs

POLYGON ((0.9 0.9, 0.9 1.1, 1.1 1.1, 1.1 0.9, 0.9 0.9))

i.e. a rectangle from x = 0.9 to 1.1 and y from 0.9 to 1.1.

Ian Thomas

···

On 12 November 2015 at 03:47, Al Niessner <Al.Niessner at gmx.net> wrote:

I have three paths that each define a bounding box. Lets just say I have
these three in (x,y) coordinates and all are moveto, lineto, lineto,
lineto, and closepoly:

1: (0, 0), (1.1, 0), (1.1, 1.1), (0, 1.1), (0, 0)
2: (.9, 0), (2, 0), (2, 1.1), (.9, 1.1), (.9, 0)
3: (.9, .9), (2, .9), (2, 2), (.9, 2) (.9, .9)

While my paths have more nodes and are not as cleanly vertical and
horizontal, it does cover the nature of what I am experiencing.

The first thing to note is that each box has overlap at x = 1 and y = 1
and all three boxes overlap at (1,1).

What I am looking for is an optimizer that would be smart enough to say
hey, because of the overlap, we can trim the boxes to:

1: (0,0) (1,0) (1,1) (0,1) (0,0)
2: (1,0) (2,0) (2,1), (1,1), (1,0)
3: (1,1) (2,1) (2,2), (1,2), (1,1)

I am not sure that optimizer is the right word to use either. I have
poked around matplotlib a bit (over many years) and tried searching but
guessing the search terms is not simple either. Hence, I am asking if
anyone is aware of matplotlib functionality that will help me do this
task. Any other tool outside of matplotlib would be just as nice of a
suggestion. One last bit, it has to work for N paths.

--
Al Niessner

I have never found the companion that was so companionable as solitude.
- From Walden by Henry David Thoreau

The universe is indifferent, and life is brutal; however, it is man's
choice of behavior that makes them malevolent rather than benevolent.

Some will fall in love with life and drink it from a fountain
That is pouring like an avalanche coming down the mountain.
- From the song Pepper by the Butthole Surfers

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151112/ba53c11d/attachment.html>

If I understand them both correctly (will need more time to fully
appreciate what the documentation is telling me) it seems I will need to
use both. I can use shapely to find the intersections in order to form
my new path and then use matplotlib patches to clip the original
polygons. Maybe shapely can clip too but I did not find it in the first
30 seconds that I was looking at the documentation.

Thanks for the help.

···

On Thu, 2015-11-12 at 08:21 +0000, Ian Thomas wrote:

Hello Al,

The search terms you are looking for are 'polygon clipping' and
'boolean operations on polygons'.

Matplotlib can clip one polygon with respect to another, there is a
simple example at
http://stackoverflow.com/questions/22612323/clipping-a-triagle-with-a-circle-in-matplotlib

Alternatively, for more flexibility use shapely. For example:

from shapely.geometry import Polygon
a = Polygon([(0, 0), (1.1, 0), (1.1, 1.1), (0, 1.1)])
b = Polygon([(.9, 0), (2, 0), (2, 1.1), (.9, 1.1)])
c = Polygon([(.9, .9), (2, .9), (2, 2), (.9, 2)])

d = a.intersection(b).intersection(c)

print(d)

which outputs

POLYGON ((0.9 0.9, 0.9 1.1, 1.1 1.1, 1.1 0.9, 0.9 0.9))

i.e. a rectangle from x = 0.9 to 1.1 and y from 0.9 to 1.1.

Ian Thomas

On 12 November 2015 at 03:47, Al Niessner <Al.Niessner at gmx.net> wrote:

I have three paths that each define a bounding box. Lets just
say I have
these three in (x,y) coordinates and all are moveto, lineto,
lineto,
lineto, and closepoly:

1: (0, 0), (1.1, 0), (1.1, 1.1), (0, 1.1), (0, 0)
2: (.9, 0), (2, 0), (2, 1.1), (.9, 1.1), (.9, 0)
3: (.9, .9), (2, .9), (2, 2), (.9, 2) (.9, .9)

While my paths have more nodes and are not as cleanly vertical
and
horizontal, it does cover the nature of what I am
experiencing.

The first thing to note is that each box has overlap at x = 1
and y = 1
and all three boxes overlap at (1,1).

What I am looking for is an optimizer that would be smart
enough to say
hey, because of the overlap, we can trim the boxes to:

1: (0,0) (1,0) (1,1) (0,1) (0,0)
2: (1,0) (2,0) (2,1), (1,1), (1,0)
3: (1,1) (2,1) (2,2), (1,2), (1,1)

I am not sure that optimizer is the right word to use either.
I have
poked around matplotlib a bit (over many years) and tried
searching but
guessing the search terms is not simple either. Hence, I am
anyone is aware of matplotlib functionality that will help me
do this
task. Any other tool outside of matplotlib would be just as
nice of a
suggestion. One last bit, it has to work for N paths.

--
Al Niessner

I have never found the companion that was so companionable as
solitude.
- From Walden by Henry David Thoreau

The universe is indifferent, and life is brutal; however, it
is man's
choice of behavior that makes them malevolent rather than
benevolent.

Some will fall in love with life and drink it from a fountain
That is pouring like an avalanche coming down the mountain.
- From the song Pepper by the Butthole Surfers

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

--
Al Niessner

I have never found the companion that was so companionable as solitude.
- From Walden by Henry David Thoreau

The universe is indifferent, and life is brutal; however, it is man's
choice of behavior that makes them malevolent rather than benevolent.

Some will fall in love with life and drink it from a fountain
That is pouring like an avalanche coming down the mountain.
- From the song Pepper by the Butthole Surfers