-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawer.py
35 lines (30 loc) · 1.5 KB
/
drawer.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
from qtcarcas import Carcass, Drawer
from PyQt4 import QtGui, QtCore
import operator
class HyperbolaDrawer(Drawer):
def __init__(self, c):
super().__init__()
self.size = None
self.curve = c
def draw(self, qp):
qp.setPen(QtCore.Qt.blue)
for x in self.curve.starting_points:
self.draw_point(x, qp)
qp.setPen(QtCore.Qt.black)
self.brez_process(self.curve.starting_points[1], self.curve.left_points, qp)
self.brez_process(self.curve.starting_points[1], self.curve.right_points, qp)
self.brez_process(self.curve.starting_points[0], self.curve.left_points, qp)
self.brez_process(self.curve.starting_points[0], self.curve.right_points, qp)
def brez_process(self, point, directs, qp, verbose=False):
x, y = point
while abs(x) <= self.size.width()/2 and abs(y) <= self.size.height()/2:
if verbose:
print("Current point: {} {}".format(x, y))
for fff in directs:
print("\tNew point: {} {}. Dist: {}".format(*fff(x, y), self.curve.get_distance_from_focuses(fff(x, y))))
deltas = [self.curve.get_distance_from_focuses(p(x, y)) for p in directs]
min_index, min_value = min(enumerate(deltas), key=operator.itemgetter(1))
x, y = directs[min_index](x, y)
self.draw_point((x, y), qp)
def draw_point(self, p, qp):
qp.drawPoint(p[0] + self.size.width()/2, self.size.height() - (p[1] + self.size.height()/2))