In [1]:
from droplet_planning import svg_polygons_to_df
from path_helpers import path
from dmf_device_ui.tesselate import tesselate_shapes_frame
from dmf_device_ui.plot import plot_shapes
from dmf_device_ui.point_query import get_shapes_pymunk_space
%matplotlib inline
In [2]:
device_svg = 'static/device.svg'
# Read SVG polygons into dataframe, one row per polygon vertex.
df_electrodes = svg_polygons_to_df(device_svg)
# Tesselate electrode polygons into convex shapes (triangles), for
# compatability with `pymunk`.
df_electrode_tesselations = tesselate_shapes_frame(df_electrodes, ['path_id'])
# Create `pymunk` space and add a body for each convex shape. Each
# body is mapped to the original `path_id` through `electrode_bodies`.
electrodes_space, electrode_bodies = \
get_shapes_pymunk_space(df_electrode_tesselations,
['path_id', 'triangle_i'])
In [3]:
axis = plot_shapes(df_electrode_tesselations, ['path_id', 'triangle_i'],
fc='none')
plot_shapes(df_electrodes, ['path_id'], alpha=.3, axis=axis)
Out[3]:
In [4]:
shape = electrodes_space.point_query_first((275, 100))
if shape:
print electrode_bodies[shape.body]