欧拉角、旋转矩阵、四元数、角轴、UTM/ENU 及多格式矩阵计算基础库
Project description
transform-base
欧拉角、旋转矩阵、四元数、角轴及外参变换基础库,支持多种旋转顺序(XYZ/XZY/YXZ/YZX/ZXY/ZYX),并提供多输入格式解析、矩阵乘法/求逆/比较/方程求解、UTM/ENU 坐标转换的通用 API。
安装
pip install transform-base
功能特性
- 角度归一化:
normalize_angle将角度归一化到 [-180, 180] - 欧拉角 ↔ 旋转矩阵:支持 6 种旋转顺序(order),默认 ZYX
- 旋转矩阵 ↔ 四元数:
[x, y, z, w]格式 - 旋转矩阵 ↔ 角轴:Rodrigues 公式
- 外参类 ExtrinsicParam:欧拉/旋转矩阵/四元数/角轴多种初始化,齐次矩阵、点变换、复合与逆
- 多格式输入解析:支持旋转矩阵+平移、四元数+平移、欧拉角+平移、4x4 齐次矩阵、JSON/proto/flex 四元数格式
- 矩阵计算:支持统一格式输出、矩阵比较、
A = C @ B/A = B @ D求解 - 地理坐标转换:支持 UTM -> 经纬度、经纬高 -> ENU,以及 TUM UTM 轨迹文件转换为 ENU
- 参考 INS 位姿:使用 PyProj + GRS80 逐记录计算 UTM,支持南北半球、
height + geoid_undulation与qz * qy * qx
快速开始
from transform_base import (
normalize_angle,
standard_euler_to_rotation_matrix,
rotation_matrix_to_standard_euler,
ExtrinsicParam,
parse_transform_input,
transform_from_input,
transform_to_all_formats,
compare_transforms,
solve_transform_equations,
convert_tum_utm_rows_to_enu_rows,
geodetic_pose_to_utm_tum,
utm_to_latlon,
)
# 欧拉角 -> 旋转矩阵 -> 欧拉角
euler = [10.0, 20.0, 30.0] # roll, pitch, yaw (度)
R = standard_euler_to_rotation_matrix(*euler, order="ZYX")
euler_back = rotation_matrix_to_standard_euler(R, order="ZYX")
# 外参:欧拉角 + 平移
ext = ExtrinsicParam(euler=[0, 0, 90], translation=[1, 0, 0])
p_out = ext.transform_point([1, 0, 0])
ext_inv = ext.inverse()
# 多格式输入 -> 外参
raw = '''
"translation": {"x": 1, "y": 2, "z": 3},
"rotation": {"qx": 0.0, "qy": 0.0, "qz": 0.70710678, "qw": 0.70710678}
'''
parsed = parse_transform_input(raw, format_name="json_rotation_translation_qxyzw")
ext_from_input = transform_from_input(raw, format_name="json_rotation_translation_qxyzw")
all_formats = transform_to_all_formats(ext_from_input)
# 比较与方程求解
cmp_result = compare_transforms(ext, ext_inv.inverse())
solve_result = solve_transform_equations(ext, ext_from_input)
# UTM / ENU
lat, lon = utm_to_latlon(500000.0, 3450000.0, zone=50)
enu_rows = convert_tum_utm_rows_to_enu_rows([
"1000.000 500000.000 3450000.000 10.000 0 0 0 1",
"1001.000 500010.000 3450000.000 10.000 0 0 0 1",
])
pose = geodetic_pose_to_utm_tum(
lat=22.5096,
lon=114.0441,
height=10.0,
geoid_undulation=1.25,
roll_deg=10.0,
pitch_deg=20.0,
yaw_deg=30.0,
)
版本记录
- 0.0.5:新增
latlon_to_utm_grs80、euler_rz_ry_rx_to_quaternion、geodetic_pose_to_utm_tum,统一参考 INS 程序的 GRS80 UTM、南北半球、姿态和高度计算。 - 0.0.4:新增 geodesy API:
utm_to_latlon、latlon_to_enu、convert_tum_utm_rows_to_enu_rows、convert_tum_utm_file_to_enu_file。
依赖
- Python >= 3.10
- numpy >= 1.20
- pyproj >= 3.6
- PyYAML >= 6.0
支持的输入格式
rotation_matrix_translationquaternion_translationeuler_degree_translationhomogeneous_matrix_4x4json_rotation_translationjson_rotation_translation_qxyzwtranslation_rotation_quaternionrotation_translation_flex
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
transform_base-0.0.5.tar.gz
(17.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file transform_base-0.0.5.tar.gz.
File metadata
- Download URL: transform_base-0.0.5.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcec118966aba4e04e2ca28ce1dbde0eedfafdf46dec1da49c0d90b1dea79ed0
|
|
| MD5 |
75c2e2dee9b8096716fe847daa006439
|
|
| BLAKE2b-256 |
db7619825a03ce0f583426cafbab68bbc8e5894114ce2d7d80e7e5cadb88fc19
|
File details
Details for the file transform_base-0.0.5-py3-none-any.whl.
File metadata
- Download URL: transform_base-0.0.5-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fed414e535f519f27b362b14c36ea5d96eeff675d68c7f29772962d54cfed0a7
|
|
| MD5 |
8c0b5bc114cd4bf2166d1c5cccff5d4f
|
|
| BLAKE2b-256 |
a000e969a77ba42f1601fec99e8c0ec62a7228aabb1f58b14225cc59e56d5463
|