Skip to content

Doubling of coordinates in polygon clipping #5670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stefanv opened this issue Dec 14, 2015 · 2 comments
Closed

Doubling of coordinates in polygon clipping #5670

stefanv opened this issue Dec 14, 2015 · 2 comments
Assignees
Milestone

Comments

@stefanv
Copy link
Contributor

stefanv commented Dec 14, 2015

The following code snippet takes coordinates for a hand, and clips it to a rectangular window. Of the returned polygon, the endpoints are duplicated.

from matplotlib import path, transforms
import matplotlib.pyplot as plt
import numpy as np

hand = np.array(
    [[ 1.64516129,  1.16145833 ],
     [ 1.64516129,  1.59375    ],
     [ 1.35080645,  1.921875   ],
     [ 1.375     ,  2.18229167 ],
     [ 1.68548387,  1.9375     ],
     [ 1.60887097,  2.55208333 ],
     [ 1.68548387,  2.69791667 ],
     [ 1.76209677,  2.56770833 ],
     [ 1.83064516,  1.97395833 ],
     [ 1.89516129,  2.75       ],
     [ 1.9516129 ,  2.84895833 ],
     [ 2.01209677,  2.76041667 ],
     [ 1.99193548,  1.99479167 ],
     [ 2.11290323,  2.63020833 ],
     [ 2.2016129 ,  2.734375   ],
     [ 2.25403226,  2.60416667 ],
     [ 2.14919355,  1.953125   ],
     [ 2.30645161,  2.36979167 ],
     [ 2.39112903,  2.36979167 ],
     [ 2.41532258,  2.1875     ],
     [ 2.1733871 ,  1.703125   ],
     [ 2.07782258,  1.16666667 ]])

(r0, c0, r1, c1) = (1.0, 1.5, 2.1, 2.5)

poly = path.Path(np.vstack((hand[:, 1], hand[:, 0])).T, closed=True)
clip_rect = transforms.Bbox([[r0, c0], [r1, c1]])
poly_clipped = poly.clip_to_bbox(clip_rect).to_polygons()[0]

print(len(poly_clipped[:, 0]), len(poly_clipped[:, 1]))

plt.plot(hand[:, 0], hand[:, 1], 'r-')
plt.plot(poly_clipped[:, 1], poly_clipped[:, 0], 'go-')
plt.show()

print(poly_clipped[-2:, :])
@mdboom mdboom self-assigned this Dec 14, 2015
@mdboom mdboom closed this as completed in 36ce4a7 Dec 15, 2015
tacaswell added a commit that referenced this issue Dec 15, 2015
Fix #5670. No double endpoints in Path.to_polygon
tacaswell added a commit that referenced this issue Dec 15, 2015
Fix #5670. No double endpoints in Path.to_polygon
@QuLogic QuLogic added this to the Critical bugfix release (1.5.1) milestone Dec 15, 2015
@stefanv
Copy link
Contributor Author

stefanv commented Dec 15, 2015

Wow, that was quick! Thank you!

@tacaswell
Copy link
Member

@mdboom has been down some really gnarly rabbit holes recently, I bet an strait forward bug like this one was fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants