Commit 58b70eb5 authored by ronan's avatar ronan
Browse files

Début gestion des cas dégénérés

parent a76a0b0a
......@@ -71,15 +71,15 @@ class Fortune:
# AJout des breakpoints
if p1 is not None:
min = findMinCircle(p1, p, site)
min.on = p
if self.isValidVertex(min) and min.point.getY() > site.point.getY():
if self.isValidVertex(min) and min.point.getY() >= site.point.getY():
min.on = p
vertexVerif(min)
self.addEvent(min)
if p3 is not None:
min = findMinCircle(p3, p, site)
min.on = p
if self.isValidVertex(min) and min.point.getY() > site.point.getY():
if self.isValidVertex(min) and min.point.getY() >= site.point.getY():
min.on = p
vertexVerif(min)
self.addEvent(min)
......@@ -121,7 +121,7 @@ class Fortune:
# On supprime les evenements liés aux anciens points
self.removeEvent(p1, pi, vSite)
min = findMinCircle(p1, pi, pk)
if self.isValidVertex(min) and min.point.getY() > vSite.point.getY():
if self.isValidVertex(min) and min.point.getY() >= vSite.point.getY():
if vSite.type == 0:
on = pi
print("Possible Error")
......@@ -137,7 +137,7 @@ class Fortune:
# On supprime les evenements liés aux anciens points
self.removeEvent(vSite, pk, p2)
min = findMinCircle(pi, pk, p2)
if self.isValidVertex(min) and min.point.getY() > vSite.point.getY():
if self.isValidVertex(min) and min.point.getY() >= vSite.point.getY():
if vSite.type == 0:
on = pk
print("Possible Error")
......@@ -187,6 +187,8 @@ class Fortune:
i += 1
def isValidVertex(self, vSite):
if vSite is None:
return False
radius = (vSite.center - vSite.point).getMagnitude()
i = len(self.sites) - 1
while i > -1 and vSite.point.getY() >= self.sites[i].point.getY():
......
......@@ -10,22 +10,28 @@ def findMinCircle(p1, p2, p3):
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)
h = -(x2_2 + y2_2) + (y1_2 + x1_2)
b = 2*(x2 - x1)
a = (y1 - y2)
a = 2*(y2 - y1)
# Second Part
f = x3_2 + y3_2 - (y1_2 + x1_2)
f = -(x3_2 + y3_2) + (y1_2 + x1_2)
d = 2*(y3 - y1)
e = (x1 - x3)
e = 2*(x3 - x1)
# Determine Center
x = 0
if (1-(4*a*e/(d*b))) != 0.0:
x = ((2*a*f/d) + h)/(b*(1-(4*a*e/(d*b))))
t = (d*b - a*e)
if isNull(t):
return None
y = (2*x*e + f)/d
x = 0
y = 0
if isNull(b):
y = -h/a #a != 0 car pas deux points identiques
x = -(d*y + f)/e #e != 0 car pas 3 points alignés
else:
y = (-f*b + e*h)/t
x = -(a*y + h)/b
center = Vector3D(x, y)
magn = math.sqrt((x - x1)*(x - x1) + (y - y1)*(y - y1))
......@@ -47,31 +53,38 @@ def computeBreakPoint(p1, p2, ly):
# First part
h = x1_2 + y1_2 - ly_2
e = 2*(y1 - ly)
e = 2*(ly - y1)
# 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)
if delta < 0.0:
return []
elif delta < 0.00001:
x = -d/(2*b/e)
y = (x*x - 2*x1*x + h)/e
if isNull(b):
if isNull(e):
return []
x = -c/a
y = (-x*x + 2*x*x1 - h)/e
return [Vector3D(x, y)]
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
return [Vector3D(xa, ya), Vector3D(xb, yb)]
d = -(a*e + 2*b*x1)
f = -c*e + h*b
delta = (d*d - 4*b*f)
if delta < 0.0:
return []
elif delta < 0.00001:
x = -d/(2*b)
y = (-c -a*x)/b
return [Vector3D(x, y)]
else:
xa = (-d - math.sqrt(delta))/(2*b)
xb = (-d + math.sqrt(delta))/(2*b)
# On prend entre les deux
ya = (-c -a*xa)/b
yb = (-c -a*xb)/b
return [Vector3D(xa, ya), Vector3D(xb, yb)]
def createEdge(p0, p1, pointToAdd = None):
......@@ -206,3 +219,83 @@ def getPosCurve(p, x, y):
return Vector3D(x1, y1)
else:
return Vector3D(0, 0)
def isNull(v):
"""
a = 0.000000001
return v > -a and v < a
"""
return v == 0.0
def last():
"""
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 = 0
if (1-(4*a*e/(d*b))) != 0.0:
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)
vSite.sites.append(p1)
vSite.sites.append(p2)
vSite.sites.append(p3)
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)
if delta < 0.0:
return []
elif delta < 0.00001:
x = -d/(2*b/e)
y = (x*x - 2*x1*x + h)/e
return [Vector3D(x, y)]
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
return [Vector3D(xa, ya), Vector3D(xb, yb)]
"""
pass
\ No newline at end of file
......@@ -34,9 +34,9 @@ class Node:
def remove(self, p0, edges):
if p0.on is self.site:
piN = self.fullLast()
if piN[0].site in p0.sites:
if piN[0] is not None and piN[0].site in p0.sites:
pkN = self.fullNext()
if pkN[0].site in p0.sites:
if pkN[0] is not None and pkN[0].site in p0.sites:
p1 = piN[0].lastSite()
p2 = pkN[0].nextSite()
pi = piN[0].site
......
......@@ -40,9 +40,9 @@ def clavier(event):
a.setX(rE[i].point.getX() * fac.getX())
a.setY(rE[i].point.getY() * fac.getY())
a.draw(canvas)
#draw_Pol(canvas, a, ly[0])
draw_Pol(canvas, a, ly[0])
canvas.create_text(a.getX() - 10, a.getY() + 12, anchor=W, font="Arial 8", text=str(rE[i]))
"""
E = fortune.events
for i in range(len(E)):
if type(E[i]) == VSite:
......@@ -64,7 +64,7 @@ def clavier(event):
a.setY(E[i].point.getY() * fac.getY())
a.draw(canvas)
canvas.create_text(a.getX() - 10, a.getY() + 12, anchor=W, font="Arial 8", text=str(E[i]))
"""
edges = fortune.edges
for i in range(len(edges)):
......@@ -103,7 +103,7 @@ if __name__ == "__main__":
vec = []
vec.append(Vector3D(2, 1))
vec.append(Vector3D(4, 1.1))
vec.append(Vector3D(4, 1.001))
vec.append(Vector3D(5, 2.7))
vec.append(Vector3D(3.2, 3))
vec.append(Vector3D(4.2, 4))
......
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