#!/usr/bin/env python3 import re import sys import numpy as np def extract_positions(text): """ Extract only x, y, and z position values from each data block. Returns a list of NumPy arrays. """ # Match lines such as: # x: +5272.9397 km # y: +4563.9851 km # z: -717.9430 km pattern = re.compile( r"^\s*([xyz])\s*:\s*([+-]?\d+(?:\.\d+)?)\s*km", re.MULTILINE | re.IGNORECASE ) values = {} for coordinate, value in pattern.findall(text): coordinate = coordinate.lower() values[coordinate] = np.float64(value) # Once x, y, and z are found, save the position if all(axis in values for axis in ("x", "y", "z")): position = np.array( [values["x"], values["y"], values["z"]], dtype=np.float64 ) yield position values = {} def main(): print("Paste your data below.") print("When finished:") print(" Linux/macOS: press Ctrl-D") print(" Windows: press Ctrl-Z, then Enter") print() data = sys.stdin.read() positions = list(extract_positions(data)) if len(positions) < 2: print("Error: at least two x/y/z position sets are required.") return print("\nExtracted positions:") for index, position in enumerate(positions, start=1): print(f"Position {index}: {position}") print("\nOffsets:") for index in range(len(positions) - 1): position_1 = positions[index] position_2 = positions[index + 1] difference = position_2 - position_1 offset = np.float64(np.linalg.norm(difference)) print(f"Position {index + 1} → Position {index + 2}") print(f"Difference vector: {difference} km") print(f"Offset: {offset} km") if __name__ == "__main__": main()