我从45°倾斜矢量开始。之后,我将它绕另一个轴倾斜45°。如何找出矢量倾斜的程度以及绕哪个轴?我认为使用起始四元数的倒数就足够了。
代码:
glm::quat beg = glm::angleAxis(glm::radians(45.f), glm::vec3(1, 1, 0));
glm::vec3 eul = glm::degrees(glm::eulerAngles(beg));
qDebug() << "eul:" << eul[0] << eul[1] << eul[2];
glm::quat end = beg * glm::angleAxis(glm::radians(45.f), glm::vec3(1, 1, 0));
eul = glm::degrees(glm::eulerAngles(end));
qDebug() << "end:" << eul[0] << eul[1] << eul[2];
问题从这里开始,我想得到例如45°左右(1,1,0)。
glm::quat dif = end * glm::inverse(beg);
eul = glm::degrees(glm::eulerAngles(dif));
qDebug() << "dif:" << eul[0] << eul[1] << eul[2];
出:
eul: 51.5893 45 18.9394
end: 130.852 52.4567 72.55
dif: 51.5893 45 18.9394