Stand Masterprojekt_V2 ohne Michelle

This commit is contained in:
2025-12-30 09:56:04 +01:00
commit 0a65208d71
41 changed files with 22312 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import os
import sqlite3
class Datenbank_anlegen:
def __init__(self, pfad_datenbank):
self.pfad_datenbank = pfad_datenbank
self.db_anlegen()
def db_anlegen(self):
#pfad = r"C:\Users\fabia\OneDrive\Jade HS\Master\MGW2\Masterprojekt_allgemein\Masterprojekt\Programmierung\Campusnetz\Campusnetz.db"
if not os.path.exists(self.pfad_datenbank):
con = sqlite3.connect(self.pfad_datenbank)
cursor = con.cursor()
cursor.executescript("""CREATE TABLE Netzpunkte (
punktnummer TEXT(10),
naeherungx NUMERIC(9,3),
naeherungy NUMERIC(7,3),
naeherungz NUMERIC(8,3),
CONSTRAINT pk_Netzpunkte PRIMARY KEY (punktnummer)
);
CREATE TABLE Standpunkte_Tachymeter (
spID INTEGER PRIMARY KEY AUTOINCREMENT,
punktnummer TEXT(10),
orientierunghz NUMERIC(2,5),
orientierungv NUMERIC(2,5),
dateipfad TEXT(150),
standpunktsnummer INTEGER,
CONSTRAINT fk_Standpunkte_Tachymeter_Netzpunkte FOREIGN KEY (punktnummer)
REFERENCES Netzpunkte(punktnummer)
);
CREATE TABLE Beobachtungen_Tachymeter (
btID INTEGER PRIMARY KEY AUTOINCREMENT,
spID INTEGER,
punktnummer TEXT(10),
hz NUMERIC(3,5),
v NUMERIC(3,5),
distanz NUMERIC(4,4),
CONSTRAINT fk_Beobachtungen_Tachymeter_Standpunkte_Tachymeter FOREIGN KEY (spID)
REFERENCES Standpunkte_Tachymeter(spID),
CONSTRAINT fk_Beobachtungen_Tachymeter_Netzpunkte FOREIGN KEY (punktnummer)
REFERENCES Netzpunkte(punktnummer)
);
""");
con.commit()
con.close()

View File

@@ -0,0 +1,157 @@
from pathlib import Path
import sqlite3
from decimal import Decimal, getcontext
# ToDo: instrumentenID von Anwender übergeben lassen!
def string_to_decimal(zahl):
zahl = zahl.replace(',', '.')
return Decimal(zahl)
pfad_script = Path(__file__).resolve().parent
dateiname = "campsnetz_beobachtungen_bereinigt.csv"
pfad_datei = pfad_script.parent / "Daten" / dateiname
# Prüfen, ob Bereits Daten aus der Datei in der Datenbank vorhanden sind
pfad_datenbank = pfad_script.parent / "Campusnetz.db"
instrumentenID = 1
con = sqlite3.connect(pfad_datenbank)
cursor = con.cursor()
liste_dateinamen_in_db = [r[0] for r in cursor.execute(
"SELECT DISTINCT dateiname FROM Beobachtungen"
).fetchall()]
liste_beobachtungsgruppeID = [r[0] for r in cursor.execute("""SELECT DISTINCT beobachtungsgruppeID FROM Beobachtungen""").fetchall()]
liste_instrumentenid = [r[0] for r in cursor.execute("SELECT instrumenteID FROM Instrumente").fetchall()]
con.close()
cursor.close
Import_fortsetzen = True
if dateiname in liste_dateinamen_in_db:
Import_fortsetzen = False
if Import_fortsetzen:
nummer_zielpunkt = 0
try:
nummer_beobachtungsgruppeID = max(liste_beobachtungsgruppeID)
except:
nummer_beobachtungsgruppeID = 0
with (open(pfad_datei, "r", encoding="utf-8") as f):
liste_fehlerhafte_zeile = []
liste_beobachtungen_vorbereitung = []
for i, zeile in enumerate(f):
if i < 3:
continue
zeile = zeile.strip().split(";")
if zeile[1] == "" and zeile[2] == "" and zeile[3] == "":
nummer_beobachtungsgruppeID += 1
#print("Standpunkt: ",nummer_beobachtungsgruppeID ,zeile[0])
standpunkt = zeile[0]
if nummer_zielpunkt % 6 != 0:
liste_fehlerhafte_zeile.append(i)
nummer_zielpunkt = 0
liste_zielpunkte_hs = []
liste_zielpunkte_vs2 = []
liste_zielpunkte_vs3 = []
else:
nummer_zielpunkt += 1
if zeile[0] not in liste_zielpunkte_hs:
liste_zielpunkte_hs.append(zeile[0])
if zeile[0] in liste_zielpunkte_vs3:
#print(f"{nummer_zielpunkt} VS3 HS1 {zeile}")
liste_beobachtungen_vorbereitung.append([nummer_beobachtungsgruppeID,"VS3", "HS1", standpunkt, zeile[0], zeile[1], zeile[2], zeile[3]])
elif zeile[0] in liste_zielpunkte_vs2:
#print(f"{nummer_zielpunkt} VS2 HS1 {zeile}")
liste_beobachtungen_vorbereitung.append([nummer_beobachtungsgruppeID,"VS2", "HS1", standpunkt, zeile[0], zeile[1], zeile[2], zeile[3]])
else:
#print(f"{nummer_zielpunkt} VS1 HS1 {zeile}")
liste_beobachtungen_vorbereitung.append(
[nummer_beobachtungsgruppeID,"VS1", "HS1", standpunkt, zeile[0], zeile[1], zeile[2],
zeile[3]])
else:
liste_zielpunkte_hs.remove(zeile[0])
if zeile[0] in liste_zielpunkte_vs3:
#print(f"{nummer_zielpunkt} VS3 HS2 {zeile}")
liste_beobachtungen_vorbereitung.append(
[nummer_beobachtungsgruppeID,"VS3", "HS2", standpunkt, zeile[0], zeile[1], zeile[2],
zeile[3]])
elif zeile[0] in liste_zielpunkte_vs2:
if zeile[0] not in liste_zielpunkte_vs3:
liste_zielpunkte_vs3.append(zeile[0])
#print(f"{nummer_zielpunkt} VS2 HS2 {zeile}")
liste_beobachtungen_vorbereitung.append(
[nummer_beobachtungsgruppeID,"VS2", "HS2", standpunkt, zeile[0], zeile[1], zeile[2],
zeile[3]])
else:
if zeile[0] not in liste_zielpunkte_vs2:
liste_zielpunkte_vs2.append(zeile[0])
#print(f"{nummer_zielpunkt} VS1 HS2 {zeile}")
liste_beobachtungen_vorbereitung.append(
[nummer_beobachtungsgruppeID,"VS1", "HS2", standpunkt, zeile[0], zeile[1], zeile[2],
zeile[3]])
if liste_fehlerhafte_zeile == []:
#print(f"Einlesen der Datei {pfad_datei} erfolgreich beendet.")
pass
else:
print(f"Das Einlesen der Datei {pfad_datei} wurde abgebrochen.\nBitte bearbeiten Sie die Zeilen rund um: {", ".join(map(str, liste_fehlerhafte_zeile))} in der csv-Datei und wiederholen Sie den Import.")
Import_fortsetzen = False
else:
print(f"Der Import wurde abgebrochen, weil die Beobachtungen aus der Datei {pfad_datei} bereits in der Datenbank vorhanden sind.")
if Import_fortsetzen:
liste_beobachtungen_import = []
while len(liste_beobachtungen_vorbereitung) > 0:
liste_aktueller_zielpunkt = liste_beobachtungen_vorbereitung[0]
aktueller_zielpunkt = liste_aktueller_zielpunkt[4]
#print(liste_beobachtungen_vorbereitung[0])
for index in range(1, len(liste_beobachtungen_vorbereitung)):
liste = liste_beobachtungen_vorbereitung[index]
if liste[4] == aktueller_zielpunkt:
#print(liste)
richtung1 = string_to_decimal(liste_aktueller_zielpunkt[5])
richtung2 = string_to_decimal(liste[5]) - Decimal(200)
zenitwinkel_vollsatz = (string_to_decimal(liste_aktueller_zielpunkt[6]) - string_to_decimal(liste[6]) + 400) / 2
distanz_vollsatz = (string_to_decimal(liste_aktueller_zielpunkt[7]) + string_to_decimal(liste[7])) / 2
if richtung2 < 0:
richtung2 += Decimal(400)
elif richtung2 > 400:
richtung2 -= Decimal(400)
richtung_vollsatz = (richtung1 + richtung2) / 2
#print(richtung_vollsatz)
#print(zenitwinkel_vollsatz)
#print(distanz_vollsatz)
liste_beobachtungen_import.append([liste[0], liste[3], liste[4], richtung_vollsatz, zenitwinkel_vollsatz, distanz_vollsatz])
del liste_beobachtungen_vorbereitung[index]
del liste_beobachtungen_vorbereitung[0]
break
if instrumentenID not in liste_instrumentenid:
Import_fortsetzen = False
print("Der Import wurde abgebrochen. Bitte eine gültige InstrumentenID eingeben. Bei Bedarf ist das Instrument neu anzulegen.")
if Import_fortsetzen:
con = sqlite3.connect(pfad_datenbank)
cursor = con.cursor()
for beobachtung_import in liste_beobachtungen_import:
cursor.execute("INSERT INTO Beobachtungen (punktnummer_sp, punktnummer_zp, instrumenteID, beobachtungsgruppeID, tachymeter_richtung, tachymeter_zenitwinkel, tachymeter_distanz, dateiname) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(beobachtung_import[1], beobachtung_import[2], instrumentenID, beobachtung_import[0], float(beobachtung_import[3]), float(beobachtung_import[4]), float(beobachtung_import[5]), dateiname))
con.commit()
cursor.close()
con.close()
print(f"Der Import der Datei {pfad_datei} wurde erfolgreich abgeschlossen.")

View File

@@ -0,0 +1,208 @@
@staticmethod
def R_matrix_aus_quaternion(q0, q1, q2, q3):
return sp.Matrix([
[1 - 2 * (q2 ** 2 + q3 ** 2), 2 * (q1 * q2 - q0 * q3), 2 * (q0 * q2 + q1 * q3)],
[2 * (q1 * q2 + q0 * q3), 1 - 2 * (q1 ** 2 + q3 ** 2), 2 * (q2 * q3 - q0 * q1)],
[2 * (q1 * q3 - q0 * q2), 2 * (q0 * q1 + q2 * q3), 1 - 2 * (q1 ** 2 + q2 ** 2)]
])
def Helmerttransformation_Quaternionen(self):
db = Datenbank.Datenbankzugriff(self.pfad_datenbank)
dict_ausgangssystem = db.get_koordinaten("naeherung_lh", "Dict")
dict_zielsystem = db.get_koordinaten("naeherung_us", "Dict")
gemeinsame_punktnummern = sorted(set(dict_ausgangssystem.keys()) & set(dict_zielsystem.keys()))
anzahl_gemeinsame_punkte = len(gemeinsame_punktnummern)
liste_punkte_ausgangssystem = [dict_ausgangssystem[i] for i in gemeinsame_punktnummern]
liste_punkte_zielsystem = [dict_zielsystem[i] for i in gemeinsame_punktnummern]
print("Anzahl gemeinsame Punkte:", anzahl_gemeinsame_punkte)
print("\nErste Zielpunkte:")
for pn, P in list(zip(gemeinsame_punktnummern, liste_punkte_zielsystem))[:5]:
print(pn, [float(P[0]), float(P[1]), float(P[2])])
print("\nErste Ausgangspunkte:")
for pn, p in list(zip(gemeinsame_punktnummern, liste_punkte_ausgangssystem))[:5]:
print(pn, [float(p[0]), float(p[1]), float(p[2])])
# ToDo: Achtung: Die Ergebnisse sind leicht anders, als in den Beispielrechnung von Luhmann (Rundungsfehler bei Luhmann?)
# ToDo: Automatische Ermittlung der Anzahl Nachkommastellen für Test auf Orthonormalität integrieren!
p1, p2, p3 = liste_punkte_ausgangssystem[0], liste_punkte_ausgangssystem[1], liste_punkte_ausgangssystem[2]
P1, P2, P3 = liste_punkte_zielsystem[0], liste_punkte_zielsystem[1], liste_punkte_zielsystem[2]
# 1) Näherungswertberechnung
m0 = (P2 - P1).norm() / (p2 - p1).norm()
U = (P2 - P1) / (P2 - P1).norm()
W = (U.cross(P3 - P1)) / (U.cross(P3 - P1)).norm()
V = W.cross(U)
u = (p2 - p1) / (p2 - p1).norm()
w = (u.cross(p3 - p1)) / (u.cross(p3 - p1)).norm()
v = w.cross(u)
R = sp.Matrix.hstack(U, V, W) * sp.Matrix.hstack(u, v, w).T
XS = (P1 + P2 + P3) / 3
xS = (p1 + p2 + p3) / 3
Translation = XS - m0 * R * xS
# 2) Test auf orthonormale Drehmatrix bei 3 Nachkommastellen!
if R.T.applyfunc(lambda x: round(float(x), 3)) == R.inv().applyfunc(lambda x: round(float(x), 3)) and (
R.T * R).applyfunc(lambda x: round(float(x), 3)) == sp.eye(3).applyfunc(lambda x: round(float(x), 3)) and (
(round(R.det(), 3) == 1.000 or round(R.det(), 3) == -1.000)):
print("R ist Orthonormal!")
else:
print("R ist nicht Orthonormal!")
# 3) Quaternionen berechnen
# ToDo: Prüfen, ob Vorzeichen bei q0 richtig ist!
# ToDo: q0 stimmt nicht mit Luhmann überein!
q = Quaternion.from_rotation_matrix(R)
q0_wert = q.a
q1_wert = q.b
q2_wert = q.c
q3_wert = q.d
dX, dY, dZ, m, q0, q1, q2, q3 = sp.symbols('dX dY dZ m q0 q1 q2 q3')
R_symbolisch = self.R_matrix_aus_quaternion(q0, q1, q2, q3)
# 4) Funktionales Modell
f_zeilen = []
for punkt in liste_punkte_ausgangssystem:
punkt_vektor = sp.Matrix([punkt[0], punkt[1], punkt[2]])
f_zeile_i = sp.Matrix([dX, dY, dZ]) + m * R_symbolisch * punkt_vektor
f_zeilen.extend(list(f_zeile_i))
f_matrix = sp.Matrix(f_zeilen)
f = f_matrix
A_ohne_zahlen = f_matrix.jacobian([dX, dY, dZ, m, q0, q1, q2, q3])
# Parameterschätzung
schwellenwert = 1e-4
anzahl_iterationen = 0
alle_kleiner_vorherige_iteration = False
l_vektor = sp.Matrix([koord for P in liste_punkte_zielsystem for koord in P])
l = l_vektor
P = sp.eye(3 * anzahl_gemeinsame_punkte)
l_berechnet_0 = None
while True:
if anzahl_iterationen == 0:
zahlen_0 = {dX: float(Translation[0]), dY: float(Translation[1]), dZ: float(Translation[2]), m: float(m0),
q0: float(q0_wert), q1: float(q1_wert),
q2: float(q2_wert),
q3: float(q3_wert)}
x0 = sp.Matrix(
[zahlen_0[dX], zahlen_0[dY], zahlen_0[dZ], zahlen_0[m], zahlen_0[q0], zahlen_0[q1], zahlen_0[q2],
zahlen_0[q3]])
l_berechnet_0 = f.subs(zahlen_0).evalf(n=30)
dl_0 = l_vektor - l_berechnet_0
A_0 = A_ohne_zahlen.subs(zahlen_0).evalf(n=30)
N = A_0.T * P * A_0
n_0 = A_0.T * P * dl_0
Qxx_0 = N.inv()
dx = Qxx_0 * n_0
x = x0 + dx
x = sp.N(x, 30) # 30 Nachkommastellen
q_norm = sp.sqrt(x[4] ** 2 + x[5] ** 2 + x[6] ** 2 + x[7] ** 2)
x = sp.Matrix(x)
x[4] /= q_norm
x[5] /= q_norm
x[6] /= q_norm
x[7] /= q_norm
anzahl_iterationen += 1
print(f"Iteration Nr.{anzahl_iterationen} abgeschlossen")
print(dx.evalf(n=3))
else:
zahlen_i = {dX: float(x[0]), dY: float(x[1]), dZ: float(x[2]), m: float(x[3]), q0: float(x[4]),
q1: float(x[5]),
q2: float(x[6]),
q3: float(x[7])}
l_berechnet_i = f.subs(zahlen_i).evalf(n=30)
dl_i = l_vektor - l_berechnet_i
A_i = A_ohne_zahlen.subs(zahlen_i).evalf(n=30)
N_i = A_i.T * P * A_i
Qxx_i = N_i.inv()
n_i = A_i.T * P * dl_i
dx = Qxx_i * n_i
x = sp.Matrix(x + dx)
q_norm = sp.sqrt(x[4] ** 2 + x[5] ** 2 + x[6] ** 2 + x[7] ** 2)
x[4] /= q_norm
x[5] /= q_norm
x[6] /= q_norm
x[7] /= q_norm
anzahl_iterationen += 1
print(f"Iteration Nr.{anzahl_iterationen} abgeschlossen")
print(dx.evalf(n=3))
alle_kleiner = True
for i in range(dx.rows):
wert = float(dx[i])
if abs(wert) > schwellenwert:
alle_kleiner = False
if alle_kleiner and alle_kleiner_vorherige_iteration or anzahl_iterationen == 100:
break
alle_kleiner_vorherige_iteration = alle_kleiner
print(l.evalf(n=3))
print(l_berechnet_0.evalf(n=3))
print(f"x = {x.evalf(n=3)}")
# Neuberechnung Zielsystem
zahlen_final = {
dX: float(x[0]),
dY: float(x[1]),
dZ: float(x[2]),
m: float(x[3]),
q0: float(x[4]),
q1: float(x[5]),
q2: float(x[6]),
q3: float(x[7])
}
l_berechnet_final = f.subs(zahlen_final).evalf(n=30)
liste_l_berechnet_final = []
for i in range(anzahl_gemeinsame_punkte):
Xi = l_berechnet_final[3 * i + 0]
Yi = l_berechnet_final[3 * i + 1]
Zi = l_berechnet_final[3 * i + 2]
liste_l_berechnet_final.append(sp.Matrix([Xi, Yi, Zi]))
print("")
print("l_berechnet_final:")
for punktnummer, l_fin in zip(gemeinsame_punktnummern, liste_l_berechnet_final):
print(f"{punktnummer}: {float(l_fin[0]):.3f}, {float(l_fin[1]):.3f}, {float(l_fin[2]):.3f}")
print("Streckendifferenzen:")
streckendifferenzen = [
(punkt_zielsys - l_final).norm()
for punkt_zielsys, l_final in zip(liste_punkte_zielsystem, liste_l_berechnet_final)
]
print([round(float(s), 6) for s in streckendifferenzen])
Schwerpunkt_Zielsystem = sum(liste_punkte_zielsystem, sp.Matrix([0, 0, 0])) / anzahl_gemeinsame_punkte
Schwerpunkt_berechnet = sum(liste_l_berechnet_final, sp.Matrix([0, 0, 0])) / anzahl_gemeinsame_punkte
Schwerpunktsdifferenz = Schwerpunkt_Zielsystem - Schwerpunkt_berechnet
print("\nDifferenz Schwerpunkt (Vektor):")
print(Schwerpunktsdifferenz.evalf(3))
print("Betrag der Schwerpunkt-Differenz:")
print(f"{float(Schwerpunktsdifferenz.norm()):.3f}m")
# ToDo: Abweichungen in Printausgabe ausgeben!

View File

@@ -0,0 +1,141 @@
import sympy as sp
from sympy.algebras.quaternion import Quaternion
#ToDo: Achtung: Die Ergebnisse sind leicht anders, als in den Beispielrechnung von Luhmann (Rundungsfehler bei Luhmann?)
#ToDo: Automatische Ermittlung der Anzahl Nachkommastellen für Test auf Orthonormalität integrieren!
#Beipsiel aus Luhmann S. 76
# Ausgangssystem
p1 = sp.Matrix([110, 100, 110])
p2 = sp.Matrix([150, 280, 100])
p3 = sp.Matrix([300, 300, 120])
p4 = sp.Matrix([170, 100, 100])
p5 = sp.Matrix([200, 200, 140])
# Zielsystem
P1 = sp.Matrix([153.559, 170.747, 150.768])
P2 = sp.Matrix([99.026, 350.313, 354.912])
P3 = sp.Matrix([215.054, 544.420, 319.003])
P4 = sp.Matrix([179.413, 251.030, 115.601])
P5 = sp.Matrix([213.431, 340.349, 253.036])
#1) Näherungswertberechnung
m0 = (P2 - P1).norm() / (p2 - p1).norm()
U = (P2 - P1) / (P2 - P1).norm()
W = (U.cross(P3 - P1)) / (U.cross(P3 - P1)).norm()
V = W.cross(U)
u = (p2 - p1) / (p2 - p1).norm()
w = (u.cross(p3 - p1)) / (u.cross(p3 - p1)).norm()
v = w.cross(u)
R = sp.Matrix.hstack(U, V, W) * sp.Matrix.hstack(u, v, w).T
XS = (P1 + P2 + P3) / 3
xS = (p1 + p2 + p3) / 3
Translation = XS - m0 * R * xS
#print(m0.evalf())
#print(R.evalf())
#print(Translation.evalf())
# 2) Test auf orthonormale Drehmatrix bei 3 Nachkommastellen!
if R.T.applyfunc(lambda x: round(float(x), 3)) == R.inv().applyfunc(lambda x: round(float(x), 3)) and (R.T * R).applyfunc(lambda x: round(float(x), 3)) == sp.eye(3).applyfunc(lambda x: round(float(x), 3)) and ((round(R.det(), 3) == 1.000 or round(R.det(), 3) == -1.000)):
print("R ist Orthonormal!")
else:
print("R ist nicht Orthonormal!")
# Testmatrix R aus Luhmann S. 66
#R = sp.Matrix([
# [0.996911, -0.013541, -0.077361],
# [0.030706, 0.973820, 0.225238],
# [0.072285, -0.226918, 0.971228]
#])
# 3) Quaternionen berechnen
# ToDo: Prüfen, ob Vorzeichen bei q0 richtig ist!
#ToDo: q0 stimmt nicht mit Luhmann überein!
q = Quaternion.from_rotation_matrix(R)
q0_wert = q.a
q1_wert = q.b
q2_wert = q.c
q3_wert = q.d
# 4) Funktionales Modell
liste_Punkte = ["P1", "P2", "P3", "P4", "P5"]
liste_unbekannte = ["dX", "dY", "dZ", "dm", "dq0", "dq1", "dq2", "dq3"]
liste_beobachtungen =[]
for punkt in liste_Punkte:
liste_beobachtungen.append(f"X_{punkt}")
liste_beobachtungen.append(f"Y_{punkt}")
liste_beobachtungen.append(f"Z_{punkt}")
dX, dY, dZ, m, q0, q1, q2, q3, xp1, yp1, zp1, xp2, yp2, zp2, xp3, yp3, zp3, xp4, yp4, zp4, xp5, yp5, zp5 = sp.symbols('dX dY dZ m q0 q1 q2 q3 xp1 yp1 zp1 xp2 yp2 zp2 xp3 yp3 zp3 xp4 yp4 zp4 xp5 yp5 zp5')
#print(Translation[0])
zahlen = {dX: Translation[0], dY: Translation[1], dZ: Translation[2], m: m0, q0: q0_wert, q1: q1_wert, q2: q2_wert, q3: q3_wert, xp1: p1[0], yp1: p1[1], zp1: p1[2], xp2: p2[0], yp2: p2[1], zp2: p2[2], xp3: p3[0], yp3: p3[1], zp3: p3[2], xp4: p4[0], yp4: p4[1], zp4: p4[2], xp5: p5[0], yp5: p5[1], zp5: p5[2]}
#print(zahlen[zp1])
f = sp.Matrix(
[[dX + m * (xp1 * (1 - 2 * (q2**2 + q3**2)) + yp1 * (2 * (q1 * q2 - q0 * q3)) + zp1 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp1 * (2 * (q1 * q2 + q0 * q3)) + yp1 * (1 - 2 * (q1**2 + q3**2)) + zp1 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp1 * (2 * (q1 * q3 - q0 * q2)) + yp1 * (2 * (q0 * q1 + q2 * q3)) + zp1 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp2 * (1 - 2 * (q2**2 + q3**2)) + yp2 * (2 * (q1 * q2 - q0 * q3)) + zp2 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp2 * (2 * (q1 * q2 + q0 * q3)) + yp2 * (1 - 2 * (q1**2 + q3**2)) + zp2 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp2 * (2 * (q1 * q3 - q0 * q2)) + yp2 * (2 * (q0 * q1 + q2 * q3)) + zp2 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp3 * (1 - 2 * (q2**2 + q3**2)) + yp3 * (2 * (q1 * q2 - q0 * q3)) + zp3 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp3 * (2 * (q1 * q2 + q0 * q3)) + yp3 * (1 - 2 * (q1**2 + q3**2)) + zp3 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp3 * (2 * (q1 * q3 - q0 * q2)) + yp3 * (2 * (q0 * q1 + q2 * q3)) + zp3 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp4 * (1 - 2 * (q2**2 + q3**2)) + yp4 * (2 * (q1 * q2 - q0 * q3)) + zp4 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp4 * (2 * (q1 * q2 + q0 * q3)) + yp4 * (1 - 2 * (q1**2 + q3**2)) + zp4 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp4 * (2 * (q1 * q3 - q0 * q2)) + yp4 * (2 * (q0 * q1 + q2 * q3)) + zp4 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp5 * (1 - 2 * (q2**2 + q3**2)) + yp5 * (2 * (q1 * q2 - q0 * q3)) + zp5 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp5 * (2 * (q1 * q2 + q0 * q3)) + yp5 * (1 - 2 * (q1**2 + q3**2)) + zp5 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp5 * (2 * (q1 * q3 - q0 * q2)) + yp5 * (2 * (q0 * q1 + q2 * q3)) + zp5 * (1 - 2 * (q1**2 + q2**2)))],
]
)
A_ohne_zahlen = f.jacobian([dX, dY, dZ, m, q0, q1, q2, q3])
A = A_ohne_zahlen.subs(zahlen)
#print(J)
#print(J_zahlen.evalf(n=3))
# Parameterschätzung
schwellenwert = 1e-3
alle_kleiner = True
x0 = sp.Matrix([zahlen[dX], zahlen[dY], zahlen[dZ], zahlen[m], zahlen[q0], zahlen[q1], zahlen[q2], zahlen[q3]])
P = sp.eye(15)
N = A.T * P * A
l = sp.Matrix([p1[0], p1[1], p1[2], p2[0], p2[1], p2[2], p3[0], p3[1], p3[2], p4[0], p4[1], p4[2], p5[0], p5[1], p5[2]])
# ToDo: Prüfen, ob n mit l oder mit dl!
n = A.T * P * l
Qxx = N.evalf(n=30).inv()
dx = Qxx * n
x = x0 + dx
print(x0.evalf(n=3))
print(dx.evalf(n=3))
print(x.evalf(n=3))
for i in range (dx.rows):
wert = float(dx[i])
if abs(wert) >= schwellenwert:
print("Warnung")
alle_kleiner = False
if alle_kleiner: print("Ausgleichung fertig!")

View File

@@ -0,0 +1,155 @@
import sympy as sp
from sympy.algebras.quaternion import Quaternion
#ToDo: Achtung: Die Ergebnisse sind leicht anders, als in den Beispielrechnung von Luhmann (Rundungsfehler bei Luhmann?)
#ToDo: Automatische Ermittlung der Anzahl Nachkommastellen für Test auf Orthonormalität integrieren!
#Beipsiel aus Luhmann S. 76
# Ausgangssystem
p1 = sp.Matrix([110, 100, 110])
p2 = sp.Matrix([150, 280, 100])
p3 = sp.Matrix([300, 300, 120])
p4 = sp.Matrix([170, 100, 100])
p5 = sp.Matrix([200, 200, 140])
# Zielsystem
P1 = sp.Matrix([153.559, 170.747, 150.768])
P2 = sp.Matrix([99.026, 350.313, 354.912])
P3 = sp.Matrix([215.054, 544.420, 319.003])
P4 = sp.Matrix([179.413, 251.030, 115.601])
P5 = sp.Matrix([213.431, 340.349, 253.036])
#1) Näherungswertberechnung
m0 = (P2 - P1).norm() / (p2 - p1).norm()
U = (P2 - P1) / (P2 - P1).norm()
W = (U.cross(P3 - P1)) / (U.cross(P3 - P1)).norm()
V = W.cross(U)
u = (p2 - p1) / (p2 - p1).norm()
w = (u.cross(p3 - p1)) / (u.cross(p3 - p1)).norm()
v = w.cross(u)
R = sp.Matrix.hstack(U, V, W) * sp.Matrix.hstack(u, v, w).T
XS = (P1 + P2 + P3) / 3
xS = (p1 + p2 + p3) / 3
Translation = XS - m0 * R * xS
#print(m0.evalf())
#print(R.evalf())
#print(Translation.evalf())
# 2) Test auf orthonormale Drehmatrix bei 3 Nachkommastellen!
if R.T.applyfunc(lambda x: round(float(x), 3)) == R.inv().applyfunc(lambda x: round(float(x), 3)) and (R.T * R).applyfunc(lambda x: round(float(x), 3)) == sp.eye(3).applyfunc(lambda x: round(float(x), 3)) and ((round(R.det(), 3) == 1.000 or round(R.det(), 3) == -1.000)):
print("R ist Orthonormal!")
else:
print("R ist nicht Orthonormal!")
# Testmatrix R aus Luhmann S. 66
#R = sp.Matrix([
# [0.996911, -0.013541, -0.077361],
# [0.030706, 0.973820, 0.225238],
# [0.072285, -0.226918, 0.971228]
#])
# 3) Quaternionen berechnen
# ToDo: Prüfen, ob Vorzeichen bei q0 richtig ist!
#ToDo: q0 stimmt nicht mit Luhmann überein!
q = Quaternion.from_rotation_matrix(R)
q0_wert = q.a
q1_wert = q.b
q2_wert = q.c
q3_wert = q.d
# 4) Funktionales Modell
liste_Punkte = ["P1", "P2", "P3", "P4", "P5"]
liste_unbekannte = ["dX", "dY", "dZ", "dm", "dq0", "dq1", "dq2", "dq3"]
liste_beobachtungen =[]
for punkt in liste_Punkte:
liste_beobachtungen.append(f"X_{punkt}")
liste_beobachtungen.append(f"Y_{punkt}")
liste_beobachtungen.append(f"Z_{punkt}")
dX, dY, dZ, m, q0, q1, q2, q3, xp1, yp1, zp1, xp2, yp2, zp2, xp3, yp3, zp3, xp4, yp4, zp4, xp5, yp5, zp5 = sp.symbols('dX dY dZ m q0 q1 q2 q3 xp1 yp1 zp1 xp2 yp2 zp2 xp3 yp3 zp3 xp4 yp4 zp4 xp5 yp5 zp5')
#print(Translation[0])
zahlen = {dX: Translation[0], dY: Translation[1], dZ: Translation[2], m: m0, q0: q0_wert, q1: q1_wert, q2: q2_wert, q3: q3_wert, xp1: p1[0], yp1: p1[1], zp1: p1[2], xp2: p2[0], yp2: p2[1], zp2: p2[2], xp3: p3[0], yp3: p3[1], zp3: p3[2], xp4: p4[0], yp4: p4[1], zp4: p4[2], xp5: p5[0], yp5: p5[1], zp5: p5[2]}
#print(zahlen[zp1])
f = sp.Matrix(
[[dX + m * (xp1 * (1 - 2 * (q2**2 + q3**2)) + yp1 * (2 * (q1 * q2 - q0 * q3)) + zp1 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp1 * (2 * (q1 * q2 + q0 * q3)) + yp1 * (1 - 2 * (q1**2 + q3**2)) + zp1 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp1 * (2 * (q1 * q3 - q0 * q2)) + yp1 * (2 * (q0 * q1 + q2 * q3)) + zp1 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp2 * (1 - 2 * (q2**2 + q3**2)) + yp2 * (2 * (q1 * q2 - q0 * q3)) + zp2 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp2 * (2 * (q1 * q2 + q0 * q3)) + yp2 * (1 - 2 * (q1**2 + q3**2)) + zp2 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp2 * (2 * (q1 * q3 - q0 * q2)) + yp2 * (2 * (q0 * q1 + q2 * q3)) + zp2 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp3 * (1 - 2 * (q2**2 + q3**2)) + yp3 * (2 * (q1 * q2 - q0 * q3)) + zp3 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp3 * (2 * (q1 * q2 + q0 * q3)) + yp3 * (1 - 2 * (q1**2 + q3**2)) + zp3 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp3 * (2 * (q1 * q3 - q0 * q2)) + yp3 * (2 * (q0 * q1 + q2 * q3)) + zp3 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp4 * (1 - 2 * (q2**2 + q3**2)) + yp4 * (2 * (q1 * q2 - q0 * q3)) + zp4 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp4 * (2 * (q1 * q2 + q0 * q3)) + yp4 * (1 - 2 * (q1**2 + q3**2)) + zp4 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp4 * (2 * (q1 * q3 - q0 * q2)) + yp4 * (2 * (q0 * q1 + q2 * q3)) + zp4 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp5 * (1 - 2 * (q2**2 + q3**2)) + yp5 * (2 * (q1 * q2 - q0 * q3)) + zp5 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp5 * (2 * (q1 * q2 + q0 * q3)) + yp5 * (1 - 2 * (q1**2 + q3**2)) + zp5 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp5 * (2 * (q1 * q3 - q0 * q2)) + yp5 * (2 * (q0 * q1 + q2 * q3)) + zp5 * (1 - 2 * (q1**2 + q2**2)))],
]
)
A_ohne_zahlen = f.jacobian([dX, dY, dZ, m, q0, q1, q2, q3])
A = A_ohne_zahlen.subs(zahlen)
#print(J)
#print(J_zahlen.evalf(n=3))
# Parameterschätzung
schwellenwert = 1e-3
alle_kleiner = True
x0 = sp.Matrix([zahlen[dX], zahlen[dY], zahlen[dZ], zahlen[m], zahlen[q0], zahlen[q1], zahlen[q2], zahlen[q3]])
P = sp.eye(15)
N = A.T * P * A
#l = sp.Matrix([p1[0], p1[1], p1[2], p2[0], p2[1], p2[2], p3[0], p3[1], p3[2], p4[0], p4[1], p4[2], p5[0], p5[1], p5[2]])
R_matrix = sp.Matrix([[1 - 2 * (q2_wert**2 + q3_wert**2), 2 * (q1_wert * q2_wert - q0_wert * q3_wert), 2 * (q0_wert * q2_wert + q1_wert * q3_wert)],
[2 * (q1_wert * q2_wert + q0_wert * q3_wert), 1 - 2 * (q1_wert**2 + q3_wert**2), 2 * (q2_wert * q3_wert - q0_wert * q1_wert)],
[2 * (q1_wert * q3_wert - q0_wert * q2_wert), 2 * (q0_wert * q1_wert + q2_wert * q3_wert), 1 - 2 * (q1_wert**2 + q2_wert**2)]])
liste_punkte_ausgangssystem = [p1, p2, p3, p4, p5]
liste_l_berechnet_0 = [Translation + m0 * R_matrix * p for p in liste_punkte_ausgangssystem]
l_berechnet_0 = sp.Matrix.vstack(*liste_l_berechnet_0)
l = sp.Matrix([P1[0] - p1[0], P1[1] - p1[1], P1[2] - p1[2], P2[0] - p2[0], P2[1] - p2[1], P2[2] - p2[2], P3[0] - p3[0], P3[1] - p3[1], P3[2] - p3[2], P4[0] - p4[0], P4[1] - p4[1], P4[2] - p4[2], P5[0] - p5[0], P5[1] - p5[1], P5[2] - p5[2]])
# ToDo: Prüfen, ob n mit l oder mit dl!
n = A.T * P * l
Qxx = N.evalf(n=30).inv()
dx = Qxx * n
x = x0 + dx
print(l.evalf(n=3))
print(l_berechnet_0.evalf(n=3))
#print(x0.evalf(n=3))
#print(dx.evalf(n=3))
#print(x.evalf(n=3))
for i in range (dx.rows):
wert = float(dx[i])
if abs(wert) >= schwellenwert:
#print("Warnung")
alle_kleiner = False
if alle_kleiner: print("Ausgleichung fertig!")

View File

@@ -0,0 +1,6 @@
i = 5
if i % 6 != 0:
print("nein")
else:
print("ja")

View File

@@ -0,0 +1,33 @@
{
"cells": [
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "",
"id": "32199e6b9a0ba953"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,482 @@
import sympy as sp
from sympy.algebras.quaternion import Quaternion
#ToDo: Achtung: Die Ergebnisse sind leicht anders, als in den Beispielrechnung von Luhmann (Rundungsfehler bei Luhmann?)
#ToDo: Automatische Ermittlung der Anzahl Nachkommastellen für Test auf Orthonormalität integrieren!
#Beipsiel aus Luhmann S. 76
# Ausgangssystem
p1 = sp.Matrix([110, 100, 110])
p2 = sp.Matrix([150, 280, 100])
p3 = sp.Matrix([300, 300, 120])
p4 = sp.Matrix([170, 100, 100])
p5 = sp.Matrix([200, 200, 140])
# Zielsystem
P1 = sp.Matrix([153.559, 170.747, 150.768])
P2 = sp.Matrix([99.026, 350.313, 354.912])
P3 = sp.Matrix([215.054, 544.420, 319.003])
P4 = sp.Matrix([179.413, 251.030, 115.601])
P5 = sp.Matrix([213.431, 340.349, 253.036])
#1) Näherungswertberechnung
m0 = (P2 - P1).norm() / (p2 - p1).norm()
U = (P2 - P1) / (P2 - P1).norm()
W = (U.cross(P3 - P1)) / (U.cross(P3 - P1)).norm()
V = W.cross(U)
u = (p2 - p1) / (p2 - p1).norm()
w = (u.cross(p3 - p1)) / (u.cross(p3 - p1)).norm()
v = w.cross(u)
R = sp.Matrix.hstack(U, V, W) * sp.Matrix.hstack(u, v, w).T
XS = (P1 + P2 + P3) / 3
xS = (p1 + p2 + p3) / 3
Translation = XS - m0 * R * xS
#print(m0.evalf())
#print(R.evalf())
#print(Translation.evalf())
# 2) Test auf orthonormale Drehmatrix bei 3 Nachkommastellen!
if R.T.applyfunc(lambda x: round(float(x), 3)) == R.inv().applyfunc(lambda x: round(float(x), 3)) and (R.T * R).applyfunc(lambda x: round(float(x), 3)) == sp.eye(3).applyfunc(lambda x: round(float(x), 3)) and ((round(R.det(), 3) == 1.000 or round(R.det(), 3) == -1.000)):
print("R ist Orthonormal!")
else:
print("R ist nicht Orthonormal!")
# Testmatrix R aus Luhmann S. 66
#R = sp.Matrix([
# [0.996911, -0.013541, -0.077361],
# [0.030706, 0.973820, 0.225238],
# [0.072285, -0.226918, 0.971228]
#])
# 3) Quaternionen berechnen
# ToDo: Prüfen, ob Vorzeichen bei q0 richtig ist!
#ToDo: q0 stimmt nicht mit Luhmann überein!
q = Quaternion.from_rotation_matrix(R)
q0_wert = q.a
q1_wert = q.b
q2_wert = q.c
q3_wert = q.d
# 4) Funktionales Modell
liste_Punkte = ["P1", "P2", "P3", "P4", "P5"]
liste_unbekannte = ["dX", "dY", "dZ", "dm", "dq0", "dq1", "dq2", "dq3"]
liste_beobachtungen =[]
for punkt in liste_Punkte:
liste_beobachtungen.append(f"X_{punkt}")
liste_beobachtungen.append(f"Y_{punkt}")
liste_beobachtungen.append(f"Z_{punkt}")
dX, dY, dZ, m, q0, q1, q2, q3, xp1, yp1, zp1, xp2, yp2, zp2, xp3, yp3, zp3, xp4, yp4, zp4, xp5, yp5, zp5 = sp.symbols('dX dY dZ m q0 q1 q2 q3 xp1 yp1 zp1 xp2 yp2 zp2 xp3 yp3 zp3 xp4 yp4 zp4 xp5 yp5 zp5')
#print(Translation[0])
#print(zahlen[zp1])
f = sp.Matrix(
[[dX + m * (xp1 * (1 - 2 * (q2**2 + q3**2)) + yp1 * (2 * (q1 * q2 - q0 * q3)) + zp1 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp1 * (2 * (q1 * q2 + q0 * q3)) + yp1 * (1 - 2 * (q1**2 + q3**2)) + zp1 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp1 * (2 * (q1 * q3 - q0 * q2)) + yp1 * (2 * (q0 * q1 + q2 * q3)) + zp1 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp2 * (1 - 2 * (q2**2 + q3**2)) + yp2 * (2 * (q1 * q2 - q0 * q3)) + zp2 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp2 * (2 * (q1 * q2 + q0 * q3)) + yp2 * (1 - 2 * (q1**2 + q3**2)) + zp2 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp2 * (2 * (q1 * q3 - q0 * q2)) + yp2 * (2 * (q0 * q1 + q2 * q3)) + zp2 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp3 * (1 - 2 * (q2**2 + q3**2)) + yp3 * (2 * (q1 * q2 - q0 * q3)) + zp3 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp3 * (2 * (q1 * q2 + q0 * q3)) + yp3 * (1 - 2 * (q1**2 + q3**2)) + zp3 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp3 * (2 * (q1 * q3 - q0 * q2)) + yp3 * (2 * (q0 * q1 + q2 * q3)) + zp3 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp4 * (1 - 2 * (q2**2 + q3**2)) + yp4 * (2 * (q1 * q2 - q0 * q3)) + zp4 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp4 * (2 * (q1 * q2 + q0 * q3)) + yp4 * (1 - 2 * (q1**2 + q3**2)) + zp4 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp4 * (2 * (q1 * q3 - q0 * q2)) + yp4 * (2 * (q0 * q1 + q2 * q3)) + zp4 * (1 - 2 * (q1**2 + q2**2)))],
[dX + m * (xp5 * (1 - 2 * (q2**2 + q3**2)) + yp5 * (2 * (q1 * q2 - q0 * q3)) + zp5 * (2 * (q0 * q2 + q1 * q3)))],
[dY + m * (xp5 * (2 * (q1 * q2 + q0 * q3)) + yp5 * (1 - 2 * (q1**2 + q3**2)) + zp5 * (2 * (q2 * q3 - q0 * q1)))],
[dZ + m * (xp5 * (2 * (q1 * q3 - q0 * q2)) + yp5 * (2 * (q0 * q1 + q2 * q3)) + zp5 * (1 - 2 * (q1**2 + q2**2)))],
]
)
A_ohne_zahlen = f.jacobian([dX, dY, dZ, m, q0, q1, q2, q3])
#print(J)
#print(J_zahlen.evalf(n=3))
# Parameterschätzung
schwellenwert = 1e-4
anzahl_iterationen = 0
alle_kleiner_vorherige_iteration = False
P = sp.eye(15)
#l = sp.Matrix([p1[0], p1[1], p1[2], p2[0], p2[1], p2[2], p3[0], p3[1], p3[2], p4[0], p4[1], p4[2], p5[0], p5[1], p5[2]])
liste_punkte_ausgangssystem = [p1, p2, p3, p4, p5]
#l = sp.Matrix([P1[0] - p1[0], P1[1] - p1[1], P1[2] - p1[2], P2[0] - p2[0], P2[1] - p2[1], P2[2] - p2[2], P3[0] - p3[0], P3[1] - p3[1], P3[2] - p3[2], P4[0] - p4[0], P4[1] - p4[1], P4[2] - p4[2], P5[0] - p5[0], P5[1] - p5[1], P5[2] - p5[2]])
l = sp.Matrix([P1[0], P1[1], P1[2], P2[0], P2[1], P2[2], P3[0], P3[1], P3[2], P4[0], P4[1], P4[2], P5[0], P5[1], P5[2]])
# ToDo: Prüfen, ob n mit l oder mit dl!
while True:
if anzahl_iterationen == 0:
zahlen_0 = {dX: float(Translation[0]), dY: float(Translation[1]), dZ: float(Translation[2]), m: float(m0), q0: float(q0_wert), q1: float(q1_wert),
q2: float(q2_wert),
q3: float(q3_wert), xp1: p1[0], yp1: p1[1], zp1: p1[2], xp2: p2[0], yp2: p2[1], zp2: p2[2], xp3: p3[0],
yp3: p3[1], zp3: p3[2], xp4: p4[0], yp4: p4[1], zp4: p4[2], xp5: p5[0], yp5: p5[1], zp5: p5[2]}
x0 = sp.Matrix([zahlen_0[dX], zahlen_0[dY], zahlen_0[dZ], zahlen_0[m], zahlen_0[q0], zahlen_0[q1], zahlen_0[q2], zahlen_0[q3]])
R_matrix_0 = sp.Matrix([[1 - 2 * (q2_wert ** 2 + q3_wert ** 2), 2 * (q1_wert * q2_wert - q0_wert * q3_wert),
2 * (q0_wert * q2_wert + q1_wert * q3_wert)],
[2 * (q1_wert * q2_wert + q0_wert * q3_wert), 1 - 2 * (q1_wert ** 2 + q3_wert ** 2),
2 * (q2_wert * q3_wert - q0_wert * q1_wert)],
[2 * (q1_wert * q3_wert - q0_wert * q2_wert), 2 * (q0_wert * q1_wert + q2_wert * q3_wert),
1 - 2 * (q1_wert ** 2 + q2_wert ** 2)]])
liste_l_berechnet_0 = [Translation + m0 * R_matrix_0 * p for p in liste_punkte_ausgangssystem]
l_berechnet_0 = sp.Matrix.vstack(*liste_l_berechnet_0)
dl_0 = l - l_berechnet_0
A_0 = A_ohne_zahlen.subs(zahlen_0)
N = A_0.T * P * A_0
n_0 = A_0.T * P * dl_0
Qxx_0 = N.evalf(n=30).inv()
dx = Qxx_0 * n_0
x = x0 + dx
x = sp.N(x, 10) # 10 Nachkommastellen
q_norm = sp.sqrt(x[4] ** 2 + x[5] ** 2 + x[6] ** 2 + x[7] ** 2)
x = sp.Matrix(x)
x[4] /= q_norm
x[5] /= q_norm
x[6] /= q_norm
x[7] /= q_norm
anzahl_iterationen += 1
print(f"Iteration Nr.{anzahl_iterationen} abgeschlossen")
print(dx.evalf(n=3))
else:
zahlen_i = {dX: float(x[0]), dY: float(x[1]), dZ: float(x[2]), m: float(x[3]), q0: float(x[4]), q1: float(x[5]),
q2: float(x[6]),
q3: float(x[7]), xp1: p1[0], yp1: p1[1], zp1: p1[2], xp2: p2[0], yp2: p2[1], zp2: p2[2], xp3: p3[0],
yp3: p3[1], zp3: p3[2], xp4: p4[0], yp4: p4[1], zp4: p4[2], xp5: p5[0], yp5: p5[1], zp5: p5[2]}
R_matrix_i = sp.Matrix([[1 - 2 * (zahlen_i[q2] ** 2 + zahlen_i[q3] ** 2), 2 * (zahlen_i[q1] * zahlen_i[q2] - zahlen_i[q0] * zahlen_i[q3]),
2 * (zahlen_i[q0] * zahlen_i[q2] + zahlen_i[q1] * zahlen_i[q3])],
[2 * (zahlen_i[q1] * zahlen_i[q2] + zahlen_i[q0] * zahlen_i[q3]), 1 - 2 * (zahlen_i[q1] ** 2 + zahlen_i[q3] ** 2),
2 * (zahlen_i[q2] * zahlen_i[q3] - zahlen_i[q0] * zahlen_i[q1])],
[2 * (zahlen_i[q1] * zahlen_i[q3] - zahlen_i[q0] * zahlen_i[q2]),
2 * (zahlen_i[q0] * zahlen_i[q1] + zahlen_i[q2] * zahlen_i[q3]),
1 - 2 * (zahlen_i[q1] ** 2 + zahlen_i[q2] ** 2)]])
#print("R_matrix_i")
liste_l_berechnet_i = [sp.Matrix([zahlen_i[dX], zahlen_i[dY], zahlen_i[dZ]]) + zahlen_i[m] * R_matrix_i * p for p in liste_punkte_ausgangssystem]
#print("liste_l_berechnet_i")
l_berechnet_i = sp.Matrix.vstack(*liste_l_berechnet_i)
#print("l_berechnet_i")
dl_i = l - l_berechnet_i
#print("dl_i")
A_i = A_ohne_zahlen.subs(zahlen_i).evalf(n=30)
#print("A_i")
N_i = A_i.T * P * A_i
#print("N_i")
n_i = A_i.T * P * dl_i
# print("n_i")
Qxx_i = N_i.evalf(n=30).inv()
#print("Qxx_i")
n_i = A_i.T * P * dl_i
#print("n_i")
dx = Qxx_i * n_i
#print("dx")
x += dx
x = sp.Matrix(x)
q_norm = sp.sqrt(x[4] ** 2 + x[5] ** 2 + x[6] ** 2 + x[7] ** 2)
x[4] /= q_norm
x[5] /= q_norm
x[6] /= q_norm
x[7] /= q_norm
# print("x")
anzahl_iterationen += 1
print(f"Iteration Nr.{anzahl_iterationen} abgeschlossen")
print(dx.evalf(n=3))
alle_kleiner = True
for i in range(dx.rows):
wert = float(dx[i])
if abs(wert) > schwellenwert:
alle_kleiner = False
if alle_kleiner and alle_kleiner_vorherige_iteration or anzahl_iterationen == 20:
break
alle_kleiner_vorherige_iteration = alle_kleiner
print(l.evalf(n=3))
print(l_berechnet_0.evalf(n=3))
print(f"x = {x.evalf(n=3)}")
#Neuberechnung Zielsystem
zahlen_i = {dX: float(x[0]), dY: float(x[1]), dZ: float(x[2]), m: float(x[3]), q0: float(x[4]), q1: float(x[5]),
q2: float(x[6]),
q3: float(x[7]), xp1: p1[0], yp1: p1[1], zp1: p1[2], xp2: p2[0], yp2: p2[1], zp2: p2[2], xp3: p3[0],
yp3: p3[1], zp3: p3[2], xp4: p4[0], yp4: p4[1], zp4: p4[2], xp5: p5[0], yp5: p5[1], zp5: p5[2]}
# print("zahlen_i")
R_matrix_i = sp.Matrix(
[[1 - 2 * (zahlen_i[q2] ** 2 + zahlen_i[q3] ** 2), 2 * (zahlen_i[q1] * zahlen_i[q2] - zahlen_i[q0] * zahlen_i[q3]),
2 * (zahlen_i[q0] * zahlen_i[q2] + zahlen_i[q1] * zahlen_i[q3])],
[2 * (zahlen_i[q1] * zahlen_i[q2] + zahlen_i[q0] * zahlen_i[q3]), 1 - 2 * (zahlen_i[q1] ** 2 + zahlen_i[q3] ** 2),
2 * (zahlen_i[q2] * zahlen_i[q3] - zahlen_i[q0] * zahlen_i[q1])],
[2 * (zahlen_i[q1] * zahlen_i[q3] - zahlen_i[q0] * zahlen_i[q2]),
2 * (zahlen_i[q0] * zahlen_i[q1] + zahlen_i[q2] * zahlen_i[q3]),
1 - 2 * (zahlen_i[q1] ** 2 + zahlen_i[q2] ** 2)]])
# print("R_matrix_i")
liste_l_berechnet_i = [sp.Matrix([zahlen_i[dX], zahlen_i[dY], zahlen_i[dZ]]) + zahlen_i[m] * R_matrix_i * p for p in
liste_punkte_ausgangssystem]
# print("liste_l_berechnet_i")
l_berechnet_i = sp.Matrix.vstack(*liste_l_berechnet_i)
print("")
print("l_berechnet_final:")
liste_punkte_zielsystem = [P1, P2, P3, P4, P5]
for v in l_berechnet_i:
print(f"{float(v):.3f}")
print("Streckendifferenzen:")
streckendifferenzen = [(P - L).norm() for P, L in zip(liste_punkte_zielsystem, liste_l_berechnet_i)]
print([round(float(s), 6) for s in streckendifferenzen])
Schwerpunkt_Zielsystem = sum(liste_punkte_zielsystem, sp.Matrix([0, 0, 0])) / len(liste_punkte_zielsystem)
Schwerpunkt_berechnet = sum(liste_l_berechnet_i, sp.Matrix([0, 0, 0])) / len(liste_l_berechnet_i)
Schwerpunktsdifferenz = Schwerpunkt_Zielsystem - Schwerpunkt_berechnet
print("\nDifferenz Schwerpunkt (Vektor):")
print(Schwerpunktsdifferenz.evalf(3))
print("Betrag der Schwerpunkt-Differenz:")
print(f"{float(Schwerpunktsdifferenz.norm()):.3f}m")
#ToDo: Abweichungen in Printausgabe ausgeben!
def Helmerttransformation_Euler(self):
db = Datenbank.Datenbankzugriff(self.pfad_datenbank)
dict_ausgangssystem = db.get_koordinaten("naeherung_lh", "Dict")
dict_zielsystem = db.get_koordinaten("naeherung_us", "Dict")
gemeinsame_punktnummern = sorted(set(dict_ausgangssystem.keys()) & set(dict_zielsystem.keys()))
anzahl_gemeinsame_punkte = len(gemeinsame_punktnummern)
liste_punkte_ausgangssystem = [dict_ausgangssystem[i] for i in gemeinsame_punktnummern]
liste_punkte_zielsystem = [dict_zielsystem[i] for i in gemeinsame_punktnummern]
print("Anzahl gemeinsame Punkte:", anzahl_gemeinsame_punkte)
print("\nErste Zielpunkte:")
for pn, P in list(zip(gemeinsame_punktnummern, liste_punkte_zielsystem))[:5]:
print(pn, [float(P[0]), float(P[1]), float(P[2])])
print("\nErste Ausgangspunkte:")
for pn, p in list(zip(gemeinsame_punktnummern, liste_punkte_ausgangssystem))[:5]:
print(pn, [float(p[0]), float(p[1]), float(p[2])])
# --- Näherungswerte (minimal erweitert) ---
p1, p2, p3 = liste_punkte_ausgangssystem[0], liste_punkte_ausgangssystem[1], liste_punkte_ausgangssystem[2]
P1, P2, P3 = liste_punkte_zielsystem[0], liste_punkte_zielsystem[1], liste_punkte_zielsystem[2]
# 1) Näherungswert Maßstab: Mittelwert aus allen Punktpaaren
ratios = []
for i, j in combinations(range(anzahl_gemeinsame_punkte), 2):
dp = (liste_punkte_ausgangssystem[j] - liste_punkte_ausgangssystem[i]).norm()
dP = (liste_punkte_zielsystem[j] - liste_punkte_zielsystem[i]).norm()
dp_f = float(dp)
if dp_f > 0:
ratios.append(float(dP) / dp_f)
m0 = sum(ratios) / len(ratios)
if ratios:
print("min/mean/max:",
min(ratios),
sum(ratios) / len(ratios),
max(ratios))
U = (P2 - P1) / (P2 - P1).norm()
W = (U.cross(P3 - P1)) / (U.cross(P3 - P1)).norm()
V = W.cross(U)
u = (p2 - p1) / (p2 - p1).norm()
w = (u.cross(p3 - p1)) / (u.cross(p3 - p1)).norm()
v = w.cross(u)
R0 = sp.Matrix.hstack(U, V, W) * sp.Matrix.hstack(u, v, w).T
XS = sum(liste_punkte_zielsystem, sp.Matrix([0, 0, 0])) / anzahl_gemeinsame_punkte
xS = sum(liste_punkte_ausgangssystem, sp.Matrix([0, 0, 0])) / anzahl_gemeinsame_punkte
Translation0 = XS - m0 * R0 * xS
# 2) Test auf orthonormale Drehmatrix bei 3 Nachkommastellen!
if R0.T.applyfunc(lambda x: round(float(x), 3)) == R0.inv().applyfunc(lambda x: round(float(x), 3)) \
and (R0.T * R0).applyfunc(lambda x: round(float(x), 3)) == sp.eye(3).applyfunc(lambda x: round(float(x), 3)) \
and ((round(R0.det(), 3) == 1.000 or round(R0.det(), 3) == -1.000)):
print("R ist Orthonormal!")
else:
print("R ist nicht Orthonormal!")
# 3) Euler-Näherungswerte aus R0
e2_0 = sp.asin(R0[2, 0])
# Schutz gegen Division durch 0 wenn cos(e2) ~ 0:
cos_e2_0 = sp.cos(e2_0)
e1_0 = sp.acos(R0[2, 2] / cos_e2_0)
e3_0 = sp.acos(R0[0, 0] / cos_e2_0)
# --- Symbolische Unbekannte (klassische 7 Parameter) ---
dX, dY, dZ, m, e1, e2, e3 = sp.symbols('dX dY dZ m e1 e2 e3')
R_symbolisch = self.R_matrix_aus_euler(e1, e2, e3)
# 4) Funktionales Modell
f_zeilen = []
for punkt in liste_punkte_ausgangssystem:
punkt_vektor = sp.Matrix([punkt[0], punkt[1], punkt[2]])
f_zeile_i = sp.Matrix([dX, dY, dZ]) + m * R_symbolisch * punkt_vektor
f_zeilen.extend(list(f_zeile_i))
f_matrix = sp.Matrix(f_zeilen)
f = f_matrix
A_ohne_zahlen = f_matrix.jacobian([dX, dY, dZ, m, e1, e2, e3])
# Parameterschätzung
schwellenwert = 1e-4
anzahl_iterationen = 0
alle_kleiner_vorherige_iteration = False
l_vektor = sp.Matrix([koord for P in liste_punkte_zielsystem for koord in P])
l = l_vektor
P_mat = sp.eye(3 * anzahl_gemeinsame_punkte)
l_berechnet_0 = None
while True:
if anzahl_iterationen == 0:
zahlen_0 = {
dX: float(Translation0[0]),
dY: float(Translation0[1]),
dZ: float(Translation0[2]),
m: float(m0),
e1: float(e1_0),
e2: float(e2_0),
e3: float(e3_0)
}
x0 = sp.Matrix([zahlen_0[dX], zahlen_0[dY], zahlen_0[dZ],
zahlen_0[m], zahlen_0[e1], zahlen_0[e2], zahlen_0[e3]])
l_berechnet_0 = f.subs(zahlen_0).evalf(n=30)
dl_0 = l_vektor - l_berechnet_0
A_0 = A_ohne_zahlen.subs(zahlen_0).evalf(n=30)
N = A_0.T * P_mat * A_0
n_0 = A_0.T * P_mat * dl_0
Qxx_0 = N.inv()
dx = Qxx_0 * n_0
x = x0 + dx
x = sp.N(x, 30)
anzahl_iterationen += 1
print(f"Iteration Nr.{anzahl_iterationen} abgeschlossen")
print(dx.evalf(n=3))
else:
zahlen_i = {
dX: float(x[0]),
dY: float(x[1]),
dZ: float(x[2]),
m: float(x[3]),
e1: float(x[4]),
e2: float(x[5]),
e3: float(x[6])
}
l_berechnet_i = f.subs(zahlen_i).evalf(n=30)
dl_i = l_vektor - l_berechnet_i
A_i = A_ohne_zahlen.subs(zahlen_i).evalf(n=30)
N_i = A_i.T * P_mat * A_i
Qxx_i = N_i.inv()
n_i = A_i.T * P_mat * dl_i
dx = Qxx_i * n_i
x = sp.Matrix(x + dx)
anzahl_iterationen += 1
print(f"Iteration Nr.{anzahl_iterationen} abgeschlossen")
print(dx.evalf(n=3))
alle_kleiner = True
for i in range(dx.rows):
wert = float(dx[i])
if abs(wert) > schwellenwert:
alle_kleiner = False
if (alle_kleiner and alle_kleiner_vorherige_iteration) or anzahl_iterationen == 100:
break
alle_kleiner_vorherige_iteration = alle_kleiner
print(l.evalf(n=3))
print(l_berechnet_0.evalf(n=3))
print(f"x = {x.evalf(n=3)}")
# --- Neuberechnung Zielsystem ---
zahlen_final = {
dX: float(x[0]),
dY: float(x[1]),
dZ: float(x[2]),
m: float(x[3]),
e1: float(x[4]),
e2: float(x[5]),
e3: float(x[6])
}
l_berechnet_final = f.subs(zahlen_final).evalf(n=30)
liste_l_berechnet_final = []
for i in range(anzahl_gemeinsame_punkte):
Xi = l_berechnet_final[3 * i + 0]
Yi = l_berechnet_final[3 * i + 1]
Zi = l_berechnet_final[3 * i + 2]
liste_l_berechnet_final.append(sp.Matrix([Xi, Yi, Zi]))
print("")
print("l_berechnet_final:")
for punktnummer, l_fin in zip(gemeinsame_punktnummern, liste_l_berechnet_final):
print(f"{punktnummer}: {float(l_fin[0]):.3f}, {float(l_fin[1]):.3f}, {float(l_fin[2]):.3f}")
print("Streckendifferenzen:")
streckendifferenzen = [
(punkt_zielsys - l_final).norm()
for punkt_zielsys, l_final in zip(liste_punkte_zielsystem, liste_l_berechnet_final)
]
print([round(float(s), 6) for s in streckendifferenzen])
Schwerpunkt_Zielsystem = sum(liste_punkte_zielsystem, sp.Matrix([0, 0, 0])) / anzahl_gemeinsame_punkte
Schwerpunkt_berechnet = sum(liste_l_berechnet_final, sp.Matrix([0, 0, 0])) / anzahl_gemeinsame_punkte
Schwerpunktsdifferenz = Schwerpunkt_Zielsystem - Schwerpunkt_berechnet
print("\nDifferenz Schwerpunkt (Vektor):")
print(Schwerpunktsdifferenz.evalf(3))
print("Betrag der Schwerpunkt-Differenz:")
print(f"{float(Schwerpunktsdifferenz.norm()):.3f}m")

View File

@@ -0,0 +1,53 @@
# Transformation ITRF2020 --> ETRF89/DREF91 Realisierung 2025
import sympy as sp
from Berechnungen import Einheitenumrechnung
# Helmetert Paramteter zur Referenzepoche t0
t0 = 2015.0
T1 = Einheitenumrechnung.mm_to_m(41.1393)
T2 = Einheitenumrechnung.mm_to_m(51.9830)
T3 = Einheitenumrechnung.mm_to_m(-101.1455)
D = Einheitenumrechnung.ppb(7.8918)
R1 = Einheitenumrechnung.mas_to_rad(0.8878)
R2 = Einheitenumrechnung.mas_to_rad(12.7748)
R3 = Einheitenumrechnung.mas_to_rad(-22.2616)
dotT1 = Einheitenumrechnung.mm_to_m(0)
dotT2 = Einheitenumrechnung.mm_to_m(0)
dotT3 = Einheitenumrechnung.mm_to_m(0)
dotD = 0
dotR1 = Einheitenumrechnung.mas_to_rad(0.086)
dotR2 = Einheitenumrechnung.mas_to_rad(0.519)
dotR3 = Einheitenumrechnung.mas_to_rad(-0.753)
# Testdatensatz der AdV
tc = 2021.48
BRMG = sp.Matrix([4245557.0412, 568958.1394, 4710200.0645])
RANT = sp.Matrix([3645376.2264, 531202.1700, 5189297.0638])
TIT2 = sp.Matrix([3993787.0533, 450204.1794, 4936131.8526])
LDB2 = sp.Matrix([3798344.6978, 955553.3244, 5017221.8937])
FFMJ = sp.Matrix([4053455.6399, 617729.9375, 4869395.8850])
# 1) Epochendifferenz
dt = tc - t0
# 2) Parameter von Epoche t0 auf tc umrechnen
T1_c = T1 + dotT1 * dt
T2_c = T2 + dotT2 * dt
T3_c = T3 + dotT3 * dt
R1_c = R1 + dotR1 * dt
R2_c = R2 + dotR2 * dt
R3_c = R3 + dotR3 * dt
D_c = D + dotD * dt
# 3) Matrizen aufstellen
R_Matrix = sp.Matrix([[D_c, -R3_c, R2_c], [R3_c, D_c, -R1_c], [-R2_c, R1_c, D_c]])
T_Vektor = sp.Matrix([T1_c, T2_c, T3_c])
# 4) Helmerttransformation
print(f"BRMG = {(BRMG + T_Vektor + R_Matrix * BRMG).evalf()}")
print(f"RANT = {(RANT + T_Vektor + R_Matrix * RANT).evalf()}")
print(f"TIT2 = {(TIT2 + T_Vektor + R_Matrix * TIT2).evalf()}")
print(f"LDB2 = {(LDB2 + T_Vektor + R_Matrix * LDB2).evalf()}")
print(f"FFMJ = {(FFMJ + T_Vektor + R_Matrix * FFMJ).evalf()}")

View File

@@ -0,0 +1,239 @@
{
"cells": [
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-14T13:15:38.527230Z",
"start_time": "2025-11-14T13:15:38.518151Z"
}
},
"cell_type": "code",
"source": [
"import csv\n",
"\n",
"from prompt_toolkit.utils import to_float\n"
],
"id": "9317c939b4662e39",
"outputs": [],
"execution_count": 1
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-10-26T17:16:07.067056Z",
"start_time": "2025-10-26T17:16:07.064166Z"
}
},
"cell_type": "code",
"source": [
"# ToDo: Materialized View für Mittel aus mehreren Vollsätzen verschiedener Standpunkte erstellen und nach dem importieren der Tachymeterdaten aaktualisieren (Dazu klären: Wo werden die Gewichte der einzelnen Beobachtungen gespeichert?)\n",
"\n",
"# Hier werden die Nutzereingaben vorgenommen:\n",
"pfad_datenbank = r\"C:\\Users\\fabia\\OneDrive\\Jade HS\\Master\\MGW2\\Masterprojekt_allgemein\\Masterprojekt\\Programmierung\\Campusnetz\\Campusnetz.db\""
],
"id": "33969d88a569b138",
"outputs": [],
"execution_count": 2
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-10-26T17:16:07.118676Z",
"start_time": "2025-10-26T17:16:07.073244Z"
}
},
"cell_type": "code",
"source": [
"# Es wird geprüft, ob die .db-Datei bereits vorhanden ist. Wenn dies nicht der Fall ist, wird die Datenbank mitsamt aller Tabellen angelegt.\n",
"Datenbank.Datenbank_anlegen(pfad_datenbank)\n",
"pfad = r\"C:\\Users\\fabia\\OneDrive\\Jade HS\\Master\\MGW2\\Masterprojekt_allgemein\\Masterprojekt\\Übungsnetz\\Tachymeterdaten\\Masterprobe_2.csv\""
],
"id": "c55d4c3fccfa7902",
"outputs": [
{
"data": {
"text/plain": [
"<Datenbank.Datenbank_anlegen at 0x1472dd0b8c0>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 3
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-10-26T17:16:07.199262Z",
"start_time": "2025-10-26T17:16:07.196785Z"
}
},
"cell_type": "code",
"source": [
"# ToDo: Dateipfad bereits vorhanden? --> Abbruch import\n",
"# ToDo: Rundungsfehler überarbeiten!\n",
"# ToDo: Print ausgabe Anzahl importierte Punkte\n",
"# ToDo: Ggf. Ausgabe Rohdaten in Tabellenform (Berechnungen nachvollziehen)\n",
"\n",
"import sqlite3\n",
"\n",
"liste_netzpunkte = []\n",
"liste_netzpunkte_neu = []\n",
"liste_netzpunkte_vorhanden = []\n",
"liste_zeilennummern_Orientierung = []\n",
"liste_standpunkte = []\n",
"liste_beobachtungen = []\n",
"\n",
"with open (pfad, newline='', encoding='utf-8') as csvfile:\n",
" r = csv.reader(csvfile, delimiter=';')\n",
" zeilennummer = 0\n",
" for row in r:\n",
" zeilennummer += 1\n",
" if zeilennummer < 4:\n",
" pass\n",
" else:\n",
" if row[0] != \"Orientierung\":\n",
" liste_netzpunkte.append(row[0].strip())\n",
" else:\n",
" liste_zeilennummern_Orientierung.append(zeilennummer-1)\n",
" liste_standpunkte.append(zeilennummer-1)\n",
" liste_zeilennummern_Orientierung.append(zeilennummer)\n",
" #print(row)\n",
"\n",
"\n",
"liste_netzpunkte = list(set(liste_netzpunkte))\n",
"\n",
"con = sqlite3.connect(pfad_datenbank)\n",
"cursor = con.cursor()\n",
"cursor.execute(\"\"\"SELECT punktnummer FROM Netzpunkte\"\"\")\n",
"liste_netzpunkte_in_db = {row[0] for row in cursor.fetchall()}\n",
"\n",
"liste_netzpunkte_neu = [np for np in liste_netzpunkte if np not in liste_netzpunkte_in_db]\n",
"liste_netzpunkte_vorhanden = [np for np in liste_netzpunkte if np in liste_netzpunkte_in_db]\n",
"\n",
"for np_neu in liste_netzpunkte_neu:\n",
" cursor.execute(\"INSERT INTO Netzpunkte (punktnummer) VALUES (?)\", (np_neu,))\n",
"\n",
"with open (pfad, newline='', encoding='utf-8') as csvfile:\n",
" r = csv.reader(csvfile, delimiter=';')\n",
" standpunktsnummer = 0\n",
" for nummer, row in enumerate(r, start=1):\n",
" if nummer < 4:\n",
" pass\n",
" if nummer in liste_zeilennummern_Orientierung:\n",
" if row[0] != \"Orientierung\":\n",
" punktnummer = row[0].strip()\n",
" else:\n",
" standpunktsnummer += 1\n",
" cursor.execute(\"INSERT INTO Standpunkte_Tachymeter (punktnummer, orientierunghz, orientierungv, dateipfad, standpunktsnummer) VALUES (?, ?, ?, ?, ?)\", (punktnummer, row[1], row[2], pfad, standpunktsnummer))\n",
"\n",
"with open (pfad, newline='', encoding='utf-8') as csvfile:\n",
" r = csv.reader(csvfile, delimiter=';')\n",
" rows = list(r)\n",
"\n",
" for index, row in enumerate(liste_standpunkte):\n",
" zeile_punktnummer = row - 1\n",
" punktnummer = rows[zeile_punktnummer][0].strip()\n",
" zeile_eins = zeile_punktnummer + 2\n",
" if index + 1 < len(liste_standpunkte):\n",
" zeile_zwei = liste_standpunkte[index + 1]\n",
" else:\n",
" zeile_zwei = len(rows)+1\n",
"\n",
" for i in range (zeile_eins, zeile_zwei-1):\n",
" liste_beobachtungen.append([punktnummer] + rows[i])\n",
"\n",
" standpunktsnummer = 0\n",
" standpunkt_alt = None\n",
"while len(liste_beobachtungen) > 0:\n",
" standpunkt1 = liste_beobachtungen[0][0]\n",
" zielpunkt1 = liste_beobachtungen[0][1]\n",
" horizonalwinkel1 = to_float(liste_beobachtungen[0][2].replace(',', '.'))\n",
" vertikalwinkel1 = to_float(liste_beobachtungen[0][3].replace(',', '.'))\n",
" distanz1 = to_float(liste_beobachtungen[0][4].replace(',', '.'))\n",
" liste_beobachtungen.pop(0)\n",
"\n",
" if standpunkt_alt != standpunkt1:\n",
" standpunktsnummer += 1\n",
"\n",
" standpunkt_alt = standpunkt1\n",
"\n",
" standpunktsid = cursor.execute(\"SELECT spID FROM Standpunkte_Tachymeter WHERE punktnummer = ? AND dateipfad = ? AND standpunktsnummer = ?\", (standpunkt1, pfad, standpunktsnummer)).fetchall()[0][0]\n",
"\n",
" index_beobachtung2 = None\n",
" for index in range(len(liste_beobachtungen)):\n",
" beobachtung = liste_beobachtungen[index]\n",
" if beobachtung[0] == standpunkt1 and beobachtung[1] == zielpunkt1:\n",
" index_beobachtung2 = index\n",
" break\n",
" if index_beobachtung2 is None:\n",
" print(f\"Zweite Lage für Standpunkt: {standpunkt1}, Zielpunkt: {zielpunkt1} wurde nicht gefund!\")\n",
"\n",
" standpunkt2 = liste_beobachtungen[index_beobachtung2][0]\n",
" zielpunkt2 = liste_beobachtungen[index_beobachtung2][1]\n",
" horizonalwinkel2 = to_float(liste_beobachtungen[index_beobachtung2][2].replace(',', '.'))\n",
" vertikalwinkel2 = to_float(liste_beobachtungen[index_beobachtung2][3].replace(',', '.'))\n",
" distanz2 = to_float(liste_beobachtungen[index_beobachtung2][4].replace(',', '.'))\n",
"\n",
" if horizonalwinkel1 > horizonalwinkel2:\n",
" horizontalwinkel_vollsatz = (horizonalwinkel1 + horizonalwinkel2 + 200) / 2\n",
" else:\n",
" horizontalwinkel_vollsatz = (horizonalwinkel1 + horizonalwinkel2) / 2\n",
"\n",
" if vertikalwinkel1 < vertikalwinkel2:\n",
" vertikalwinkel_satzmittel = (400 + (vertikalwinkel1 - vertikalwinkel2)) / 2\n",
" else:\n",
" vertikalwinkel_satzmittel = (400 + (vertikalwinkel2 - vertikalwinkel1)) / 2\n",
"\n",
" distanz_satzmittel = (distanz1 + distanz2) / 2\n",
"\n",
" print(f\"spid: {standpunktsid}, standpunktsnummer: {standpunktsnummer},standpunkt1: {standpunkt1}, standpunkt2: {standpunkt2}, zielpunkt1: {zielpunkt1}, zielpunkt2: {zielpunkt2}, horizonalwinkel1: {horizonalwinkel1}, horizonalwinkel2: {horizonalwinkel2}, horizontalwinkel_vollsatz: {horizontalwinkel_vollsatz},vertikalwinkel1: {vertikalwinkel1}, vertikalwinkel2: {vertikalwinkel2}, vertikalwinkel_vollsatz: {vertikalwinkel_satzmittel},distanz1: {distanz1}, distanz2: {distanz2}, distanz_satzmittel: {distanz_satzmittel}\")\n",
"\n",
" liste_beobachtungen.pop(index_beobachtung2)\n",
"\n",
" cursor.execute(\"INSERT INTO Beobachtungen_Tachymeter (spID, punktnummer, hz, v, distanz) VALUES (?, ?, ?, ?, ?)\", (standpunktsid, standpunkt1, horizontalwinkel_vollsatz, vertikalwinkel_satzmittel, distanz_satzmittel))\n",
"\n",
" #print(row)\n",
" #print(len(liste_standpunkte))\n",
" #print(len(list(r)))\n",
"\n",
"\n",
"con.commit()\n",
"con.close()\n",
"\n",
"\n",
"print(liste_beobachtungen)\n",
"print(f\"Es wurden {len(liste_netzpunkte_neu)} neue Punkte importiert. Dies sind: {', '.join(map(str, liste_netzpunkte_neu))}\")\n",
"print(f\"Es sind bereits {len(liste_netzpunkte_vorhanden)} Punkte im Netz enthalten. Dies sind: {', '.join(map(str, liste_netzpunkte_vorhanden))}\")\n",
"# ToDo: Näherungswerte für Koordinaten aus Tychymetermessungen berechnen\n",
"# ToDo: Wenn GNSS-Daten vorliegen: Koordinaten von GNSS verwenden!"
],
"id": "d200a8b43e3646c",
"outputs": [],
"execution_count": null
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}