from typing import Tuple from numpy import tan, pi class Inertia: def __init__(self, area: float, centroid: Tuple[float, float]): self.area = area self.centroid = centroid self.sections = [self] def __add__(self, other): sections = self.sections[:] sections.extend(other.sections[:]) A = 0 AX = 0 AY = 0 for section in sections: A += section.area AX += section.area * section.centroid[0] AY += section.area * section.centroid[1] centroid = (AX / A, AY / A) inertia = Inertia(A, centroid) inertia.sections = sections[:] return inertia def __str__(self): return f"Area: {self.area}, Centroid: {self.centroid}" def Ixx(self): return sum( [ section.area * (section.centroid[1] - self.centroid[1]) ** 2 for section in self.sections ] ) def Iyy(self): return sum( [ section.area * (section.centroid[0] - self.centroid[0]) ** 2 for section in self.sections ] ) def Ixy(self): return sum( [ section.area * (section.centroid[0] - self.centroid[0]) * (section.centroid[1] - self.centroid[1]) for section in self.sections ] ) def Iyx(self): return self.Ixy() def smiley(self): return self.Ixx() * self.Iyy() - self.Ixy() ** 2 def x_factor(self, Mx, My): return (My * self.Ixx() - Mx * self.Ixy()) / self.smiley() def y_factor(self, Mx, My): return (Mx * self.Iyy() - My * self.Ixy()) / self.smiley() # def alpha(self, Mx, My): # return 180 / (tan(self.x_factor(Mx, My) / self.y_factor(Mx, My)) * pi)