static void InputAngle(TransInfo *UNUSED(t), MouseInput *mi, const double mval[2], float output[3]) { struct InputAngle_Data *data = mi->data; float dir_prev[2], dir_curr[2], mi_center[2]; copy_v2_v2(mi_center, mi->center); sub_v2_v2v2(dir_prev, (const float[2]){UNPACK2(data->mval_prev)}, mi_center); sub_v2_v2v2(dir_curr, (const float[2]){UNPACK2(mval)}, mi_center); if (normalize_v2(dir_prev) && normalize_v2(dir_curr)) { float dphi = angle_normalized_v2v2(dir_prev, dir_curr); if (cross_v2v2(dir_prev, dir_curr) > 0.0f) { dphi = -dphi; } data->angle += ((double)dphi) * (mi->precision ? (double)mi->precision_factor : 1.0); data->mval_prev[0] = mval[0]; data->mval_prev[1] = mval[1]; } output[0] = data->angle; }中output[0]如何转为欧拉角
时间: 2024-03-10 15:43:52 浏览: 100
系统概要设计说明书 (2).docx
在这段代码中,output[0] 表示角度值,不是欧拉角。如果要将这个角度值转换为欧拉角,需要知道在哪个坐标系下进行旋转,并且需要知道旋转顺序。
假设这里的旋转是绕 Z 轴旋转,且旋转顺序为 Z-Y-X,那么将角度值转换为欧拉角的代码如下:
```
float angle = data->angle;
float cx = cosf(angle);
float sx = sinf(angle);
float cy = 1.0f;
float sy = 0.0f;
float cz = 1.0f;
float sz = 0.0f;
float sxy = sx * cy;
float cxy = cx * cy;
float r00 = cz * cy;
float r01 = sz * cxy - cz * sx;
float r02 = sz * sxy + cz * cx;
float r10 = sz * cy;
float r11 = cz * cx + sz * sxy;
float r12 = cz * sx - sz * cxy;
float r20 = -sy;
float r21 = cy * sx;
float r22 = cy * cx;
float sy1 = -r20;
float cy1 = sqrtf(r00 * r00 + r10 * r10);
float angle1 = atan2f(sy1, cy1);
float sy2 = r21 / cy1;
float cy2 = r22 / cy1;
float angle2 = atan2f(sy2, cy2);
float sy3 = r10 / cy1;
float cy3 = r00 / cy1;
float angle3 = atan2f(sy3, cy3);
output[0] = angle1;
output[1] = angle2;
output[2] = angle3;
```
其中,angle1、angle2、angle3 分别表示绕 Z、Y、X 轴旋转的欧拉角值。注意,这里的角度值需要转换为弧度值。
阅读全文