Untitled
unknown
python
a year ago
8.0 kB
5
Indexable
import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QRadioButton, QLabel, QDoubleSpinBox, QPushButton, \ QLineEdit, QGroupBox, QFormLayout from PyQt5.QtCore import Qt import math class GeometryCalculatorApp(QWidget): def __init__(self): super().__init__() self.init_ui() def init_ui(self): self.setWindowTitle('Geometry Calculator') self.bryla_group = QGroupBox('Wybierz bryłę:') self.bryla_layout = QVBoxLayout(self.bryla_group) self.bryla_buttons = { 'Kula': QRadioButton('Kula'), 'Czworościan': QRadioButton('Czworościan'), 'Ostrosłup prosty': QRadioButton('Ostrosłup prosty'), 'Stożek': QRadioButton('Stożek'), 'Walec': QRadioButton('Walec'), 'Elipsoida': QRadioButton('Elipsoida'), } for button in self.bryla_buttons.values(): self.bryla_layout.addWidget(button) self.obliczenie_group = QGroupBox('Wybierz obliczenie:') self.obliczenie_layout = QVBoxLayout(self.obliczenie_group) self.obliczenie_buttons = { 'Objętość': QRadioButton('Objętość'), 'Masa': QRadioButton('Masa'), 'Pole powierzchni': QRadioButton('Pole powierzchni'), } for button in self.obliczenie_buttons.values(): self.obliczenie_layout.addWidget(button) self.parametry_group = QGroupBox('Podaj parametry:') self.parametry_layout = QFormLayout(self.parametry_group) self.parametry_input_1 = QDoubleSpinBox() self.parametry_input_1.setRange(-100000, 100000) self.parametry_input_1.setDecimals(2) self.parametry_input_1.setSingleStep(0.1) self.parametry_input_2 = QDoubleSpinBox() self.parametry_input_2.setRange(-100000, 100000) self.parametry_input_2.setDecimals(2) self.parametry_input_2.setSingleStep(0.1) self.parametry_input_3 = QDoubleSpinBox() self.parametry_input_3.setRange(-100000, 100000) self.parametry_input_3.setDecimals(2) self.parametry_input_3.setSingleStep(0.1) self.parametry_layout.addRow('Parametr 1:', self.parametry_input_1) self.parametry_layout.addRow('Parametr 2:', self.parametry_input_2) self.parametry_layout.addRow('Parametr 3:', self.parametry_input_3) self.calculate_button = QPushButton('Oblicz') self.wynik_label = QLabel('Wynik:') self.wynik_label.setAlignment(Qt.AlignCenter) self.wynik_output = QLineEdit() self.wynik_output.setReadOnly(True) layout = QVBoxLayout() layout.addWidget(self.bryla_group) layout.addWidget(self.obliczenie_group) layout.addWidget(self.parametry_group) layout.addWidget(self.calculate_button) layout.addWidget(self.wynik_label) layout.addWidget(self.wynik_output) self.setLayout(layout) self.calculate_button.clicked.connect(self.calculate) self.show() def calculate(self): bryla = '' for button, name in self.bryla_buttons.items(): if name.isChecked(): bryla = button obliczenie = '' for button, name in self.obliczenie_buttons.items(): if name.isChecked(): obliczenie = button parametry = [ self.parametry_input_1.value(), self.parametry_input_2.value(), self.parametry_input_3.value() ] if bryla and obliczenie: wynik = self.calculate_geometry(bryla, obliczenie, parametry) self.wynik_output.setText(str(wynik)) def calculate_geometry(self, bryla, wlasciwosc, parametry): if bryla == 'kula': if wlasciwosc == 'objetosc': wynik = self.objetosc_kuli(*parametry) elif wlasciwosc == 'masa': wynik = self.masa_kuli(*parametry) elif wlasciwosc == 'pole': wynik = self.pole_powierzchni_kuli(*parametry) elif bryla == 'czworoscian': if wlasciwosc == 'objetosc': wynik = self.objetosc_czworoscianu(*parametry) elif wlasciwosc == 'masa': wynik = self.masa_czworoscianu(*parametry) elif wlasciwosc == 'pole': wynik = self.pole_powierzchni_czworoscianu(*parametry) elif bryla == 'ostroslup': if wlasciwosc == 'objetosc': wynik = self.objetosc_ostroslupa_prostego(*parametry) elif wlasciwosc == 'masa': wynik = self.masa_ostroslupa_prostego(*parametry) elif wlasciwosc == 'pole': wynik = self.pole_powierzchni_ostroslupa_prostego(*parametry) elif bryla == 'stozek': if wlasciwosc == 'objetosc': wynik = self.objetosc_stozka(*parametry) elif wlasciwosc == 'masa': wynik = self.masa_stozka(*parametry) elif wlasciwosc == 'pole': wynik = self.pole_powierzchni_stozka(*parametry) elif bryla == 'walec': if wlasciwosc == 'objetosc': wynik = self.objetosc_walca(*parametry) elif wlasciwosc == 'masa': wynik = self.masa_walca(*parametry) elif wlasciwosc == 'pole': wynik = self.pole_powierzchni_walca(*parametry) elif bryla == 'elipsoida': if wlasciwosc == 'objetosc': wynik = self.objetosc_elipsoidy(*parametry) elif wlasciwosc == 'masa': wynik = self.masa_elipsoidy(*parametry) elif wlasciwosc == 'pole': wynik = self.pole_powierzchni_elipsoidy(*parametry) return wynik def objetosc_kuli(r): V = (4 / 3) * math.pi * r ** 3 return V def masa_kuli(r, gestosc): m = (4 / 3) * math.pi * r ** 3 * gestosc return m def pole_powierzchni_kuli(r): P = 4 * math.pi * r ** 2 return P def objetosc_czworoscianu(a): V = (a ** 3) / 6 return V def masa_czworoscianu(a, gestosc): m = (a ** 3) / 6 * gestosc return m def pole_powierzchni_czworoscianu(a): P = math.sqrt(3) * a ** 2 return P def objetosc_ostroslupa_prostego(a, b, h): V = (1 / 3) * a * b * h return V def masa_ostroslupa_prostego(a, b, h, gestosc): m = (1 / 3) * a * b * h * gestosc return m def pole_powierzchni_ostroslupa_prostego(a, b, h): p = math.sqrt((a / 2) ** 2 + h ** 2) P = a * b + a * p + b * p return P def objetosc_stozka(r, h): V = (1 / 3) * math.pi * r ** 2 * h return V def masa_stozka(r, h, gestosc): m = (1 / 3) * math.pi * r ** 2 * h * gestosc return m def pole_powierzchni_stozka(r, l): P = math.pi * r * (r + l) return P def objetosc_walca(r, h): V = math.pi * r ** 2 * h return V def masa_walca(r, h, gestosc): m = math.pi * r ** 2 * h * gestosc return m def pole_powierzchni_walca(r, h): P = 2 * math.pi * r * (r + h) return P def objetosc_elipsoidy(a, b): V = (4 / 3) * math.pi * a * b ** 2 return V def masa_elipsoidy(a, b, gestosc): m = (4 / 3) * math.pi * a * b ** 2 * gestosc return m def pole_powierzchni_elipsoidy(a, b): s = math.sqrt(1 - (b ** 2 / a ** 2)) P = 2 * math.pi * b * (b + (a / s) * math.asin(s)) return P if __name__ == '__main__': app = QApplication(sys.argv) ex = GeometryCalculatorApp() sys.exit(app.exec_())
Editor is loading...
Leave a Comment