Umrechnungs-Test, Tabellen

This commit is contained in:
2026-01-18 22:29:29 +01:00
parent 07212dcc97
commit aa7175c3c4
5 changed files with 5539 additions and 97 deletions

View File

@@ -5,6 +5,7 @@ import jacobian_Ligas
import matplotlib.pyplot as plt
from typing import Tuple
from numpy.typing import NDArray
import math
class EllipsoidBiaxial:
@@ -199,7 +200,10 @@ class EllipsoidTriaxial:
c0 = (self.ax ** 2 * self.ay ** 2 + self.ax ** 2 * self.b ** 2 + self.ay ** 2 * self.b ** 2 -
(self.ay ** 2 + self.b ** 2) * x ** 2 - (self.ax ** 2 + self.b ** 2) * y ** 2 - (
self.ax ** 2 + self.ay ** 2) * z ** 2)
t2 = (-c1 + sqrt(c1 ** 2 - 4 * c0)) / 2
if c1 ** 2 - 4 * c0 < 0:
t2 = np.nan
else:
t2 = (-c1 + sqrt(c1 ** 2 - 4 * c0)) / 2
if t2 == 0:
t2 = 1e-18
t1 = c0 / t2
@@ -316,12 +320,49 @@ class EllipsoidTriaxial:
Z = self.b * sin(beta) * sqrt(k**2 + k_**2 * sin(lamb)**2)
return np.array([X, Y, Z])
def cart2ell(self, point: NDArray, eps: float = 1e-12, maxI: int = 100) -> Tuple[float, float]:
def cart2ell_yFake(self, point: NDArray, start_delta) -> Tuple[float, float]:
"""
:param point:
:return:
"""
x, y, z = point
delta_y = 1e-4
best_delta = np.inf
while True:
try:
y1 = y - delta_y
beta1, lamb1 = self.cart2ell(np.array([x, y1, z]), noFake=True)
point1 = self.ell2cart(beta1, lamb1)
y2 = y + delta_y
beta2, lamb2 = self.cart2ell(np.array([x, y2, z]), noFake=True)
point2 = self.ell2cart(beta2, lamb2)
pointM = (point1 + point2) / 2
actual_delta = np.linalg.norm(point - pointM)
except:
actual_delta = np.inf
if actual_delta < best_delta:
best_delta = actual_delta
delta_y /= 10
else:
delta_y *= 10
y1 = y - delta_y
beta1, lamb1 = self.cart2ell(np.array([x, y1, z]), noFake=True)
return beta1, lamb1
def cart2ell(self, point: NDArray, eps: float = 1e-12, maxI: int = 100, noFake: bool = False) -> Tuple[float, float]:
"""
Panou, Korakitis 2019 3f. (num)
:param point: Punkt in kartesischen Koordinaten
:param eps: zu erreichende Genauigkeit
:param maxI: maximale Anzahl Iterationen
:param noFake:
:return: elliptische Breite und Länge [rad]
"""
x, y, z = point
@@ -329,70 +370,48 @@ class EllipsoidTriaxial:
delta_ell = np.array([np.inf, np.inf]).T
tiny = 1e-30
i = 0
while np.linalg.norm(delta_ell) > eps and i < maxI:
if abs(y) < eps:
delta_y = 1e-4
best_delta = np.inf
while True:
try:
y1 = y - delta_y
beta1, lamb1 = self.cart2ell(np.array([x, y1, z]))
point1 = self.ell2cart(beta1, lamb1)
try:
i = 0
while np.linalg.norm(delta_ell) > eps and i < maxI:
x0, y0, z0 = self.ell2cart(beta, lamb)
delta_l = np.array([x-x0, y-y0, z-z0]).T
y2 = y + delta_y
beta2, lamb2 = self.cart2ell(np.array([x, y2, z]))
point2 = self.ell2cart(beta2, lamb2)
B = max(self.Ex ** 2 * cos(beta) ** 2 + self.Ee ** 2 * sin(beta) ** 2, tiny)
L = max(self.Ex ** 2 - self.Ee ** 2 * cos(lamb) ** 2, tiny)
pointM = (point1 + point2) / 2
J = np.array([[(-self.ax * self.Ey ** 2) / (2 * self.Ex) * sin(2 * beta) / sqrt(B) * cos(lamb),
-self.ax / self.Ex * sqrt(B) * sin(lamb)],
[-self.ay * sin(beta) * sin(lamb),
self.ay * cos(beta) * cos(lamb)],
[self.b / self.Ex * cos(beta) * sqrt(L),
(self.b * self.Ee ** 2) / (2 * self.Ex) * sin(beta) * sin(2 * lamb) / sqrt(L)]])
actual_delta = np.linalg.norm(point-pointM)
except:
actual_delta = np.inf
N = J.T @ J
det = N[0, 0] * N[1, 1] - N[0, 1] * N[1, 0]
N_inv = 1 / det * np.array([[N[1, 1], -N[0, 1]], [-N[1, 0], N[0, 0]]])
delta_ell = N_inv @ J.T @ delta_l
# delta_ell, *_ = np.linalg.lstsq(J, delta_l, rcond=None)
if actual_delta < best_delta:
best_delta = actual_delta
delta_y /= 10
else:
delta_y *= 10
beta += delta_ell[0]
lamb += delta_ell[1]
i += 1
y1 = y - delta_y
beta1, lamb1 = self.cart2ell(np.array([x, y1, z]))
if i == maxI:
raise Exception("Umrechnung ist nicht konvergiert")
return beta1, lamb1
point_n = self.ell2cart(beta, lamb)
delta_r = np.linalg.norm(point - point_n, axis=-1)
if delta_r > 1e-6:
raise Exception("Fehler in der Umrechnung cart2ell")
x0, y0, z0 = self.ell2cart(beta, lamb)
delta_l = np.array([x-x0, y-y0, z-z0]).T
return beta, lamb
B = max(self.Ex ** 2 * cos(beta) ** 2 + self.Ee ** 2 * sin(beta) ** 2, tiny)
L = max(self.Ex ** 2 - self.Ee ** 2 * cos(lamb) ** 2, tiny)
J = np.array([[(-self.ax * self.Ey ** 2) / (2 * self.Ex) * sin(2 * beta) / sqrt(B) * cos(lamb),
-self.ax / self.Ex * sqrt(B) * sin(lamb)],
[-self.ay * sin(beta) * sin(lamb),
self.ay * cos(beta) * cos(lamb)],
[self.b / self.Ex * cos(beta) * sqrt(L),
(self.b * self.Ee ** 2) / (2 * self.Ex) * sin(beta) * sin(2 * lamb) / sqrt(L)]])
N = J.T @ J
det = N[0, 0] * N[1, 1] - N[0, 1] * N[1, 0]
N_inv = 1 / det * np.array([[N[1, 1], -N[0, 1]], [-N[1, 0], N[0, 0]]])
delta_ell = N_inv @ J.T @ delta_l
beta += delta_ell[0]
lamb += delta_ell[1]
i += 1
if i == maxI:
raise Exception("Umrechnung ist nicht konvergiert")
point_n = self.ell2cart(beta, lamb)
delta_r = np.linalg.norm(point - point_n, axis=-1)
if delta_r > 1e-3:
raise Exception("Fehler in der Umrechnung cart2ell")
return beta, lamb
except Exception as e:
delta_y = 10 ** math.floor(math.log10(abs(self.ay/1000)))
if abs(y) < delta_y and not noFake:
return self.cart2ell_yFake(point, delta_y)
else:
raise e
def cart2ell_panou(self, point: NDArray) -> Tuple[float, float]:
"""
@@ -548,18 +567,28 @@ class EllipsoidTriaxial:
pE = pEi
i += 1
phi = arctan((1-self.ee**2) / (1-self.ex**2) * pE[2] / sqrt((1-self.ee**2)**2 * pE[0]**2 + pE[1]**2))
lamb = arctan(1/(1-self.ee**2) * pE[1]/pE[0])
h = np.sign(zG - pE[2]) * np.sign(pE[2]) * sqrt((pE[0] - xG) ** 2 + (pE[1] - yG) ** 2 + (pE[2] - zG) ** 2)
if i == maxIter and loa > maxLoa:
act_mode = int(mode[-1])
new_mode = 3 if act_mode == 1 else act_mode - 1
phi, lamb, h = self.cart2geod(point, f"ligas{new_mode}", maxIter, maxLoa)
if xG < 0 and yG < 0:
lamb = -pi + lamb
else:
phi = arctan((1-self.ee**2) / (1-self.ex**2) * pE[2] / sqrt((1-self.ee**2)**2 * pE[0]**2 + pE[1]**2))
lamb = arctan(1/(1-self.ee**2) * pE[1]/pE[0])
h = np.sign(zG - pE[2]) * np.sign(pE[2]) * sqrt((pE[0] - xG) ** 2 + (pE[1] - yG) ** 2 + (pE[2] - zG) ** 2)
if h < -self.ax:
act_mode = int(mode[-1])
new_mode = 3 if act_mode == 1 else act_mode - 1
phi, lamb, h = self.cart2geod(point, f"ligas{new_mode}", maxIter, maxLoa)
else:
if xG < 0 and yG < 0:
lamb = -pi + lamb
elif xG < 0:
lamb = pi + lamb
elif xG < 0:
lamb = pi + lamb
if abs(zG) < eps:
phi = 0
if abs(zG) < eps:
phi = 0
return phi, lamb, h