-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpoly2trap.py
77 lines (65 loc) · 4.21 KB
/
poly2trap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 05 19:43:15 2015
@author: Duncan Parkes
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
import seidel
import matplotlib.pyplot as plt
from descartes import PolygonPatch
from shapely.geometry import Polygon
test = [[235.04275999999999, 739.07534999999996], [218.13066000000001, 719.73902999999996],
[218.15215000000001, 709.96821], [218.17362, 700.19740000000002], [243.15215000000001, 685.27858000000003],
[268.13065, 670.35974999999996], [268.13065, 660.81429000000003], [268.13065, 651.26882999999998],
[314.55921999999998, 651.26882999999998], [360.98779000000002, 651.26882999999998],
[360.98683999999997, 666.44740000000002], [360.98046561000007, 669.27438118000009],
[360.96234088000011,672.68539864000013], [360.93345946999995, 676.58895225999993],
[360.89481504000003, 680.89354191999996], [360.84740125000002, 685.50766749999991],
[360.79221175999999, 690.33982888000003], [360.73024022999999, 695.29852593999999],
[360.66248032000004, 700.29225856000005], [360.58992569000003, 705.22952662000012],
[360.51357000000002, 710.01882999999998], [360.04131999999998, 738.41168000000005],
[310.51454999999999, 738.41168000000005], [260.98779999999999, 738.41168000000005],
[260.98779999999999, 748.41168000000005], [260.98779999999999, 758.41168000000005],
[256.47133000000002, 758.41168000000005], [251.95484999999999, 758.41168000000005]]
dude = [[174.50415,494.59368],[215.21844,478.87939],[207.36129,458.87939],[203.07558,441.02225],[203.07558,418.1651],
[210.93272,394.59367],[224.50415,373.1651],[241.64701,358.1651],[257.36129,354.59367],[275.93272,356.73653],
[293.07558,359.59367],[309.50415,377.45082],[322.36129,398.1651],[331.64701,421.73653],[335.21844,437.45082],
[356.64701,428.52225],[356.1113,428.34367],[356.1113,428.34367],[368.78987,419.59368],[349.50415,384.59367],
[323.78987,359.59367],[290.93272,343.87939],[267.36129,341.02225],[264.50415,331.02225],[264.50415,321.02225],
[268.78987,306.02225],[285.93272,286.02225],[295.21844,270.30796],[303.78987,254.59367],[306.64701,213.87939],
[320,202.36218],[265,202.36218],[286.64701,217.45082],[293.78987,241.02225],[285,257.36218],[270.93272,271.73653],
[254.50415,266.02225],[250.93272,248.1651],[256.64701,233.1651],[256.64701,221.02225],[245.93272,215.30796],
[238.78987,216.73653],[233.78987,232.45082],[232.36129,249.59367],[243.07558,257.09367],[242.89701,270.30796],
[235.93272,279.95082],[222.36129,293.1651],[205.21844,300.6651],[185,297.36218],[170,242.36218],[175,327.36218],
[185,322.36218],[195,317.36218],[230.75415,301.02225],[235.39701,312.45082],[240.57558,323.52225],
[243.61129,330.48653],[245.21844,335.12939],[245.03987,344.4151],[229.86129,349.4151],[209.14701,362.09367],
[192.89701,377.80796],[177.18272,402.27225],[172.36129,413.87939],[169.14701,430.48653],[168.61129,458.52225],
[168.61129,492.80796]]
seidel = seidel.Triangulator(dude)
triangles = seidel.triangles()
trapezoids = seidel.trapezoids
#trapezoids = seidel.trapezoidal_map.
plt.figure()
for t in trapezoids:
#t = self.trapezoids[0]
#verts = self.trapezoids[t].vertices()
verts = t.vertices()
plt.gca().add_patch(PolygonPatch(Polygon(verts)))
plt.gca().autoscale(tight=False)
print verts
# plt.show()
# for vert in verts:
# plt.plot(vert[0], vert[1], '-')
plt.show()
#print triangles
#print trapezoids