Exemple #1
0
 def Graham_Scan(points: list):
     stack = []
     p_start = functions.find_first_point(points)
     p_start = points.pop(p_start)
     for i in range(len(points) - 1):
         m = math.atan2(points[i][1] - p_start[1],
                        points[i][0] - p_start[0])
         pair = [*points[i]]
         index = i
         for j in range(i + 1, len(points)):
             if (math.atan2(points[j][1] - p_start[1],
                            points[j][0] - p_start[0]) < m):
                 m = math.atan2(points[j][1] - p_start[1],
                                points[j][0] - p_start[0])
                 pair = points[j]
                 index = j
         t = [*points[i]]
         points[i] = [*pair]
         points[index] = [*t]
     stack.append(p_start)
     for i in range(len(points)):
         next_to_top = 0
         if len(stack) == 1:
             next_to_top = stack[-1]
         else:
             next_to_top = stack[-2]
         while len(stack) > 0 and functions.area(next_to_top, stack[-1],
                                                 points[i]) < 0:
             stack.pop()
         stack.append(points[i])
     return stack
Exemple #2
0
 def Segments_Intersect(pa: list, pb: list, pc: list, pd: list):
     p1, p2 = functions.bounding_rect(pa, pb)
     p3, p4 = functions.bounding_rect(pc, pd)
     if not functions.rectangle_intersect(p1, p2, p3, p4):
         return False
     s1 = functions.area(pc, pd, pa)
     s2 = functions.area(pc, pd, pb)
     s3 = functions.area(pa, pb, pc)
     s4 = functions.area(pa, pb, pd)
     if ((s1 > 0 > s2) or (s1 < 0 < s2)) and ((s3 > 0 > s4) or
                                              (s3 < 0 < s4)):
         return True
     elif s1 == 0 and functions.between(pc, pd, pa):
         return True
     elif s2 == 0 and functions.between(pc, pd, pb):
         return True
     elif s3 == 0 and functions.between(pa, pb, pc):
         return True
     elif s4 == 0 and functions.between(pa, pb, pd):
         return True
     return False
def execute() -> 'html':
    l = float((request.form['l']))
    #y = int(request.form['y'])

    tot = float(area(l))
    title = 'This is the equation\'s result'
    insertar_registro(l)
    return render_template(
        'results.html',
        the_title=title,
        #the_x=x,
        the_l=l,
        the_result=tot,
    )
def insertar_registro(l: float) -> None:
    configuracionDB = {
        'host': '127.0.0.1',
        'port': '5433',
        'user': '******',
        'password': '******',
        'database': 'test',
    }
    conexion = psycopg2.connect(**configuracionDB)
    tot = area(l)
    _SQL = ("INSERT INTO calculos(total) VALUES(%s)")
    cursor = conexion.cursor()
    cursor.execute(_SQL, (tot, ))
    conexion.commit()
    cursor.close()
    conexion.close()
Exemple #5
0
 def test_area(self):
     self.assertEqual(area(5, 5), 12.5)
Exemple #6
0
"""
------------------------------------------------------------------------
Task 7
------------------------------------------------------------------------
Author: Evan Attfield
ID:     180817010
Email:  [email protected]
Last Updated: Oct 30, 2018
------------------------------------------------------------------------
"""
from functions import diameter, circumference, area

radius = float(input('Enter radius: '))
d = diameter(radius)
c = circumference(radius)
a = area(radius)

print('')
print('Diameter of circle: {}'.format(d))
print('Circumference of circle: {:.2f}'.format(c))
print('Area of circle: {:.2f}'.format(a))
Exemple #7
0
from functions import circumference, area

print("Hi, welcom to Circle program\n")

x = float(input("Give me the radius of the circle: "))

while True:
    print(
        "1 --> Calculate the circumference of circle\n2 --> Calculate the area of circle\n3 --> exit"
    )
    z = int(input("your choice: "))

    if z == 1:
        circumference(x)
    elif z == 2:
        area(x)
    elif z == 3:
        break
    else:
        print("Error! Please select one of the following three options")
def test_area():
    assert functions.area(1) == pi