Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于四元数的计算 #6

Open
thunDL opened this issue Jul 25, 2019 · 8 comments
Open

关于四元数的计算 #6

thunDL opened this issue Jul 25, 2019 · 8 comments

Comments

@thunDL
Copy link

thunDL commented Jul 25, 2019

老师你好,我最近在做一个关于视频提取骨骼特征导入动画的项目,我现在已经获得了三维骨骼关节点的坐标,需要将它转换为BVH文件所表示的运动捕捉模型,在转换坐标到欧拉角的时候,我遇到了问题,所以阅读了您的代码。
但是其中有两点令我感到困惑,每个关节点旋转的变化应该是相对于其父节点,理论上只需要得到父节点指向它的向量和初始位姿的该向量计算便可以得出旋转矩阵再转换为欧拉角,但是为什么在您的代码中需要连接该关节点的所有骨骼信息?是否是因为像Hip这样的关节点连接多个关节点所以需要这样做?
还有在您的代码中,mat3应该是旋转矩阵,但是我不清除在mat3_from_axis中它是如何被转换的?
感谢老师指导。

@meshonline
Copy link
Owner

meshonline commented Jul 25, 2019 via email

@thunDL
Copy link
Author

thunDL commented Jul 25, 2019

好的,谢谢老师,不过第一个问题我具体想问的是:

  • // JOINT_LEFT_HIP
  • p1 = joints[JOINT_LEFT_HIP].pos;
  • p2 = joints[JOINT_LEFT_KNEE].pos;
  • v1 = vec3_create(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z);
  • p1 = joints[JOINT_LEFT_KNEE].pos;
  • p2 = joints[JOINT_LEFT_FOOT].pos;
  • v2 = vec3_create(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z);
  • dot = vec3_dot(vec3_normalize(v1), vec3_normalize(v2));
  • vx = vec3_cross(vec3_normalize(v1), vec3_normalize(v2));
  • // constrain to body's axis x
  • vx = vec3_add(vec3_mul_scalar(vec3_normalize(v_body_x), dot),
    vec3_mul_scalar(vec3_normalize(vx), 1 - dot));
  • // reverse the direction because knees can only bend to back
  • vx = vec3_negate(vx);
  • vy = v1;
  • vz = vec3_zero;
  • m = mat3_from_axis(vx, vy, vz);
  • // inverse bind pose
  • mr = mat3_inverse(mat3_rotation_z(kPi));
  • m = mat3_multiply(mr, m);
  • q = quat_from_mat3(m);
  • joints[JOINT_LEFT_HIP].quat = vec4_create(q.x, q.y, q.z, q.w);

1.例如对于LEFT_HIP这一关节点,为什么需要对它的父节点和子节点都进行运算,计算某一关节点我认为只需要对其子节点,即v2这一向量与初始位姿计算其欧拉角应该就可以了吧,不知道我这想法错在哪里。
2.还有 // constrain to body's axis x不明白这一操作有何意义。
感谢老师的指导。

@meshonline
Copy link
Owner

meshonline commented Jul 26, 2019 via email

@thunDL
Copy link
Author

thunDL commented Jul 26, 2019

好的,明白了,谢谢老师了

@xorespesp
Copy link

Hello, i have a question about quaternion calculation part.
When calculating the quaternions for each joint, i found that the vx, vy, and vz vectors were commonly calculated.
What exactly do these vectors mean?

For example, for a neck joint:

// JOINT_NECK
p1 = joints[JOINT_LEFT_SHOULDER].pos;
p2 = joints[JOINT_RIGHT_SHOULDER].pos;
vx = vec3_create(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z);
p1 = joints[JOINT_NECK].pos;
p2 = joints[JOINT_HEAD].pos;
vy = vec3_create(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z);
vz = vec3_zero;
m = mat3_from_axis(vx, vy, vz);
q = quat_from_mat3(m);
joints[JOINT_NECK].quat = vec4_create(q.x, q.y, q.z, q.w);

In code above, the difference in 3d position values between the left shoulder and right shoulder is set as the vx vector, the difference in 3d position values between the head and neck is set as the vy vector, and finally, vz is set as the zero vector.

I'm not sure what this behavior means exactly.

Any help would be appreciated.
Thank you.

@meshonline
Copy link
Owner

meshonline commented Nov 16, 2023 via email

@xorespesp
Copy link

Thank you for your reply!

And i have one more question.
I'm currently working on converting the skeleton coordinates of the Azure Kinect Body Tracking SDK into BVH by referring to the quaternion calculation code of this project.

This generally works well, but there is one problem: the result skeleton's left and right sides are flipped.

To solve this problem, I first tried simply changing the R/L calculation, but I got a BVH with a completely wrong posture.

I'd like some advice on how to modify my quaternion calculations to solve this problem.

I don't have deep knowledge of quaternion.. so any help would be appreciated.

Thank you.

@meshonline
Copy link
Owner

meshonline commented Nov 18, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants