Commit 068cc40f authored by ronan's avatar ronan
Browse files

BreakPoint corrigé

parent 894c842e
......@@ -11,3 +11,7 @@ class BeachLine:
self.root = Node(p0)
else:
self.root.insert(p0)
def remove(self, p0):
assert(self.root is not None)
self.root.remove(p0)
......@@ -6,3 +6,11 @@ class Edge:
self.vec = vec
self.p0 = p0
self.p1 = p1
def addPoint(self, p):
if self.p0 is None:
self.p0 = p
else:
assert(self.p1 is not None)
self.p1 = p
from Site import Site
from VSite import VSite
from BeachLine import BeachLine
from Geom import *
from Vector3D import Vector3D
import math
......@@ -10,6 +11,7 @@ class Fortune:
self.sites = []
self.events = []
self.beachLine = BeachLine()
self.vertex = []
# Sort Y
for i in range(len(self.points)):
......@@ -32,94 +34,78 @@ class Fortune:
else:
self.handleSite()
def findMinCircle(self, p1, p2, p3):
x1 = p1.point.getX(); x1_2 = x1*x1; x2 = p2.point.getX(); x2_2 = x2*x2; x3 = p3.point.getX(); x3_2 = x3*x3;
y1 = p1.point.getY(); y1_2 = y1*y1; y2 = p2.point.getY(); y2_2 = y2*y2; y3 = p3.point.getY(); y3_2 = y3*y3;
# First part
h = x2_2 + y2_2 - (y1_2 + x1_2)
b = 2*(x2 - x1)
a = (y1 - y2)
# Second Part
f = x3_2 + y3_2 - (y1_2 + x1_2)
d = 2*(y3 - y1)
e = (x1 - x3)
# Determine Center
x = ((2*a*f/d) + h)/(b*(1-(4*a*e/(d*b))))
y = (2*x*e + f)/d
center = Vector3D(x, y)
magn = math.sqrt((x - x1)*(x - x1) + (y - y1)*(y - y1))
minY = Vector3D(x, y + magn)
vSite = VSite(minY, center)
return vSite
def computeBreakPoint(self, p1, p2, ly):
x1 = p1.point.getX(); x1_2 = x1*x1; x2 = p2.point.getX(); x2_2 = x2*x2;
y1 = p1.point.getY(); y1_2 = y1*y1; y2 = p2.point.getY(); y2_2 = y2*y2;
ly_2 = ly*ly;
# First part
h = x1_2 + y1_2 - ly_2
e = 2*(y1 - ly)
# Second Part
a = 2*(x2 - x1)
b = 2*(y2 - y1)
c = x1_2 + y1_2 - x2_2 - y2_2
d = (a - 2*((x1*b)/e))
f = (((h*b)/e) + c)
delta = (d*d - 4*b*f/e)
x = 0
y = 0
print(delta)
assert(delta >= 0), "Ca a crashé " + str(delta)
if delta < 0.00001:
x = -d/(2*b/e)
y = (x*x - 2*x1*x + h)/e
else:
xa = (-d + math.sqrt(delta))/(2*b/e)
xb = (-d - math.sqrt(delta))/(2*b/e)
# On prend entre les deux
ya = (xa*xa - 2*x1*xa + h)/e
yb = (xb*xb - 2*x1*xb + h)/e
if (ya >= y1 and ya <= y2) or (ya <= y1 and ya >= y2):
x = xa
y = ya
else:
x = xb
y = yb
breakPoint = Vector3D(x, y)
return breakPoint
def insertBeachLine(self, p0):
pass
def handleSite(self):
site = self.events.pop(len(self.events)-1) #SweapLine
[p1, p, p3] = self.beachLine.insert(site)
if p1 is not None and p is not None and p3 is not None:
if p is not None:
if p1 is not None and p3 is not None:
self.removeEvent(p1, p, p3)
createEdge(p, site)
if p1 is not None:
min = self.findMinCircle(p1, p, site)
min = findMinCircle(p1, p, site)
if min.point.y > site.point.y:
self.addEvent(min)
if p3 is not None:
min = self.findMinCircle(p1, p, site)
min = findMinCircle(p1, p, site)
if min.point.y > site.point.y:
self.addEvent(min)
def handleVertex(self):
vSite = self.events.pop(len(self.events)-1)
[p1, pi, pk, p2] = self.beachLine.remove(vSite)
if pi is not None and pk is not None:
edge1 = None
edge2 = None
i = 0
while edge1 is None:
if vSite.edges[i] in pi.edges:
edge1 = vSite.edges[i]
i += 1
i = 0
while edge2 is None:
if vSite.edges[i] in pk.edges:
edge2 = vSite.edges[i]
i += 1
edge1.addPoint(vSite.center)
edge2.addPoint(vSite.center)
self.vertex.append(vSite.center)
if p1 is not None:
self.removeEvent(p1, pi, vSite)
min = findMinCircle(p1, pi, pk)
if min.point.y > vSite.point.y:
self.addEvent(min)
if p2 is not None:
self.removeEvent(vSite, pk, p2)
min = findMinCircle(pi, pk, p2)
if min.point.y > vSite.point.y:
self.addEvent(min)
else:
print("normal?")
#removeEvent
def addEvent(self, site):
pass
\ No newline at end of file
i = 0
while i < len(self.events):
if site.point.getY() < self.events[i].point.getY():
break
i += 1
self.events.append(site, i)
def removeEvent(self, p1, p, p3):
for i in range(len(p.sites)):
if p.sites[i] in p1.sites:
if p.sites[i] in p3.sites:
self.events.remove(p.sites[i])
p1.remove(p.sites[i])
p3.remove(p.sites[i])
p.pop(i)
from Site import Site
from VSite import VSite
from Vector3D import Vector3D
import math
from Edge import Edge
def findMinCircle(p1, p2, p3):
x1 = p1.point.getX(); x1_2 = x1*x1; x2 = p2.point.getX(); x2_2 = x2*x2; x3 = p3.point.getX(); x3_2 = x3*x3;
y1 = p1.point.getY(); y1_2 = y1*y1; y2 = p2.point.getY(); y2_2 = y2*y2; y3 = p3.point.getY(); y3_2 = y3*y3;
# First part
h = x2_2 + y2_2 - (y1_2 + x1_2)
b = 2*(x2 - x1)
a = (y1 - y2)
# Second Part
f = x3_2 + y3_2 - (y1_2 + x1_2)
d = 2*(y3 - y1)
e = (x1 - x3)
# Determine Center
x = ((2*a*f/d) + h)/(b*(1-(4*a*e/(d*b))))
y = (2*x*e + f)/d
center = Vector3D(x, y)
magn = math.sqrt((x - x1)*(x - x1) + (y - y1)*(y - y1))
minY = Vector3D(x, y + magn)
vSite = VSite(minY, center)
return vSite
def computeBreakPoint(p1, p2, ly):
x1 = p1.point.getX(); x1_2 = x1*x1; x2 = p2.point.getX(); x2_2 = x2*x2;
y1 = p1.point.getY(); y1_2 = y1*y1; y2 = p2.point.getY(); y2_2 = y2*y2;
ly_2 = ly*ly;
# First part
h = x1_2 + y1_2 - ly_2
e = 2*(y1 - ly)
# Second Part
a = 2*(x2 - x1)
b = 2*(y2 - y1)
c = x1_2 + y1_2 - x2_2 - y2_2
d = (a - 2*((x1*b)/e))
f = (((h*b)/e) + c)
delta = (d*d - 4*b*f/e)
x = 0
y = 0
print(delta)
assert(delta >= 0), "Ca a crashé " + str(delta)
if delta < 0.00001:
x = -d/(2*b/e)
y = (x*x - 2*x1*x + h)/e
else:
xa = (-d + math.sqrt(delta))/(2*b/e)
xb = (-d - math.sqrt(delta))/(2*b/e)
# On prend entre les deux
ya = (xa*xa - 2*x1*xa + h)/e
yb = (xb*xb - 2*x1*xb + h)/e
if (ya >= y1 and ya <= y2) or (ya <= y1 and ya >= y2):
x = xa
y = ya
else:
x = xb
y = yb
breakPoint = Vector3D(x, y)
return breakPoint
def createEdge(p0, p1):
vec = p1 - p0
edge = Edge(Vector3D(-vec.getY(), vec.getX()))
p0.edges.append(edge)
p1.edges.append(edge)
......@@ -5,20 +5,41 @@ class Node:
self.right = None
self.value = 0
self.stop = False
self.root = None
def insert(self, p0):
magnL = 0
magnR = 0
if self.value < p0.point.getX():
if self.left is None:
self.left = Node(p0)
self.left.root = self
else:
self.left.insert(p0)
else:
if self.right is None:
self.right = Node(p0)
self.right.root = self
else:
self.right.insert(p0)
def remove(self, p0):
if self.site is p0:
assert(self.root is not None)
assert(self.left is None and self.right is None)
if self.root.left is self:
self.root.left = None
else:
self.root.right = None
return True
else:
if self.left is None or (not self.left.remove(p0)):
assert(self.right is not None and self.right.remov(p0))
def array(self, a):
if self.left is not None:
magnL = self.left.getMagn()
if self.right is not None:
magnR = self.right.getMagn()
if magnL < magnR:
self.left.insert
self.left.array(a)
def getY(self):
return self.site.point.getY()
a.append(self.site)
def getMagn(self, site):
v = site.point - self.site.point
return v.getMagnitude()
\ No newline at end of file
if self.right is not None:
self.right.array(a)
\ No newline at end of file
......@@ -3,5 +3,5 @@ class Site:
def __init__(self, point):
self.point = point
self.sites = {}
self.edges = {}
self.sites = []
self.edges = []
......@@ -110,6 +110,8 @@ if __name__ == "__main__":
canvas.pack()
fenetre.mainloop()
"""
def draw_Pol(screen, p, y):
fac = 10
a = p.getY()*p.getY() - y*y
......@@ -120,6 +122,7 @@ def draw_Pol(screen, p, y):
y1 = -h/b
screen.create_oval(x1 - 1, y1 - 1, x1 + 1, y1 + 1, fill='black')
if __name__ == "__main__":
fenetre = Tk()
canvas = Canvas(fenetre, width=800, height=800, background='white')
......@@ -139,13 +142,10 @@ if __name__ == "__main__":
vec[i].setY(vec[i].getY() * fac.getY())
canvas.focus_set()
fortune = Fortune(vec)
#canvas.bind("<Key>", clavier)
canvas.create_line(0, ly, 500, ly)
canvas.pack()
fenetre.mainloop()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment