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 78 79 80 81 82 83 84 85
| import matplotlib.pyplot
def equdroite(x0, y0, x1, y1):
a = y1 - y0
b = x0 - x1
c = -(b * y0 + a * x0)
# print("verif00:",sign(x0,y0,a,b,c),sign(x1,y1,a,b,c))
return a, b, c
def inside(Poly, p):
for P in Poly:
a, b, c, s, x, y = P[0], P[1], P[2], P[3], pp[0], pp[1]
if s * sign(x, y, a, b, c) < 0:
# print("outside:",a,b,c,s,x,y)
return False
return True
def sign(x, y, a, b, c):
return a * x + b * y + c
# Les 4 coordonnées sources
(x, y) = ([325010, 325015, 325015, 325010], [2077560, 2077560, 2077555, 2077555])
# x = [325010, 325015, 325015, 325010, 325010]
# y = [2077560, 2077560, 2077555, 2077555, 2077560]
sg = 5
# L'emprise du projet
(A, B) = ([324989.345, 324987.133, 324987.502, 325037.452, 325035.977, 324989.345],
[2077586.246, 2077553.622, 2077537.955, 2077537.402, 2077589.933, 2077586.246])
# A = [324989.345, 324987.133, 324980, 325037.452, 325035.977, 324989.345]
# B = [2077586.246, 2077553.622, 2077800, 2077537.402, 2077589.933, 2077586.246]
# avgA,avgB=sum(A)/len(A),sum(B)/len(B)
# # print ("avg:",avgA,avgB)
# A=[x-avgA for x in A]
# B=[x-avgB for x in B]
# x=[x-avgA for x in x]
# y=[x-avgB for x in y]
nc = len(A) - 1
E = []
for p0 in range(nc):
p1 = (p0 + 1) % nc
p2 = (p0 + int(nc / 2)) % nc
a, b, c = equdroite(A[p0], B[p0], A[p1], B[p1])
s = sign(A[p2], B[p2], a, b, c)
# print("inloop:",p0,a,b,c,s)
E.append([a, b, c, s, p0, p1])
# print("E:",E)
for p in range(nc):
for C in E:
if p != C[4] and p != C[5]:
a, b, c, s, xp, yp = C[0], C[1], C[2], C[3], A[p], B[p]
v = sign(xp, yp, a, b, c)
if s * v < 0:
# print("outside:",a,b,c,s,xp,yp)
print("OUPS!", s, v)
matplotlib.pyplot.plot(A, B)
matplotlib.pyplot.scatter(x, y, color="r")
matplotlib.pyplot.axis("equal")
matplotlib.pyplot.grid()
phg = (int(min(A) / sg) * sg, int(min(B) / sg) * sg)
pbd = (int(max(A) / sg + 1) * sg, int(max(B) / sg + 1) * sg)
nrow = int((pbd[0] - phg[0]) / sg) + 1
ncol = int((pbd[1] - phg[1]) / sg) + 1
# print(phg)
# print(nrow,ncol)
prouge = []
for row in range(nrow):
for col in range(ncol):
pp = (phg[0] + sg * row, phg[1] + sg * col)
if inside(E, pp):
prouge.append(pp)
xrouge = [ppp[0] for ppp in prouge]
yrouge = [ppp[1] for ppp in prouge]
matplotlib.pyplot.scatter(xrouge, yrouge, color="g")
matplotlib.pyplot.scatter(x, y, color="r")
with open("coordout.csv", "w") as f:
print("X;Y", file=f)
for xrouge, yrouge in prouge:
print(f"{xrouge};{yrouge}", file=f)
matplotlib.pyplot.show() |
Partager