In [4]:
from shapeanalyzer.centers import Center
from shapeanalyzer.shapes import *
import json
import numpy as np
import matplotlib.pyplot as plt
plt.axis("equal")
fig_size = [15,15]
plt.rcParams["figure.figsize"] = fig_size
fp = open("data/water1.json")
data = json.loads(fp.read())
fp.read()
def plotcell(c):
    x,y,h = c["x"], c["y"], c["h"]
    xs = [x-h,x-h,x+h,x+h,x-h]
    ys = [y-h,y+h,y+h,y-h,y-h]
    plt.plot(xs,ys,'g-')
polys = []
for d in data:
    pts = []
    for p in d:
        pts.append(Point(p[0],p[1]))
    pts.pop()
    pts.pop()
    polys.append(Polygon(pts))

i = 6
cent = Center(polys[i])
cd = cent.Centroid()
vc,pts,cells = cent.VisualCenter()
pts = np.asarray(pts)
sdat = np.asarray(data[i])
print polys[i].coords()
print cd, polys[i].isinside(cd)
plt.plot(sdat[:,0], sdat[:,1],"-")
plt.plot(pts[:,0],pts[:,1],"g+")
for c in cells:
    plotcell(c)
plt.plot(cd.x, cd.y,"om")
plt.plot(vc.x, vc.y,"or")
plt.show()


[[4051.0, 3200.0], [4064.0, 3206.0], [4077.0, 3205.0], [4081.0, 3192.0], [4080.0, 3181.0], [4068.0, 3174.0], [4068.0, 3166.0], [4090.0, 3179.0], [4092.0, 3193.0], [4085.0, 3209.0], [4063.0, 3214.0], [4043.0, 3210.0], [4034.0, 3197.0], [4033.0, 3187.0], [4044.0, 3171.0], [4039.0, 3183.0], [4047.0, 3190.0], [4044.0, 3170.0], [4049.0, 3161.0], [4050.0, 3172.0]]
Point ( 4062.02342733, 3193.36500362 ) [[4051.0, 3200.0], [4064.0, 3206.0], [4077.0, 3205.0], [4081.0, 3192.0], [4080.0, 3181.0], [4068.0, 3174.0], [4068.0, 3166.0], [4090.0, 3179.0], [4092.0, 3193.0], [4085.0, 3209.0], [4063.0, 3214.0], [4043.0, 3210.0], [4034.0, 3197.0], [4033.0, 3187.0], [4044.0, 3171.0], [4039.0, 3183.0], [4047.0, 3190.0], [4044.0, 3170.0], [4049.0, 3161.0], [4050.0, 3172.0]]
Point ( 4077.0, 3205.0 ) Point ( 4081.0, 3192.0 ) Point ( 4062.02342733, 3193.36500362 )
Point ( 4092.0, 3193.0 ) Point ( 4085.0, 3209.0 ) Point ( 4062.02342733, 3193.36500362 )
False

In [ ]:


In [ ]:


In [ ]: