diff --git a/aero_astro_calc/Inertia.py b/aero_astro_calc/Inertia.py index 535e556..dd0c297 100644 --- a/aero_astro_calc/Inertia.py +++ b/aero_astro_calc/Inertia.py @@ -1,4 +1,5 @@ from typing import Tuple +from numpy import tan, pi class Inertia: @@ -6,9 +7,68 @@ class Inertia: self.area = area self.centroid = centroid - def __add__(self, other): - AX = self.area * self.centroid[0] + other.area * other.centroid[0] - AY = self.area * self.centroid[1] + other.area * other.centroid[1] - self.area = self.area + other.area - self.centroid = (AX / self.area, AY / self.area) + 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)