Aktualisierung
This commit is contained in:
1 parent
863bb21df7
commit
2ae8a2438a
6 files changed
+229
-17
No files matched your search
@@ -14,8 +14,8 @@ class Apollo(Moon):
|
|||||||
result = matmul(self.rot_apollo, point) #apollo wird mit dr rotationsmatrix gedreht
|
result = matmul(self.rot_apollo, point) #apollo wird mit dr rotationsmatrix gedreht
|
||||||
self.position_apollo = (result[0][0], result[1][0]) #koordinaten werden gespeichert
|
self.position_apollo = (result[0][0], result[1][0]) #koordinaten werden gespeichert
|
||||||
return True
|
return True
|
||||||
def draw_game(self):
|
def draw_content(self):
|
||||||
super().draw_game()
|
super().draw_content()
|
||||||
|
|
||||||
center_x = self.size[0] // 2 #mittelpunkt bestimmen
|
center_x = self.size[0] // 2 #mittelpunkt bestimmen
|
||||||
center_y = self.size[1] // 2
|
center_y = self.size[1] // 2
|
||||||
@@ -34,12 +34,11 @@ class Apollo(Moon):
|
|||||||
|
|
||||||
pygame.draw.circle(
|
pygame.draw.circle(
|
||||||
self.screen,
|
self.screen,
|
||||||
(255, 0, 0),
|
(255, 50, 50),
|
||||||
(int(apollo_x), int(apollo_y)),
|
(int(apollo_x), int(apollo_y)),
|
||||||
5
|
5
|
||||||
)
|
)
|
||||||
|
|
||||||
pygame.display.flip()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
apollo = Apollo()
|
apollo = Apollo()
|
||||||
|
|||||||
+9
-11
@@ -41,14 +41,17 @@ class Moon(Game):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def draw_game(self) -> None:
|
def draw_game(self) -> None:
|
||||||
"""Zeichnet Erde und Mond."""
|
self.draw_content()
|
||||||
|
|
||||||
|
# TODO: Bild anzeigen
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
def draw_content(self):
|
||||||
|
"""Zeichnet Erde und Mond."""
|
||||||
# TODO: Bildschirm löschen
|
# TODO: Bildschirm löschen
|
||||||
self.screen.fill(BLACK)
|
self.screen.fill(BLACK)
|
||||||
|
|
||||||
center_x = self.size[0] // 2
|
center_x = self.size[0] // 2
|
||||||
center_y = self.size[1] // 2 #hiermit berchnen wir den mittelpunkt des fensters
|
center_y = self.size[1] // 2 # hiermit berchnen wir den mittelpunkt des fensters
|
||||||
|
|
||||||
# TODO: Erde zeichnen
|
# TODO: Erde zeichnen
|
||||||
pygame.draw.circle(
|
pygame.draw.circle(
|
||||||
self.screen,
|
self.screen,
|
||||||
@@ -56,11 +59,9 @@ class Moon(Game):
|
|||||||
(center_x, center_y),
|
(center_x, center_y),
|
||||||
EARTH_RADIUS
|
EARTH_RADIUS
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: Mond zeichnen
|
# TODO: Mond zeichnen
|
||||||
moon_x = center_x + self.position_moon[0] #zuerst die pos berechnen
|
moon_x = center_x + self.position_moon[0] # zuerst die pos berechnen
|
||||||
moon_y = center_y + self.position_moon[1] #abstand zur erde
|
moon_y = center_y + self.position_moon[1] # abstand zur erde
|
||||||
|
|
||||||
pygame.draw.circle(
|
pygame.draw.circle(
|
||||||
self.screen,
|
self.screen,
|
||||||
WHITE,
|
WHITE,
|
||||||
@@ -68,9 +69,6 @@ class Moon(Game):
|
|||||||
MOON_RADIUS
|
MOON_RADIUS
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: Bild anzeigen
|
|
||||||
pygame.display.flip()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# TODO: Moon-Objekt erzeugen und starten
|
# TODO: Moon-Objekt erzeugen und starten
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# Prog3B/compute.py
|
# Prog3B/compute.py
|
||||||
|
# Von opencode generiert und anschließend mit dem Prof korrigiert
|
||||||
|
|
||||||
"""Matrix transpose implementation.
|
"""Matrix transpose implementation.
|
||||||
|
|
||||||
@@ -17,7 +18,6 @@ Example
|
|||||||
from typing import List, Any
|
from typing import List, Any
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
|
||||||
def transpose(matrix: List[List[Any]]) -> List[List[Any]]:
|
def transpose(matrix: List[List[Any]]) -> List[List[Any]]:
|
||||||
"""Return the transpose of a rectangular matrix.
|
"""Return the transpose of a rectangular matrix.
|
||||||
|
|
||||||
@@ -81,6 +81,48 @@ def rot_2D(theta):
|
|||||||
[math.cos(theta), -math.sin(theta)],
|
[math.cos(theta), -math.sin(theta)],
|
||||||
[math.sin(theta), math.cos(theta)]
|
[math.sin(theta), math.cos(theta)]
|
||||||
]
|
]
|
||||||
|
def rot_3D(angle: float, axis: str) -> list[list[float]]: #Praktikumsaufgabe 3
|
||||||
|
"""Create a 3‑D rotation matrix.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
angle
|
||||||
|
Rotation angle in **radians**.
|
||||||
|
axis
|
||||||
|
Axis to rotate around – ``"x"``, ``"y"`` or ``"z"``
|
||||||
|
(case‑insensitive).
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
list[list[float]]
|
||||||
|
3×3 rotation matrix.
|
||||||
|
"""
|
||||||
|
# Normalise the axis argument.
|
||||||
|
ax = axis.lower()
|
||||||
|
if ax not in {"x", "y", "z"}:
|
||||||
|
raise ValueError("Axis must be 'x', 'y' or 'z'")
|
||||||
|
|
||||||
|
c = math.cos(angle)
|
||||||
|
s = math.sin(angle)
|
||||||
|
|
||||||
|
if ax == "x":
|
||||||
|
return [
|
||||||
|
[1.0, 0.0, 0.0],
|
||||||
|
[0.0, c, -s],
|
||||||
|
[0.0, s, c],
|
||||||
|
]
|
||||||
|
if ax == "y":
|
||||||
|
return [
|
||||||
|
[c, 0.0, s],
|
||||||
|
[0.0, 1.0, 0.0],
|
||||||
|
[-s, 0.0, c],
|
||||||
|
]
|
||||||
|
# ax == "z"
|
||||||
|
return [
|
||||||
|
[c, -s, 0.0],
|
||||||
|
[s, c, 0.0],
|
||||||
|
[0.0, 0.0, 1.0],
|
||||||
|
]
|
||||||
|
|
||||||
def matmul(A, B):
|
def matmul(A, B):
|
||||||
"""Multipliziert zwei Matrizen."""
|
"""Multipliziert zwei Matrizen."""
|
||||||
|
|||||||
@@ -0,0 +1,146 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Installiert die Abhängigkeiten aus pyproject.toml in die aktuelle Python-Umgebung.
|
||||||
|
|
||||||
|
Ersatz für "Install requirements" aus PyCharm, wenn das Projekt eine pyproject.toml
|
||||||
|
statt einer requirements.txt hat. Kein Build, keine besondere Projektstruktur nötig,
|
||||||
|
nur Standardbibliothek (Python >= 3.11).
|
||||||
|
|
||||||
|
Benutzung:
|
||||||
|
In PyCharm: Rechtsklick auf diese Datei -> Run 'install_dependencies'
|
||||||
|
Im Terminal (venv aktiv): python install_dependencies.py
|
||||||
|
|
||||||
|
Ohne Parameter wird ALLES installiert:
|
||||||
|
[project].dependencies + alle [project.optional-dependencies] + alle [dependency-groups]
|
||||||
|
|
||||||
|
Abweichendes Verhalten:
|
||||||
|
python install_dependencies.py --extra dev nur Basis + Extra "dev"
|
||||||
|
python install_dependencies.py --group test nur Basis + Gruppe "test"
|
||||||
|
python install_dependencies.py --no-main --group dev
|
||||||
|
python install_dependencies.py --list nur anzeigen, nichts installieren
|
||||||
|
python install_dependencies.py --write requirements.txt schreiben statt installieren
|
||||||
|
python install_dependencies.py --write -o reqs.txt
|
||||||
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.version_info < (3, 11):
|
||||||
|
sys.exit("Dieses Skript braucht Python 3.11 oder neuer (tomllib). "
|
||||||
|
f"Aktuell: {sys.version.split()[0]}")
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
import tomllib
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
PROJECT_DIR = Path(__file__).resolve().parent
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_group(groups: dict, name: str, seen: set[str] | None = None) -> list[str]:
|
||||||
|
"""Löst eine Dependency-Group inkl. {include-group = "..."} rekursiv auf."""
|
||||||
|
seen = set() if seen is None else seen
|
||||||
|
if name in seen:
|
||||||
|
raise ValueError(f"Zyklische include-group: {name}")
|
||||||
|
if name not in groups:
|
||||||
|
raise KeyError(f"Dependency-Group '{name}' nicht gefunden")
|
||||||
|
seen.add(name)
|
||||||
|
result: list[str] = []
|
||||||
|
for entry in groups[name]:
|
||||||
|
if isinstance(entry, str):
|
||||||
|
result.append(entry)
|
||||||
|
elif isinstance(entry, dict) and "include-group" in entry:
|
||||||
|
result.extend(resolve_group(groups, entry["include-group"], seen))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def collect(data: dict, extras: list[str], groups: list[str], no_main: bool) -> list[str]:
|
||||||
|
project = data.get("project", {})
|
||||||
|
optional = project.get("optional-dependencies", {})
|
||||||
|
dep_groups = data.get("dependency-groups", {})
|
||||||
|
deps: list[str] = []
|
||||||
|
|
||||||
|
if not no_main:
|
||||||
|
deps.extend(project.get("dependencies", []))
|
||||||
|
for extra in extras:
|
||||||
|
if extra not in optional:
|
||||||
|
raise KeyError(f"Optional-Dependency '{extra}' nicht gefunden")
|
||||||
|
deps.extend(optional[extra])
|
||||||
|
for group in groups:
|
||||||
|
deps.extend(resolve_group(dep_groups, group))
|
||||||
|
|
||||||
|
# Duplikate entfernen, Reihenfolge behalten
|
||||||
|
return list(dict.fromkeys(d.strip() for d in deps if d.strip()))
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||||
|
p.add_argument("-p", "--pyproject", type=Path, default=PROJECT_DIR / "pyproject.toml",
|
||||||
|
help="Pfad zur pyproject.toml (Standard: neben diesem Skript)")
|
||||||
|
p.add_argument("--extra", action="append", default=None,
|
||||||
|
help="nur diese optional-dependencies (mehrfach möglich)")
|
||||||
|
p.add_argument("--group", action="append", default=None,
|
||||||
|
help="nur diese dependency-groups (mehrfach möglich)")
|
||||||
|
p.add_argument("--no-main", action="store_true", help="[project].dependencies weglassen")
|
||||||
|
p.add_argument("--list", action="store_true", help="Abhängigkeiten nur anzeigen")
|
||||||
|
p.add_argument("--write", action="store_true", help="requirements-Datei schreiben statt installieren")
|
||||||
|
p.add_argument("-o", "--output", type=Path, default=PROJECT_DIR / "requirements.txt",
|
||||||
|
help="Zieldatei für --write")
|
||||||
|
args = p.parse_args()
|
||||||
|
|
||||||
|
if not args.pyproject.exists():
|
||||||
|
print(f"{args.pyproject} nicht gefunden", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
data = tomllib.loads(args.pyproject.read_text(encoding="utf-8"))
|
||||||
|
all_extras = list(data.get("project", {}).get("optional-dependencies", {}))
|
||||||
|
all_groups = list(data.get("dependency-groups", {}))
|
||||||
|
|
||||||
|
# Ohne --extra/--group: alles. Mit einem davon: nur das Gewählte.
|
||||||
|
selective = args.extra is not None or args.group is not None
|
||||||
|
extras = (args.extra or []) if selective else all_extras
|
||||||
|
groups = (args.group or []) if selective else all_groups
|
||||||
|
|
||||||
|
try:
|
||||||
|
deps = collect(data, extras, groups, args.no_main)
|
||||||
|
except (KeyError, ValueError) as e:
|
||||||
|
print(f"Fehler: {e.args[0]}", file=sys.stderr)
|
||||||
|
print(f" Vorhandene --extra: {', '.join(all_extras) or '(keine)'}", file=sys.stderr)
|
||||||
|
print(f" Vorhandene --group: {', '.join(all_groups) or '(keine)'}", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
parts = ([] if args.no_main else ["Basis"]) + [f"extra:{e}" for e in extras] + [f"group:{g}" for g in groups]
|
||||||
|
print(f"Auswahl: {', '.join(parts) or '(nichts)'}")
|
||||||
|
|
||||||
|
if args.list:
|
||||||
|
print("\n".join(deps) or "(keine Abhängigkeiten)")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
content = f"# Automatisch erzeugt aus {args.pyproject.name} – nicht von Hand bearbeiten\n" + "\n".join(deps) + "\n"
|
||||||
|
|
||||||
|
if args.write:
|
||||||
|
args.output.write_text(content, encoding="utf-8")
|
||||||
|
print(f"{len(deps)} Abhängigkeiten -> {args.output}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if not deps:
|
||||||
|
print("Keine Abhängigkeiten gefunden – nichts zu tun.")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if sys.prefix == sys.base_prefix:
|
||||||
|
print("WARNUNG: Es ist kein virtuelles Environment aktiv – es wird in die globale "
|
||||||
|
f"Python-Installation installiert:\n {sys.prefix}", file=sys.stderr)
|
||||||
|
if sys.stdin.isatty() and input("Trotzdem fortfahren? [j/N] ").strip().lower() not in ("j", "ja", "y", "yes"):
|
||||||
|
return 1
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile("w", suffix=".txt", delete=False, encoding="utf-8") as tmp:
|
||||||
|
tmp.write(content)
|
||||||
|
tmp_path = Path(tmp.name)
|
||||||
|
try:
|
||||||
|
print(f"Installiere {len(deps)} Abhängigkeiten in {sys.prefix}\n")
|
||||||
|
return subprocess.call([sys.executable, "-m", "pip", "install", "-r", str(tmp_path)])
|
||||||
|
finally:
|
||||||
|
tmp_path.unlink(missing_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "matrixmania"
|
name = "matrixmania"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
dev = ["pytest", "ruff", "pytest-cov"]
|
||||||
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#Praktikumsaufgaben 3
|
||||||
|
#rot_2D wir testen eine Drehung um 90 grad,
|
||||||
|
#rot_3D wir testen die Rotationsmatrix im 3d Raum
|
||||||
|
|
||||||
|
import math
|
||||||
|
from compute import rot_2D, rot_3D
|
||||||
|
|
||||||
|
def test_rot_2D():
|
||||||
|
angle = math.pi / 2
|
||||||
|
expected = [
|
||||||
|
[0, -1],
|
||||||
|
[1, 0],
|
||||||
|
]
|
||||||
|
result = rot_2D(angle)
|
||||||
|
|
||||||
|
for i in range(2):
|
||||||
|
for j in range(2):
|
||||||
|
assert math.isclose(
|
||||||
|
result[i][j],
|
||||||
|
expected[i][j],
|
||||||
|
abs_tol=1e-9,
|
||||||
|
)
|
||||||
|
def test_rot_3D():
|
||||||
Reference in new issue
Block a user