Wednesday, 15 August 2018

python - Finding points of intersection in polygon?


For two given polygons generated as shown below, how do I find the points that are intersected on the rectangle by the circle? [The polygon was created using the Alphashape function]


(Similar to Returning percentage of area of polygon intersecting another polygon using shapely which is answered but I have not used Shapely to generate polygon for the distribution)


Polygon Intersection


Code implemented:


import sys
from descartes import PolygonPatch
import matplotlib.pyplot as plt

import alphashape
import numpy as np
x = np.random.uniform(41.03641664650488, 59.06406419360736, 1000)
y = np.random.uniform(100.96028140425065, 118.84533708184047, 1000)
test = np.vstack((x,y)).T
alpha_shape = alphashape.alphashape(test, 0.)
fig = plt.figure(1, figsize=(12, 5))
ax = fig.add_subplot(111, aspect='equal')
ax.scatter(*zip(*test))
ax.add_patch(PolygonPatch(alpha_shape, alpha=0.2))

circle = plt.Circle((50,100), 4, color='r', fill=True)
plt.gca().add_patch(circle)
plt.autoscale()
plt.show()


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...