@@ -96,14 +96,6 @@ void BinEdges(mjtNum* x_edges, mjtNum* y_edges, int size[2], mjtNum fov[2],
96
96
mju_scl (y_edges, y_edges, fov[1 ]*mjPI / 180 , size[1 ] + 1 );
97
97
}
98
98
99
- // Permute 3-vector from 0,1,2 to 2,0,1.
100
- static void xyz2zxy (mjtNum* x) {
101
- mjtNum z = x[2 ];
102
- x[2 ] = x[1 ];
103
- x[1 ] = x[0 ];
104
- x[0 ] = z;
105
- }
106
-
107
99
// Transform spherical (azimuth, elevation, radius) to Cartesian (x,y,z).
108
100
void SphericalToCartesian (const mjtNum aer[3 ], mjtNum xyz[3 ]) {
109
101
mjtNum a = aer[0 ], e = aer[1 ], r = aer[2 ];
@@ -372,21 +364,17 @@ void TouchStress::Compute(const mjModel* m, mjData* d, int instance) {
372
364
mju_sub3 (vel_rel, vel_sensor+3 , vel_other+3 );
373
365
374
366
// Get contact force/torque, rotate into node frame.
375
- mjtNum force [3 ];
376
- mjtNum tmp_force[ 3 ], normal[3 ];
367
+ mjtNum frc [3 ];
368
+ mjtNum normal[3 ];
377
369
mjtNum kMaxDepth = 0.05 ;
378
370
mjtNum pressure = 1 / (kMaxDepth - depth) - 1 / kMaxDepth ;
379
371
mjc_gradient (m, d, &sensor_sdf, normal, pos);
380
- mju_scl3 (tmp_force, normal, pressure);
381
- mju_mulMatTVec3 (force, mat, tmp_force);
382
- force[0 ] = mju_abs (mju_dot3 (vel_rel, mat + 0 ));
383
- force[1 ] = mju_abs (mju_dot3 (vel_rel, mat + 3 ));
384
-
385
- // Permute forces from x,y,z to z,x,y (normal, tangent, tangent)
386
- xyz2zxy (force);
387
- forcesT[0 *ncon + node] = force[0 ];
388
- forcesT[1 *ncon + node] = force[1 ];
389
- forcesT[2 *ncon + node] = force[2 ];
372
+ mju_scl3 (frc, normal, pressure);
373
+
374
+ // one row of mat^T * force
375
+ forcesT[0 *ncon + node] = mat[2 ]*frc[0 ] + mat[5 ]*frc[1 ] + mat[8 ]*frc[2 ];
376
+ forcesT[1 *ncon + node] = mju_abs (mju_dot3 (vel_rel, mat + 0 ));
377
+ forcesT[2 *ncon + node] = mju_abs (mju_dot3 (vel_rel, mat + 3 ));
390
378
node++;
391
379
}
392
380
}
0 commit comments