def BtnPressedCalc(self): A_y = float(self.str_Ay.get().replace(",", ".")) A_x = float(self.str_Ax.get().replace(",", ".")) B_y = float(self.str_By.get().replace(",", ".")) B_x = float(self.str_Bx.get().replace(",", ".")) M_y = float(self.str_My.get().replace(",", ".")) M_x = float(self.str_Mx.get().replace(",", ".")) pA = Punkt(A_y, A_x) pB = Punkt(B_y, B_x) pM = Punkt(M_y, M_x) if self.int_radioBSelect.get() == 0: t_NA = Winkel(float(self.str_TNA.get().replace(",", ".")), "gon") t_NM = Winkel(float(self.str_TNM.get().replace(",", ".")), "gon") t_NB = Winkel(float(self.str_TNB.get().replace(",", ".")), "gon") self.str_Alpha.set("") self.str_Beta.set("") pN = Rückwärtsschnitt.init_dir(pA, pB, pM, t_NA, t_NB, t_NM).schneiden() else: aAlpha = Winkel(float(self.str_Alpha.get().replace(",", ".")), "gon") aBeta = Winkel(float(self.str_Beta.get().replace(",", ".")), "gon") self.str_TNA.set("") self.str_TNM.set("") self.str_TNB.set("") pN = Rückwärtsschnitt(pA, pB, pM, aAlpha, aBeta).schneiden() self.str_Ny.set(self.runde(pN.get_y())) self.str_Nx.set(self.runde(pN.get_x()))
def readFile(self, filepath, sepDec=".", sepVal=","): with open(filepath, "r") as fh: lines = fh.read() for l in lines.splitlines(): if l == "": break if sepDec != ".": l = l.replace(sepDec, ".") try: sId, beta, s_rück, s_vor, y, x = l.split(sepVal) a = {} if beta != "": a["beta"] = Winkel(float(beta), "gon") if s_rück != "": a["s_rück"] = Strecke.init_länge(float(s_rück)) if s_vor != "": a["s_vor"] = Strecke.init_länge(float(s_vor)) if y != "" or x != "": p = Punkt(float(y), float(x), sId) else: p = Punkt(0, 0, sId) if sId in self.__polygon.get_pIdList(): self.__polygon.update_PpointAttributebyID(sId, a) else: self.__polygon.add_Ppointwithcoords(p, a) except: pass self.__parameter.update({"w_beta":Winkel(0), "w_y":0, "w_x":0})
def save_json(self): str_wRad = Winkel(float(self.strEntryRad.get().replace(",", ".")), einheit="rad").get_json() str_wGon = Winkel(float(self.strEntryGon.get().replace(",", ".")), einheit="gon").get_json() str_wGrad = Winkel(float(self.strEntryGrad.get().replace(",", ".")), einheit="grad").get_json() return json.dumps({ "rad": str_wRad, "gon": str_wGon, "grad": str_wGrad })
def showParam(self, parameter): self.dbl_ParaMY.set(self.runde(parameter["m_Y"])) self.dbl_ParaRotY.set( self.runde(Winkel(parameter["rot_Y"], "rad").get_w("gon"))) self.dbl_ParaTransY.set(self.runde(parameter["Y0"])) self.dbl_ParaTransX.set(self.runde(parameter["X0"])) if "m_X" in parameter: self.dbl_ParaMX.set(self.runde(parameter["m_X"])) self.dbl_ParaRotX.set( self.runde(Winkel(parameter["rot_X"], "rad").get_w("gon"))) else: self.dbl_ParaMX.set(self.runde(parameter["m_Y"])) self.dbl_ParaRotX.set( self.runde(Winkel(parameter["rot_Y"], "rad").get_w("gon")))
def zweite(p0,p1): dy = p1.get_y() - p0.get_y() dx = p1.get_x() - p0.get_x() t = atan2(dy, dx) if t < 0: t = 2*pi + t s = Strecke.init_koor(p0.get_y(),p0.get_x(),p1.get_y(),p1.get_x()).länge() return s, Winkel(t, "rad")
def btnBerechneErsteHAPressed(self): Y1 = float(self.str_y1.get().replace(",", ".")) X1 = float(self.str_x1.get().replace(",", ".")) t = Winkel(float(self.str_t.get().replace(",", ".")), "gon") s = Strecke.init_länge(float(self.str_s.get().replace(",", "."))) P2 = Punkt.ersteHA(Punkt(X1, Y1), s, t) self.str_x2.set(self.runde(P2.get_x())) self.str_y2.set(self.runde(P2.get_y()))
def BtnPressedCalc(self): p1_y = float(self.str_1y.get().replace(",", ".")) p1_x = float(self.str_1x.get().replace(",", ".")) p2_y = float(self.str_2y.get().replace(",", ".")) p2_x = float(self.str_2x.get().replace(",", ".")) p3_y = float(self.str_3y.get().replace(",", ".")) p3_x = float(self.str_3x.get().replace(",", ".")) p4_y = float(self.str_4y.get().replace(",", ".")) p4_x = float(self.str_4x.get().replace(",", ".")) p1 = Punkt(p1_y, p1_x) p2 = Punkt(p2_y, p2_x) p3 = Punkt(p3_y, p3_x) p4 = Punkt(p4_y, p4_x) tPhi = Winkel(float(self.str_Tphi.get().replace(",", ".")), "gon") tPsi = Winkel(float(self.str_Tpsi.get().replace(",", ".")), "gon") pN = Vorwärtsschnitt(p1, p2, p3, p4, tPhi, tPsi).schneiden() self.str_Ny.set(self.runde(pN.get_y())) self.str_Nx.set(self.runde(pN.get_x()))
def from_json(self, d): from datentyp.strecke import Strecke pd = {} for v in d.values(): for k1, v1 in v.items(): pd.update({k1: {}}) for k2, v2 in v1.items(): #Transformationen if k2 == "coord": c = {"coord": Punkt.init_json(v2)} pd[k1].update(c) elif k2 == "w": pd[k1].update({"w": Punkt.init_json(v2)}) elif k2 == "beta": pd[k1].update({"beta": Winkel.init_json(v2)}) elif k2 == "r": pd[k1].update({"r": Winkel.init_json(v2)}) elif k2 == "s_vor": pd[k1].update({"s_vor": Strecke.init_jsonKoor(v2)}) self.set_dic(pd)
def from_jsonPoly(self, d): from datentyp.strecke import Strecke pd = {} for k, v in d.items(): pd.update({k: {}}) for k1, v1 in v.items(): if k1 == "coord": c = {"coord": Punkt.init_json(v1)} pd[k].update(c) elif k1 == "w": pd[k].update({"w": Punkt.init_json(v1)}) elif k1 == "beta": pd[k].update({"beta": Winkel.init_json(v1)}) elif k1 == "t_n": pd[k].update({"t_n": Winkel.init_json(v1)}) elif k1 == "t_0": pd[k].update({"t_0": Winkel.init_json(v1)}) elif k1 == "r": pd[k].update({"r": Winkel.init_json(v1)}) elif k1 == "s_vor": pd[k].update({"s_vor": Strecke.init_jsonKoor(v1)}) self.set_dic(pd)
def berechneRingpolygon(self): # Für Außenwinkel n = self.__polygon.get_counter() # testdata: 6:(p1...p6) beta_summe = 0 s_summe = 0 for pId in self.__polygon.get_pIdList(): beta_summe += self.__polygon.get_PpointbyPId(pId)["beta"].get_w() s_summe += self.__polygon.get_PpointbyPId(pId)["s_vor"].länge() w_beta = Winkel((n+2) * pi - beta_summe) w_beta_n = Winkel(w_beta.get_w() / n) # r, dy, dx dy_summe = 0 dx_summe = 0 for i in range(n): # testdata: Standpunkt p1...p6 if i == 0: r = Winkel(0) else: r = Winkel(self.__polygon.get_PpointbyNr(i-1)["r"].get_w() + self.__polygon.get_PpointbyNr(i)["beta"].get_w() + w_beta_n.get_w() - pi) dy = sin(r.get_w()) * self.__polygon.get_PpointbyNr(i)["s_vor"].länge() dx = cos(r.get_w()) * self.__polygon.get_PpointbyNr(i)["s_vor"].länge() dy_summe += dy dx_summe += dx self.__polygon.update_PpointAttributebyNr(i, {"r": r, "dy": dy, "dx": dx}) w_y_s = - dy_summe / s_summe w_x_s = - dx_summe / s_summe for i in range(1,n): # testdata: Standpunkt p2...p6 s = self.__polygon.get_PpointbyNr(i-1)["s_vor"].länge() r = self.__polygon.get_PpointbyNr(i-1)["r"].get_w() dy = self.__polygon.get_PpointbyNr(i-1)["dy"] + w_y_s * s dx = self.__polygon.get_PpointbyNr(i-1)["dx"] + w_x_s * s y = self.__polygon.get_PpointbyNr(i-1)["coord"].get_y() x = self.__polygon.get_PpointbyNr(i-1)["coord"].get_x() pId = self.__polygon.get_PpointbyNr(i-1)["coord"].get_id() self.__polygon.update_PpointAttributebyNr(i, {"coord": Punkt(y+dy, x+dx, pId)}) self.__parameter.update({"w_beta":w_beta, "w_y":dy_summe, "w_x":dx_summe})
pd[k].update({"t_n": Winkel.init_json(v1)}) elif k1 == "t_0": pd[k].update({"t_0": Winkel.init_json(v1)}) elif k1 == "r": pd[k].update({"r": Winkel.init_json(v1)}) elif k1 == "s_vor": pd[k].update({"s_vor": Strecke.init_jsonKoor(v1)}) self.set_dic(pd) if __name__ == "__main__": from datentyp.winkel import Winkel from datentyp.strecke import Strecke p1 = Punkt(1, 1, "Test") p12_t = Winkel(100, "gon") s = 1 p12_s = Strecke.init_länge(s) result_p2 = p1.ersteHA(p12_s, p12_t) #print("P1:", p1, "Strecke:", s, "Winkel:", p12_t, "P1:", result_p2) jp = json.dumps(p1, default=lambda objekt: objekt.get_json(), sort_keys=True, indent=4) print(jp) p_j = Punkt.init_json(json.loads(jp)) print(p_j) pDic = Punkt_Dic() pDic.addPoint(p1)
def schneiden(self): p1_y = self.__p1.get_y() p1_x = self.__p1.get_x() p2_y = self.__p2.get_y() p2_x = self.__p2.get_x() t_41 = Strecke(self.__p1, self.__p4).zweiteHA()[1].get_w() t_1N = t_41 + self.__tPhi.get_w() tan_1N = tan(t_1N) t_23 = Strecke(self.__p2, self.__p3).zweiteHA()[1].get_w() t_2N = t_23 + self.__tPsi.get_w() tan_2N = tan(t_2N) pN_x = p1_x + ((p2_y - p1_y) - (p2_x - p1_x) * tan_2N) / (tan_1N - tan_2N) pN_y = p1_y + (pN_x - p1_x) * tan_1N return Punkt(pN_y, pN_x) if __name__ == "__main__": p1 = Punkt(24681.92, 90831.87) p4 = Punkt(23231.58, 91422.92) p2 = Punkt(24877.72, 89251.09) p3 = Punkt(22526.65, 89150.52) tPhi = Winkel(331.6174, "gon") tPsi = Winkel(60.7510, "gon") pN = Vorwärtsschnitt(p1, p2, p3, p4, tPhi, tPsi).schneiden() print(pN)
def berechnePolygonzug(self): t_0 = Strecke(self.__polygon.get_PpointbyNr(0)["coord"], self.__polygon.get_PpointbyNr(1)["coord"]).zweiteHA()[1] self.__polygon.update_PpointAttributebyNr(0, {"t_0": t_0}) t_n = Strecke(self.__polygon.get_PpointbyNr(-2)["coord"], self.__polygon.get_PpointbyNr(-1)["coord"]).zweiteHA()[1] self.__polygon.update_PpointAttributebyNr(-2, {"t_n": t_n}) # w_beta n = self.__polygon.get_counter()-2 # Anzahl Messstandpunkte 5:(p0...p6)-2 beta_summe = 0 for i in range(1, n+1): # testdata: Standpunkt p1...p6 beta_summe += self.__polygon.get_PpointbyNr(i)["beta"].get_w() w_beta = self.__polygon.get_PpointbyNr(-2)["t_n"].get_w() - (self.__polygon.get_PpointbyNr(0)["t_0"].get_w() + beta_summe - (n*pi)) if w_beta > pi: w_beta = 2*pi - w_beta w_beta = Winkel(w_beta) w_beta_n = Winkel(w_beta.get_w() / n) # r for i in range(1, n+1): # testdata: Standpunkt p1...p6 beta = self.__polygon.get_PpointbyNr(i)["beta"].get_w() if i == 1: r = self.__polygon.get_PpointbyNr(0)["t_0"].get_w() + beta + w_beta_n.get_w() + pi else: r = self.__polygon.get_PpointbyNr(i-1)["r"].get_w() + beta + w_beta_n.get_w() + pi if r < (2*pi): r += 2*pi elif r > (2*pi): r -= 2*pi self.__polygon.update_PpointAttributebyNr(i, {"r": Winkel(r)}) # dy, dx Koordinatenunterschiede dy_summe = 0 dx_summe = 0 s_summe = 0 for i in range(1, n): # testdata: Standpunkt p1...p4 s = self.__polygon.get_PpointbyNr(i)["s_vor"].länge() dy = s * sin(self.__polygon.get_PpointbyNr(i)["r"].get_w()) dx = s * cos(self.__polygon.get_PpointbyNr(i)["r"].get_w()) dy_summe += dy dx_summe += dx self.__polygon.update_PpointAttributebyNr(i, {"dy": dy}) self.__polygon.update_PpointAttributebyNr(i, {"dx": dx}) s_summe += s # w_y, w_x Koordinatenabschlussverbesserung w_y = (self.__polygon.get_PpointbyNr(-2)["coord"].get_y() - self.__polygon.get_PpointbyNr(1)["coord"].get_y()) - dy_summe w_x = (self.__polygon.get_PpointbyNr(-2)["coord"].get_x() - self.__polygon.get_PpointbyNr(1)["coord"].get_x()) - dx_summe w_y_s = (w_y / s_summe) w_x_s = (w_x / s_summe) # y,x Koordinaten for i in range(1, n-1): # testdata: Standpunkt p1...p3 s = self.__polygon.get_PpointbyNr(i)["s_vor"].länge() dy = self.__polygon.get_PpointbyNr(i)["dy"] dx = self.__polygon.get_PpointbyNr(i)["dx"] v_y = w_y_s * s v_x = w_x_s * s y = self.__polygon.get_PpointbyNr(i)["coord"].get_y() + dy + v_y x = self.__polygon.get_PpointbyNr(i)["coord"].get_x() + dx + v_x self.__polygon.update_PpointAttributebyNr(i+1, {"coord": Punkt(y, x)}) self.__parameter.update({"w_beta":w_beta, "w_y":w_y, "w_x":w_x})
def set_polygon_json(self,s): dic_j = json.loads(s)["parameter"] self.__parameter = {"w_beta":Winkel.init_json(dic_j["w_beta"]), "w_y":dic_j["w_y"], "w_x":dic_j["w_x"]} self.__polygon.set_json(s)
def btnPressedBerechneGon(self): w = Winkel(float(self.strEntryGon.get().replace(",", ".")), einheit="gon") self.strEntryRad.set(self.runde(w.get_w(einheit="rad"))) self.strEntryGrad.set(self.runde(w.get_w(einheit="grad")))
indent=4) pIdL_j = json.dumps(self.__pIdList) return {"pDic": pDic_j, "pIdL": pIdL_j} def set_json(self, s): p_j = json.loads(s) self.__PDic.from_jsonPoly(p_j["pDic"]) self.__pIdList = p_j["pIdL"] def clean(self): self.__pIdList.clear() self.__PDic.clear() if __name__ == "__main__": from datentyp.winkel import Winkel from datentyp.strecke import Strecke p0 = Punkt(1, 1, "p01") dir01 = Winkel(50, "gon") dist01 = Strecke.init_länge(3) poly = Polygon() poly.add_Ppointwithcoords(p0) poly.add_NextPointByDirDist(dir01, dist01) poly.add_NextPointByDirDist(dir01, dist01) poly.update_PpointAttributebyNr(2, {"test": 1235}) print(poly.get_PpointbyNr(2))
def init_dir(cls, pA, pB, pM, dirA, dirB, dirM): aAlpha = dirA.get_w() - dirM.get_w() aBeta = dirB.get_w() - dirM.get_w() aAlpha, aBeta = [e + 2 * pi if e < 0 else e for e in [aAlpha, aBeta]] return cls(pA, pB, pM, Winkel(aAlpha), Winkel(aBeta))
(1+tan_MN**2) dMN_y = dMN_x * tan_MN N_y = M_y + dMN_y N_x = M_x + dMN_x return Punkt(N_y, N_x) def cot(a): return (1 / tan(a)) if __name__ == "__main__": pA = Punkt(46867.94, 5537.00) pM = Punkt(49666.56, 4448.58) pB = Punkt(51293.86, 6365.89) riwiA = Winkel(66.8117, "gon") riwiM = Winkel(362.8516, "gon") riwiB = Winkel(294.7845, "gon") # pA = Punkt(209.13, 193.4) # pM = Punkt(420.68, 639.27) # pB = Punkt(578.47, 198.38) # riwiA = 0.0 # riwiM = 116.895 # riwiB = 284.622 pRes = Rückwärtsschnitt.init_dir(pA, pB, pM, riwiA, riwiB, riwiM).schneiden() print(pRes)
def zweiteHA(self): dy, dx = self.subtrahiere() t = atan2(dy, dx) if t < 0: t = 2 * pi + t return self.länge(), Winkel(t, "rad")
def load_json(self, s): dic_j = json.loads(s) wgrad = Winkel() wrad = Winkel() wgon = Winkel() wgrad.set_json(dic_j["grad"]) wrad.set_json(dic_j["rad"]) wgon.set_json(dic_j["gon"]) self.strEntryGrad.set(wgrad.get_w("grad")) self.strEntryRad.set(wrad.get_w("rad")) self.strEntryGon.set(wgon.get_w("gon"))