You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

四元数除法与逆元乘法结果不一致?(q1 / q2 ≠ q1 * q2⁻¹)

Why quatdivide(q1,q2) Doesn't Match quatmultiply(q1, quatinv(q2)) in MATLAB

Great question! The difference you're observing isn't a bug—it's rooted in how MATLAB defines quaternion operations compared to the general mathematical convention you're referencing. Let's break this down clearly:

Core Reason: Reversed Multiplication Order

In standard quaternion math, we define division as q1 / q2 = q1 * q2⁻¹ (multiplying q1 by the inverse of q2). However, MATLAB's quatdivide(q1, q2) actually computes q2⁻¹ * q1 instead of q1 * q2⁻¹. This flipped multiplication order is exactly why your two results have different component signs and ordering.

Let's Verify This

Run this modified version of your code to confirm the relationship:

q1 = [1 0 1 0];
q2 = [1 0.5 0.5 0.75];
q1 = quatnormalize(q1);
q2 = quatnormalize(q2);

% Original results from your code
res_1 = quatdivide(q1, q2)          % Output: [0.7385 0.1231 0.2462 -0.6155]
res_2 = quatmultiply(q1, quatinv(q2)) % Output: [0.7385 -0.6155 0.2462 -0.1231]

% Compute q2⁻¹ * q1 to match quatdivide
q2_inv = quatinv(q2);
res_3 = quatmultiply(q2_inv, q1)    % Output will match res_1 exactly!

Why Rotation Matrices Also Differ

Quaternion multiplication order directly impacts rotation composition logic:

  • q1 * q2⁻¹ represents: first apply the inverse rotation of q2, then apply q1's rotation (left-to-right rotation sequence).
  • q2⁻¹ * q1 represents: first apply q1's rotation, then apply the inverse rotation of q2 (right-to-left sequence, which is MATLAB's default for quaternion rotation functions like quatrotate).

These two distinct rotation sequences produce different rotation matrices, hence the discrepancy you saw after converting with quat2rotm.

Fixes & Next Steps

  • If you need to align with the mathematical definition q1/q2 = q1*q2⁻¹, stick with quatmultiply(q1, quatinv(q2)).
  • If you're working within MATLAB's native rotation workflow (e.g., rotating vectors or combining rotations), use quatdivide to maintain consistency with MATLAB's right-multiplication convention.

内容的提问来源于stack exchange,提问作者herohuyongtao

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 03:47:48