Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md

This file was deleted.

Binary file added __pycache__/center_mass.cpython-312.pyc
Binary file not shown.
Binary file added __pycache__/class_paint.cpython-312.pyc
Binary file not shown.
Binary file added __pycache__/const.cpython-312.pyc
Binary file not shown.
Binary file added __pycache__/moment_inert.cpython-312.pyc
Binary file not shown.
26 changes: 26 additions & 0 deletions center_mass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def calc_center_mass(x, y):
"""
Вычисляет центр масс многоугольника по координатам его вершин.
:param x: Список x-координат вершин.
:param y: Список y-координат вершин.
:return: Координаты центра масс (Cx, Cy).
"""
n = len(x)
A = 0.0
Cx = 0.0
Cy = 0.0

for i in range(n):
# Циклический индекс
j = (i + 1) % n
# Вычисление детерминанта (удвоенная площадь треугольника)
factor = x[i] * y[j] - x[j] * y[i]
A += factor
Cx += (x[i] + x[j]) * factor
Cy += (y[i] + y[j]) * factor

A *= 0.5
Cx /= (6.0 * A)
Cy /= (6.0 * A)

return Cx, Cy
55 changes: 55 additions & 0 deletions class_paint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from tkinter import *

class Paint(Frame):
def __init__(self, parent, x, y):
Frame.__init__(self, parent)
self.parent = parent
self.color = "black"
self.brush_size = 1
self.width = 900
self.height = 600
self.setUI()
self.x = x
self.y = y

def draw(self, event):
self.canv.create_oval(event.x - 2, event.y - 2, event.x + 2, event.y + 2,
fill=self.color, outline=self.color)

self.x.append(event.x)
self.y.append(-event.y)

def setUI(self):
self.pack(fill=BOTH, expand=1)
self.canv = Canvas(self, bg="white", width=self.width, height=self.height)
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.canv.grid(padx=1, pady=1, sticky=W+E+N+S)
self.canv.bind("<B1-Motion>", self.draw)

# Рисуем сетку
self.draw_grid()

def draw_grid(self):
"""Рисует координатную сетку на Canvas с разметкой."""
step = 50 # Шаг сетки
width = self.width
height = self.height

# Вертикальные линии с разметкой
for i in range(0, width+step, step):
self.canv.create_line(i, 0, i, height+step, fill="gray", dash=(1, 5))
if i != width // 2: # Не рисуем метку для центральной оси Y
self.canv.create_text(i, height - 10, text=str(i - width // 2), fill="black", font=("Arial", 8))

# Горизонтальные линии с разметкой
for i in range(0, height+step, step):
self.canv.create_line(0, i, width+step, i, fill="gray", dash=(1, 5))
if i != height - step: # Не рисуем метку для нижней грани
self.canv.create_text(10, i, text=str(height // 2 - i), fill="black", font=("Arial", 8), anchor=W)

# Ось X (горизонтальная линия внизу)
self.canv.create_line(0, height//2, width+step, height//2, fill="black", width=2)

# Ось Y (вертикальная линия по центру)
self.canv.create_line(width // 2, 0, width // 2, height, fill="black", width=2)
5 changes: 5 additions & 0 deletions const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
b = 0.0029 # м*К
c = 2.998 * 10**8 # м/с
h = 6.626 * 10**(-34)
lumin_son = 3.88 * 10**26 # Вт
ae = 149.6 * 10**9 # м
23 changes: 23 additions & 0 deletions moment_inert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def calc_moment_inert(x, y):
"""
Рассчитывает момент инерции плоской фигуры относительно оси,
перпендикулярной плоскости фигуры и проходящей через начало координат.

:param x: список X-координат вершин
:param y: список Y-координат вершин
:return: момент инерции I
"""
n = len(x)
if n < 3:
return 0.0

I = 0.0
for i in range(n):
xi, yi = x[i], y[i]
xj, yj = x[(i + 1) % n], y[(i + 1) % n]
cross = xi * yj - xj * yi
mag_sq = xi**2 + yi**2 + xi*xj + yi*yj + xj**2 + yj**2
I += cross * mag_sq

I *= 1 / 12
return abs(I)
Loading