Skip to content

KP to Hand Rotations - #384

Merged
ruofeidu merged 6 commits into
google:mainfrom
whuang37:kp-to-rotation
Jun 17, 2026
Merged

KP to Hand Rotations#384
ruofeidu merged 6 commits into
google:mainfrom
whuang37:kp-to-rotation

Conversation

@whuang37

Copy link
Copy Markdown
Collaborator

Added an additional function to convert keypoints into hand angle rotations. should enable some gesture recording and stuff into the simulator. Test file shows forward backward kinematics.

@ruofeidu

Copy link
Copy Markdown
Collaborator

Follow https://google.github.io/styleguide/tsguide.html#method-and-function-comments

Suggest to Adherence to Coding Guidelines :) The project rules require comments to use third-person verbs and end with periods. Some comments in this PR use imperative verbs or omit ending periods.

In HandPoseFK.ts:
Line 260: // Map joint positions $\rightarrow$ // Maps joint positions.
Line 272: // Helper to build palm basis $\rightarrow$ // Builds the palm basis.
Line 330: // Pre-build child mapping $\rightarrow$ // Pre-builds child mapping for fast lookup.
Line 338: // 2. Iterate remaining joints $\rightarrow$ // 2. Iterates remaining joints in hierarchical order.
Line 349: // Get the child $\rightarrow$ // Gets the child to define the bone direction.
Line 351: // Safety check $\rightarrow$ // Performs a safety check.
Line 384: // Save final orientation $\rightarrow$ // Saves final orientation for children propagation.

In HandPoseIK.test.ts:
// 1. Forward Kinematics to get $\rightarrow$ // 1. Runs Forward Kinematics to get joint positions/orientations.
// 2. Inverse Kinematics to get $\rightarrow$ // 2. Runs Inverse Kinematics to reconstruct rotations.
// 3. Forward Kinematics again $\rightarrow$ // 3. Runs Forward Kinematics again with reconstructed rotations.
// 4. Assert that the recomputed $\rightarrow$ // 4. Asserts that the recomputed joint positions match original positions.

Comment thread src/simulator/handPoses/HandPoseFK.ts Outdated
const computedRotations: SimulatorHandPoseRotations = {};
const finalRotations = new Map<JointName, THREE.Quaternion>();

// Helper to build palm basis

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/simulator/handPoses/HandPoseFK.ts Outdated
const temp = new THREE.Vector3()
.subVectors(indexMcpPos, wristPos)
.normalize();
const zAxis = new THREE.Vector3().crossVectors(yAxis, temp).normalize();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In normal scenarios, these points are non-collinear and non-coincident. However, if the keypoints are corrupted or contain degenerate values (all zeros), the cross product will be [0, 0, 0], leading to a singular basis matrix. When passed to THREE.Quaternion.setFromRotationMatrix(matrix), this can result in NaN quaternion coordinates.

@ruofeidu
ruofeidu marked this pull request as draft June 17, 2026 03:05
@whuang37
whuang37 marked this pull request as ready for review June 17, 2026 03:22
@ruofeidu
ruofeidu merged commit daa5382 into google:main Jun 17, 2026
8 checks passed
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

Successfully merging this pull request may close these issues.

2 participants