admin管理员组文章数量:1327849
So, I'm converting some c++ to javascript and I really need to know how D3DX defines their quaternion operators.
//Here's the c++ version
D3DXQUATERNION Qvel = 0.5f * otherQuat* D3DXQUATERNION(angVel.x, angVel.y, angVel.z, 0);
//Here's the js quat multiplication
function quat_mul(q1, q2) {
return
[q1.x * q2.w + q1.y * q2.z - q1.z * q2.y + q1.w * q2.x,
-q1.x * q2.z + q1.y * q2.w + q1.z * q2.x + q1.w * q2.y,
q1.x * q2.y - q1.y * q2.x + q1.z * q2.w + q1.w * q2.z,
-q1.x * q2.x - q1.y * q2.y - q1.z * q2.z + q1.w * q2.w]
Is the scalar operation quat * 0.5f just like this?
quat.x *= .5;
quat.y *= .5;
quat.z *= .5;
quat.w *= .5;
So, I'm converting some c++ to javascript and I really need to know how D3DX defines their quaternion operators.
//Here's the c++ version
D3DXQUATERNION Qvel = 0.5f * otherQuat* D3DXQUATERNION(angVel.x, angVel.y, angVel.z, 0);
//Here's the js quat multiplication
function quat_mul(q1, q2) {
return
[q1.x * q2.w + q1.y * q2.z - q1.z * q2.y + q1.w * q2.x,
-q1.x * q2.z + q1.y * q2.w + q1.z * q2.x + q1.w * q2.y,
q1.x * q2.y - q1.y * q2.x + q1.z * q2.w + q1.w * q2.z,
-q1.x * q2.x - q1.y * q2.y - q1.z * q2.z + q1.w * q2.w]
Is the scalar operation quat * 0.5f just like this?
quat.x *= .5;
quat.y *= .5;
quat.z *= .5;
quat.w *= .5;
Share
Improve this question
asked Jan 26, 2012 at 23:48
FlavorScapeFlavorScape
14.3k12 gold badges79 silver badges123 bronze badges
2 Answers
Reset to default 7According to this link, it's like you say (and also in the quaternion number system):
inline D3DXQUATERNION& D3DXQUATERNION::operator *= (FLOAT f)
{
x *= f;
y *= f;
z *= f;
w *= f;
return *this;
}
This is a very old question but I can verify this from a published source: Vince 2011 - Quaternion for Computer Graphics, page 57-58.
In simpler form:
q = [s, v] where s \in R and v \in R^3
\lambda q = [\lambda s, \lambda v] where \lambda \in R
In more plex notation:
q = a + bi + cj + dk
q * s = s * a + bi * s + cj * s + dk * s
= s * a + (b * s)i + (c * s)j + (d * s)k
in javascript
let quat = [0.4, 0.3, 0.7, 0.1];
function quaternion_scalar_multiplication(quat, s){
quat[0] *= s;
quat[1] *= s;
quat[2] *= s;
quat[3] *= s;
return quat;
}
本文标签: javascriptHow to apply a scalar multiplication to a QuaternionStack Overflow
版权声明:本文标题:javascript - How to apply a scalar multiplication to a Quaternion - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742219357a2435159.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论