Improve mju_cross implementation.
- Allow in-place cross product a = a x b using `mju_cross(a, a, b)`. - Easier for compiler to optimize since tmp cannot alias a or b (verified with godbolt). PiperOrigin-RevId: 547265908 Change-Id: If965867e08c1bc980e71729e38f6855e32de18b2
This commit is contained in:
committed by
Copybara-Service
parent
e2677d6057
commit
77b3533d90
@@ -323,9 +323,14 @@ void mju_trnVecPose(mjtNum res[3], const mjtNum pos[3], const mjtNum quat[4], co
|
||||
|
||||
// vector cross-product, 3D
|
||||
void mju_cross(mjtNum res[3], const mjtNum a[3], const mjtNum b[3]) {
|
||||
res[0] = a[1]*b[2] - a[2]*b[1];
|
||||
res[1] = a[2]*b[0] - a[0]*b[2];
|
||||
res[2] = a[0]*b[1] - a[1]*b[0];
|
||||
mjtNum tmp[3] = {
|
||||
a[1]*b[2] - a[2]*b[1],
|
||||
a[2]*b[0] - a[0]*b[2],
|
||||
a[0]*b[1] - a[1]*b[0]
|
||||
};
|
||||
res[0] = tmp[0];
|
||||
res[1] = tmp[1];
|
||||
res[2] = tmp[2];
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user