def onAutoTrim(self): """ Called when trim angle must be auto computed. """ # Start at null trim angle trim = 0.0 # Get center of gravity disp = self.computeDisplacement(trim) G = [disp[1], disp[2], disp[3]] disp = disp[0] # Get bouyancy center draft = self.computeDraft(disp) xcb = draft[1] draft = draft[0] KBT = Hydrostatics.KBT(self.ship, draft, trim) B = [xcb, KBT[0], KBT[1]] # Get stability initial condition BG = [G[0]-B[0], G[1]-B[1], G[2]-B[2]] x = BG[0]*math.cos(math.radians(trim)) - BG[2]*math.sin(math.radians(trim)) y = BG[1] z = BG[0]*math.sin(math.radians(trim)) + BG[2]*math.cos(math.radians(trim)) var = math.degrees(math.atan2(x,z)) # Iterate looking stability point dVar = math.copysign(0.0033, var) while True: if (dVar*math.copysign(dVar, var) < 0.0): break trim = trim - math.copysign(dVar, var) # Get center of gravity disp = self.computeDisplacement(trim) G = [disp[1], disp[2], disp[3]] disp = disp[0] # Get bouyancy center draft = self.computeDraft(disp, trim) xcb = draft[1] draft = draft[0] KBT = Hydrostatics.KBT(self.ship, draft, trim) B = [xcb, KBT[0], KBT[1]] # Get stability initial condition BG = [G[0]-B[0], G[1]-B[1], G[2]-B[2]] x = BG[0]*math.cos(math.radians(trim)) - BG[2]*math.sin(math.radians(trim)) y = BG[1] z = BG[0]*math.sin(math.radians(trim)) + BG[2]*math.cos(math.radians(trim)) var = math.degrees(math.atan2(x,z)) self.form.trim.setValue(trim)
def computeGZ(self, draft, trim, roll): """ Compute GZ value. @param draft Ship draft. @param trim Ship trim angle [degrees]. @param roll Ship roll angle [degrees]. @return GZ value [m]. """ # Get center of gravity (x coordinate not relevant) disp = self.computeDisplacement(trim, roll) G = [disp[2], disp[3]] disp = disp[0] # Get bouyancy center (x coordinate not relevant) KBT = Hydrostatics.KBT(self.ship, draft, trim, roll) B = [KBT[0], KBT[1]] # GZ computation BG = [G[0] - B[0], G[1] - B[1]] y = BG[0]*math.cos(math.radians(-roll)) - BG[1]*math.sin(math.radians(-roll)) z = BG[0]*math.sin(math.radians(-roll)) + BG[1]*math.cos(math.radians(-roll)) return -y