import turtle
from math import tan, sqrt, pi
def prepare(x, y, color):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.color(color)
turtle.begin_fill()
def draw_polygon(num_sides, side_length):
angle = 360.0 / num_sides
for i in range(num_sides):
turtle.forward(side_length)
turtle.right(angle)
turtle.end_fill()
def calc_s(num_sides, side_length):
return num_sides * side_length ** 2 / (4 * tan(pi/num_sides))
def calc_side(square):
return sqrt(4 * square * tan(pi/num_sides) / num_sides)
turtle.hideturtle()
turtle.speed(10)
colors = ['red', 'green', 'blue', 'cyan', 'magenta', 'black', 'yellow', 'pink', 'brown']
xcoords = [0, 150, -150, 150, -150, 270, -270, 270, -270]
ycoords = [0, 150, -150, -150, 150, 270, -270, -270, 270]
squares = []
numsides = []
for i in range(9):
num_sides = i + 3
square = round(calc_s(num_sides, 100), 2)
side_length = round(calc_side(10000), 3)
squares.append(square)
numsides.append(num_sides)
print("Углов:", num_sides, "была площадь:", square, "стала длина грани:", side_length,
"изменение в", round(side_length/100, 2), "раз")
prepare(xcoords[i], ycoords[i], colors[i])
draw_polygon(num_sides, side_length)
turtle.exitonclick()
print("Список количество углов:", numsides, end="")
print("Список площади:", squares)
Объяснение:
def sqc(xa,ya,xb,yb,xc,yc) :
return ((xb - xa) * (yc - ya) - (xc - xa) * (yb - ya)) / 2
xa, ya, xb, yb = map(float,input().split())
n, m = map(int,input().split())
astra = []
sc = []
res, smax = 0, 0
for i in range(n) :
xc, yc = map(float,input().split())
astra.append((xc,yc))
sctmp = sqc(xa,ya,xb,yb,xc,yc)
if smax < abs(sctmp) :
smax = abs(sctmp)
#print(sctmp)
sc.append(sctmp)
for i in range(m) :
sp = sqc(xa,ya,xb,yb,xc,yc)
if smax < abs(sp) :
smax = abs(sp)
#print(sp)
for j in range(n) :
xd, yd = astra[j][0], astra[j][1]
if sp * sc[j] < 0 :
if smax < abs(sp * sc[j]) :
smax = abs(sp * sc[j])
print('{:.2f}'.format(smax))
У меня получилось.
import turtle
from math import tan, sqrt, pi
def prepare(x, y, color):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.color(color)
turtle.begin_fill()
def draw_polygon(num_sides, side_length):
angle = 360.0 / num_sides
for i in range(num_sides):
turtle.forward(side_length)
turtle.right(angle)
turtle.end_fill()
def calc_s(num_sides, side_length):
return num_sides * side_length ** 2 / (4 * tan(pi/num_sides))
def calc_side(square):
return sqrt(4 * square * tan(pi/num_sides) / num_sides)
turtle.hideturtle()
turtle.speed(10)
colors = ['red', 'green', 'blue', 'cyan', 'magenta', 'black', 'yellow', 'pink', 'brown']
xcoords = [0, 150, -150, 150, -150, 270, -270, 270, -270]
ycoords = [0, 150, -150, -150, 150, 270, -270, -270, 270]
squares = []
numsides = []
for i in range(9):
num_sides = i + 3
square = round(calc_s(num_sides, 100), 2)
side_length = round(calc_side(10000), 3)
squares.append(square)
numsides.append(num_sides)
print("Углов:", num_sides, "была площадь:", square, "стала длина грани:", side_length,
"изменение в", round(side_length/100, 2), "раз")
prepare(xcoords[i], ycoords[i], colors[i])
draw_polygon(num_sides, side_length)
turtle.exitonclick()
print("Список количество углов:", numsides, end="")
print("Список площади:", squares)
Объяснение:
def sqc(xa,ya,xb,yb,xc,yc) :
return ((xb - xa) * (yc - ya) - (xc - xa) * (yb - ya)) / 2
xa, ya, xb, yb = map(float,input().split())
n, m = map(int,input().split())
astra = []
sc = []
res, smax = 0, 0
for i in range(n) :
xc, yc = map(float,input().split())
astra.append((xc,yc))
sctmp = sqc(xa,ya,xb,yb,xc,yc)
if smax < abs(sctmp) :
smax = abs(sctmp)
#print(sctmp)
sc.append(sctmp)
for i in range(m) :
xc, yc = map(float,input().split())
sp = sqc(xa,ya,xb,yb,xc,yc)
if smax < abs(sp) :
smax = abs(sp)
#print(sp)
for j in range(n) :
xd, yd = astra[j][0], astra[j][1]
if sp * sc[j] < 0 :
if smax < abs(sp * sc[j]) :
smax = abs(sp * sc[j])
print('{:.2f}'.format(smax))
У меня получилось.