2. 3D-vektor- und matrix- klasen und funktionen¶
2.1. Module mrmath.vecmat3d¶
Klassen für dreidimensionale Vektoren und 3*3-Matrizen.
Module author: Michael Rippstein <info@comlab.ch>
Idea and parts of the source from [Montenbruck2004a].
For the classes Vec3D and Mat3D the following operation are definde.
Funktion |
Arg_1 (a) |
Arg_2 (b) |
Wert (c) |
Notation |
Bedeutung |
|---|---|---|---|---|---|
- |
Vec3D |
Vec3D |
\[c = -a\]
|
Unäres Minus |
|
Mat3D |
Mat3D |
\[C = -A\]
|
|||
- |
Vec3D |
Vec3D |
Vec3D |
\[c = a - b\]
|
Vektor-Subtraktion |
Mat3D |
Mat3D |
Mat3D |
\[C = A - B\]
|
Matrix-Subtraktion |
|
+ |
Vec3D |
Vec3D |
Vec3D |
\[c = a + b\]
|
Vektor-Addition |
Mat3D |
Mat3D |
Mat3D |
\[C = A + B\]
|
Matrix-Addition |
|
* |
int |
Vec3D |
Vec3D |
\[c = ab\]
|
Skalar-Multiplikation |
float |
Vec3D |
Vec3D |
\[c = ab\]
|
||
Vec3D |
int |
Vec3D |
\[c = ab\]
|
||
Vec3D |
float |
Vec3D |
\[c = ab\]
|
||
int |
Mat3D |
Mat3D |
\[C = aB\]
|
||
float |
Mat3D |
Mat3D |
\[C = aB\]
|
||
Mat3D |
int |
Mat3D |
\[C = Ab\]
|
||
Mat3D |
float |
Mat3D |
\[C = Ab\]
|
||
* |
Mat3D |
Vec3D |
Vec3D |
\[c = Ab\]
|
Matrix/Vektor-Multiplikation |
/ |
Vec3D |
int |
Vec3D |
\[c = a/b\]
|
Skalar-Division |
Vec3D |
float |
Vec3D |
\[c = a/b\]
|
||
Mat3D |
int |
Mat3D |
\[C = A/b\]
|
||
Mat3D |
float |
Mat3D |
\[C = A/b\]
|
||
abs |
Vec3D |
float |
\[c = |a|\]
|
||
dot |
Vec3D |
Vec3D |
float |
\[c = ab\]
|
Skalarprodukt |
cross @ |
Vec3D |
Vec3D |
Vec3D |
\[c = a × b\]
|
Vektorprodukt, Kreuzprodukt |
tranp |
Mat3D |
Mat3D |
\[C = A^T\]
|
Transponierte |
|
einmat |
Mat3D |
Einheitsmatrix |
|||
rotmatx |
float |
Mat3D |
Elementare Drehmatrix |
||
rotmaty |
float |
Mat3D |
|||
rotmatz |
float |
Mat3D |
|||
== |
Vec3D |
Vec3D |
bool |
2.1.1. Bedeutung der Winkel bei den Kugelkoordinaten¶
Todo
Korekte winkel bezeichungen im den bilder!
References
- Montenbruck2004a
Montenbruck, Oliver; Pfleger, Thomas: “Astronomie mit dem Personal Computer”; 4. Auflage; Springer-Verlag; Berlin, Heidelberg 2004
2.1.2. Class Vec3D¶
- class Vec3D(arg=None, **kwargs)[source]¶
Bases:
objectDreidimensionaler Vector.
Der Aufruf ohne die angabe von Parameter initialisiert einen Null-Vector.
null_vector = Vec3D()
- Parameters
- Keyword Arguments
r (az, elev,) –
Polarkoordinaten
Vec3D(theta=, phi=, r=)
elev (az,) –
Polarkoordinaten
Vec3D(az=, elev=)
r –
Polarkoordinaten
Vec3D(az=, elev=, r=)
- Raises
- Return type
None
Examples
>>> nullvector = Vec3D() >>> print(nullvector) Vec3D([0, 0, 0]) >>> print(nullvector.xyz) [0, 0, 0] >>> repr(nullvector.array) 'array([[0],\n [0],\n [0]])' >>> print("x: {}, y: {}, z: {}".format(nullvector.x, nullvector.y, nullvector.z)) x: 0, y: 0, z: 0 >>> print("phi: {}, theta: {}, r: {}".format(nullvector.phi, ... nullvector.theta, ... nullvector.r)) phi: 0, theta: 0, r: 0 >>> print(Vec3D([1, 2, 3])) Vec3D([1, 2, 3]) >>> print(Vec3D([1.0, 2.0, 3.0])) Vec3D([1.0, 2.0, 3.0]) >>> vector = Vec3D() >>> vector.x = 9.9 >>> vector.y = 5 >>> vector.z = 1.1 >>> print(vector) Vec3D([9.9, 5, 1.1]) >>> polar = Vec3D(theta=math.pi/2, phi=math.pi/2, r=1) >>> '{:.3f}, {:.3f}, {:.3f}'.format(polar.x, polar.y, polar.z) '0.000, 0.000, 1.000' >>> vector.x = 'text' Traceback (most recent call last): ... TypeError: unsupported type for setter: '<class 'str'>'
- __abs__()[source]¶
Betrag (Radius).
- Returns
Betrag des Vektors
- Return type
Examples
>>> vector = Vec3D([1, 0, 0]) >>> print('{:.4f}'.format(abs(vector))) 1.0000 >>> vector = Vec3D([1, 1, 0]) >>> print('{:.4f}'.format(abs(vector))) 1.4142 >>> vector = Vec3D([1, 0, 1]) >>> print('{:.4f}'.format(abs(vector))) 1.4142
- __add__(other)[source]¶
Addition:
self + other.Examples
>>> summand = Vec3D([2, 6, 20]) >>> summe = summand + -9 >>> print(summe) Vec3D([-7, -3, 11]) >>> summand1 = Vec3D([2, 6, 20]) >>> summand2 = Vec3D([-9.0, -9.0, -9.0]) >>> summe = summand1 + summand2 >>> print(summe) Vec3D([-7.0, -3.0, 11.0])
- __getitem__(key)[source]¶
Implement the
self[key]call.- Returns
for key = 0: x for key = 1: y for key = 2: z
- Return type
- Raises
IndexError – When key outside of 0…2
- Parameters
key (int) –
Examples
>>> vector = Vec3D([3, 7, 13]) >>> print(vector[0]) 3 >>> print(vector[1]) 7 >>> print(vector[2]) 13 >>> print(vector[3]) Traceback (most recent call last): ... IndexError: list index out of range >>> for m in vector: ... print(m) 3 7 13
- __iadd__(other)[source]¶
Addition:
self += other.Examples
>>> summe = Vec3D([2, 6, 20]) >>> summe += -9 >>> print(summe) Vec3D([-7, -3, 11]) >>> summe = Vec3D([2, 6, 20]) >>> summand = Vec3D([-9.0, -9.0, -9.0]) >>> summe += summand >>> print(summe) Vec3D([-7.0, -3.0, 11.0])
- __imul__(other)[source]¶
Multiplikation: self = self * other.
Examples
>>> faktor1 = Vec3D((2, 4, 6)) >>> produkt = faktor1 * 3.75 >>> print(produkt) Vec3D([7.5, 15.0, 22.5]) >>> faktor1 = Vec3D((2, 4, 6)) >>> faktor2 = rotmatx(0.5 * math.pi) >>> produkt = faktor1 * faktor2 >>> print(produkt) Vec3D([2, -4, 6]) >>> produkt = faktor1 * 'text' Traceback (most recent call last): ... TypeError: unsupported operand type(s) for '*': '<class '__main__.Vec3D'>' and '<class 'str'>'
- __isub__(other)[source]¶
Subtraktion: self -= other.
Examples
>>> differenz = Vec3D([4, 8, 16]) >>> differenz -= 2 >>> print(differenz) Vec3D([2, 6, 14])
- __itruediv__(other)[source]¶
Division self /= other.
Examples
>>> quotient = Vec3D([1, 2, 3]) >>> quotient /= 2 >>> print(quotient) Vec3D([0.5, 1.0, 1.5]) >>> quotient /= 'string' Traceback (most recent call last): ... TypeError: unsupported operand type(s) for '/=': '<class '__main__.Vec3D'>' and '<class 'str'>'
- __mul__(other)[source]¶
Multiplikation self * other.
Examples
>>> faktor1 = Vec3D((2,4,6)) >>> produkt = faktor1 * 3.75 >>> print(produkt) Vec3D([7.5, 15.0, 22.5]) >>> produkt = faktor1 * 'text' Traceback (most recent call last): ... TypeError: unsupported operand type(s) for '*': '<class '__main__.Vec3D'>' and '<class 'str'>'
- __neg__()[source]¶
Negation: -self.
- Returns
inverted vector
- Return type
Examples
>>> vector = Vec3D([1, 2, 3]) >>> print(-vector) Vec3D([-1, -2, -3]) >>> vector = Vec3D([-1, -2, -3]) >>> print(-vector) Vec3D([1, 2, 3])
- __radd__(other)[source]¶
Addition:
other + self.Examples
>>> summand = Vec3D([2, 6, 20]) >>> summe = -9 + summand >>> print(summe) Vec3D([-7, -3, 11])
- __rmul__(other)[source]¶
Multiplikation other * self.
Examples
>>> faktor2 = Vec3D((2,4,6)) >>> produkt = 3.75 * faktor2 >>> print(produkt) Vec3D([7.5, 15.0, 22.5]) >>> produkt = faktor2 * 'text' Traceback (most recent call last): ... TypeError: ...
- __rsub__(other)[source]¶
Subraktion: other - self.
Examples
>>> minuend = Vec3D([4, 8, 16]) >>> subtrahend = Vec3D([3, 9, 27]) >>> differenz = 2 - subtrahend >>> print(differenz) Vec3D([-1, -7, -25]) >>> differenz = minuend - subtrahend >>> print(differenz) Vec3D([1, -1, -11])
- __setitem__(key, value)[source]¶
Implement the assignment to
self[key].- Parameters
- Raises
IndexError: – When key outside of 0…2
- Return type
None
Examples
>>> vector = Vec3D() >>> vector[0] = 3 >>> vector[1] = 7 >>> vector[2] = 13 >>> print(vector) Vec3D([3, 7, 13]) >>> vector[3] = 17 Traceback (most recent call last): ... IndexError: list index out of range >>> for m in vector: ... print(m) 3 7 13
- __sub__(other)[source]¶
Subtraktion: self - other.
Examples
>>> minuend = Vec3D([4, 8, 16]) >>> subtrahend = Vec3D([3, 9, 27]) >>> differenz = minuend - 2 >>> print(differenz) Vec3D([2, 6, 14]) >>> differenz = minuend - subtrahend >>> print(differenz) Vec3D([1, -1, -11])
- __truediv__(other)[source]¶
Division self / other.
Examples
>>> dividend = Vec3D([1, 2, 3]) >>> quotient = dividend / 2 >>> print(quotient) Vec3D([0.5, 1.0, 1.5])
- _calcpolar()[source]¶
Berechne polare Komponenten.
Berechnet die polaren Komponenten des Vektors mit den aktuellen kartesischen Daten. Setzt __polarvalid auf True.
Examples
>>> vector1 = Vec3D([1, 0, 0]) >>> print("phi: {}, theta: {}, r: {}".format(vector1.phi, ... vector1.theta, ... vector1.r)) phi: 0.0, theta: 0.0, r: 1.0 >>> vector2 = Vec3D([0, 1, 0]) >>> print("phi: {:.4f}, theta: {}, r: {}".format(vector2.phi, ... vector2.theta, ... vector2.r)) phi: 1.5708, theta: 0.0, r: 1.0 >>> vector3 = Vec3D([0, 0, 1]) >>> print("phi: {}, theta: {:.4f}, r: {}".format(vector3.phi, ... vector3.theta, ... vector3.r)) phi: 0.0, theta: 1.5708, r: 1.0 >>> vector4 = Vec3D([-1, -1, -1]) >>> print("phi: {:.4f}, theta: {:.4f}, r: {:.4f}".format(vector4.phi, ... vector4.theta, ... vector4.r)) phi: 3.9270, theta: -0.6155, r: 1.7321
- Return type
None
- property array: numpy.ndarray¶
Gibt die kartesischen Koordinaten als Spaltenvector in einem numpy.array zurück.
- Returns
Spaltenvektor
[[x][y][z]]- Return type
- property polar: List[float]¶
Gibt die polar Koordinaten zurück.
- Returns
Polarkoordinaten:
[phi, theta, r]- Return type
List[float]
2.1.3. Class Mat3D¶
2.1.4. Operationen¶
- rotmatx(alpha)[source]¶
Matrix für die rotation um die x-achse.
Examples
>>> a = rotmatx(0.25 * math.pi) >>> a._mat [[1, 0, 0], [0, 0.7071067811865476, 0.7071067811865475], [0, -0.7071067811865475, 0.7071067811865476]] >>> a = rotmatx(0.5 * math.pi) >>> b = Vec3D((0.0, 1.0, 0.0)) >>> a * b Vec3D([0.0, 6.123233995736766e-17, -1.0])

