Esempio n. 1
0
 def __init__(self, r, h, num=0, v=16):
     self.values = dict()
     self.values['r'] = r # radius of the inscribed circle
     self.values['h'] = h # height
     self.values['v'] = v # vertices number
     self.values['number'] = num # disk number, used to identify it ('name')
     self.values['topCenter'] = Point(0, 0, h/2)
     self.values['botCenter'] = Point(0, 0, -h/2)
     self.values['facets'] = []
     self.values['transformationHistory'] = []
     self.values['copied'] = 0
     alpha = 2 * math.pi / v # angle the vertex is seen from center
     for i in range(v):
         facet = Point(r * math.cos(alpha * i), r * math.sin(alpha * i), 0)
         self.values['facets'].append(facet)
Esempio n. 2
0
 def drawPositionData(self, point):
     baseDrawPoint = (point[0]+self.staticOffsetX,point[1]+self.staticOffsetY)
     myfontS = pygame.font.SysFont('monospace', self.infoFontSize)
     Print1 = '{0}'.format(Point.fromtuple(point))
     ts1 = myfontS.render(Print1, False, self.mousePositionTextColor, self.mousePositionBackColor)
     self.screen.blit(ts1,baseDrawPoint)
     return
Esempio n. 3
0
 def changeByMatrix(self, M):
     self.values['transformationHistory'].append(M)
     pt = self.values['topCenter']
     pt = np.array([pt.x(), pt.y(), pt.z(), 1])
     pt = np.dot(pt, M)
     self.values['topCenter'] = Point(pt[0], pt[1], pt[2])
     pt = self.values['botCenter']
     pt = np.array([pt.x(), pt.y(), pt.z(), 1])
     pt = np.dot(pt, M)
     self.values['botCenter'] = Point(pt[0], pt[1], pt[2])
     for i in range(len(self.values['facets'])):
         pt = np.array([self.values['facets'][i].x(),
                        self.values['facets'][i].y(),
                        self.values['facets'][i].z(), 1])
         pt = np.dot(pt, M)
         self.values['facets'][i] = Point(pt[0], pt[1], pt[2])
Esempio n. 4
0
    def __init__(self, p1, p2, p3, steps):

        if (p1[0] == p2[0] or p2[0] == p3[0] or p1[0] == p3[0]):
            raise ValueError(
                "Parabola expects all points to have differing x-values!")
        pt_array = [
            Point.fromtuple(p1),
            Point.fromtuple(p2),
            Point.fromtuple(p3)
        ]
        pt_array.sort(key=lambda point: point.x)
        self.known_points = pt_array
        self.angle = math.pi / 2
        self.degrees = math.degrees(self.angle)
        self.slope = 0
        self.change_steps(steps)
        self.quadratic = self.equation()
 def points_on_line(self, point_A, point_B, step):
     """
     Делим отрезок AB на равные отрезки длиной step.
     Возвращает список промежуточных точек(их координат), между point_A и point_B.
     Включая первую точку, последняя точка в списке отсутствует.
     Если нужна и последняя точка, раскомментируйте строку.
     """
     point_A = Point(point_A)
     point_B = Point(point_B)
     if point_B.len(Point((0,0)))<point_A.len(Point((0,0))):
         point_A, point_B = point_B, point_A
     try:
         alpha = math.atan((point_B.y-point_A.y)/(point_B.x - point_A.x))
     except ZeroDivisionError:
         alpha = math.radians(90)
     l_AB = point_A.len(point_B)
     print(alpha)
     steps = 0
     points = [point_A.as_tuple()]
     k=1
     while steps<l_AB-step:
         steps += step
         x = k*steps*math.cos(alpha)+point_A.x
         y = k*steps*math.sin(alpha)+point_A.y
         if point_B.len(Point((x,y)))>l_AB: #fixme: костыль!
             k = -1
             x = k*steps*math.cos(alpha)+point_A.x
             y = k*steps*math.sin(alpha)+point_A.y
         points.append((x,y))
     #points.append(point_B.as_tuple())
     #print("points = ", self.points)
     return points
Esempio n. 6
0
 def step(self, num):
     x = self.known_points[0].x + num * self.stepwidth
     y = x**2 * self.a + x * self.b + self.c
     return Point(x, y)
Esempio n. 7
0
        print(c)
    print(p.step(11))
    print(p.quadratic, end='\n\n')
    print(p.known_points)
    print(p.slope, p.angle, p.degrees)
    p.translate([-100, -100])
    print()
    print(p.quadratic)
    print()
    p.rotate(45)
    print()
    print(p.quadratic)
    p.rotate(-45)
    print(p.quadratic)
    try:
        p = Parabola((450, 0), (450, 700), (450, 20), 20)
    except ValueError as e:
        print('Something wrong!', e)
    Pxy = Point(2, 1)
    #print(Pxy)
    Pxy.translate([100, 100])
    Pxy.rotate(30.0)
    Pxy.rotate(-30.0)
    Pxy.rotate(90)
    Pxy.rotate(-90)
    Pxy.translate([-100, -100])
    Pxy.rotate(45)
    Pxy.rotate(45)
    Pxy.rotate(180)
    Pxy.rotate(-90)
Esempio n. 8
0
 def __add__(self, otherPoint):
     return Vector(
         Point(0, 0, 0),
         Point(self.x() + otherPoint.x(),
               self.y() + otherPoint.y(),
               self.z() + otherPoint.z()))
Esempio n. 9
0
 def vectorMultiply(self, otherVector):
     x = self.y() * otherVector.z() - self.z() * otherVector.y()
     y = self.x() * otherVector.z() - self.z() * otherVector.x()
     z = self.x() * otherVector.y() - self.y() * otherVector.x()
     return Vector(Point(0, 0, 0), Point(x, -y, z))
Esempio n. 10
0
 def __truediv__(self, coefficient):
     return Vector(
         Point(0, 0, 0),
         Point(self.x() / coefficient,
               self.y() / coefficient,
               self.z() / coefficient))
Esempio n. 11
0
 def __mul__(self, coefficient):
     return Vector(
         Point(0, 0, 0),
         Point(self.x() * coefficient,
               self.y() * coefficient,
               self.z() * coefficient))