baseball-engine / docs /GEOMETRY.md
github-actions[bot]
Automated Deploy: a19ede424a80b7b8d7f6978585141d1bb45de69c
326d3cc
|
Raw History Blame Contribute Delete
4.93 kB

Geometry and fitted motion

The body chain is SAM full body/hand initialization → exact bundled MHR differentiation → one shared shape/scale trajectory fit → the project's 35-DOF OpenSim kinematic proxy. Native MHR centimetres are converted to metres and y/z flipped once. SAM camera translation is added once. Exported native rotations are not presumed anatomical rotations.

The fitter batches the forward calculation while optimizing the complete observed short clip with one body shape. Missing source frames stay missing; temporal triplets cannot bridge gaps. Adam precedes L-BFGS. Reprojection residuals, initializer agreement, priors, limit penalties and temporal penalties remain separate. A loaded regressor must reproduce SAM's native parameters within the configured arithmetic check before optimization. Regularization sensitivity is reported, not a calibrated accuracy interval.

mhr_limits_path optionally supplies lower/upper arrays for 133 motion parameters excluding native root translation, the exact asset_sha256 and a documented source. Without asset-specific limits the initializer prior remains explicit; no rig coordinates are mislabeled anatomical angles. A height prior requires height_m, uncertainty.height_source and positive uncertainty.height_prior_scale_m. It is a scale prior, not camera calibration.

models/BattingKinematics-v1.osim is the generated project reference template. At runtime, proxy origins/marker offsets are generated from the shared neutral MHR body. configs/anatomical_model.yaml names every primitive, convention and numerical fit gate; configs/landmark_map.yaml names the MHR70 correspondence. Masses/inertias are placeholders. No forces, tissue loads, scapular motion, fingers or injury inference are supported. A forearm longitudinal rotor is an approximation.

OpenSim performs confidence-weighted frame IK. SciPy refines each contiguous accepted sequence with sparse time-aware penalties and soft coordinate limits. Refinement is retained only when observation agreement is preserved. The independent FK implementation is checked against OpenSim primitives. Flexion uses named proxy marker geometry; horizontal heading separation and pelvis-local axial twist are distinct definitions. Angular velocity uses rotation logarithms, not Euler derivatives.

Camera intrinsics are in oriented source pixels:

{"calibration":{"source":"documented calibration record",
                 "intrinsics_oriented_pixels":[[1000,0,640],[0,1000,360],[0,0,1]],
                 "world_axes":"x_pitcher_y_up_z_right_handed",
                 "world_from_camera":{"rotation":[[1,0,0],[0,-1,0],[0,0,-1]],"translation_m":[0,0,0]}}}

This numeric transform is a schema example. Supply your measured transform and verify its x axis points toward the pitcher. The engine never invents a field frame. Intrinsics alone retain model-based scale; body outputs remain experimental.

Ground-plane distances additionally require ground_plane_verified=true, a ground_homography_pixels_to_xz_metres 3×3 matrix, and reviewed event_context.ground_contact_frames with a source description. Applying a homography to an airborne foot does not establish ground distance. Event context can declare lead_side, a documented pitcher_direction_image vector and ground_line_image coefficients for projected candidates.

Independent bat reconstruction

bat_3d_mode defaults to disabled. The engine does not use monocular wrist depth as independent grip geometry. Both enabled modes require measured bat_length_m and explicit independent per-frame records under bat_geometry.frames.

For calibrated_independent_grip, each record contains source, independent=true, knob_camera_m, and endpoints_pixels in knob/barrel order. Use known camera intrinsics. If the barrel ray intersects the known-length sphere at two positive depths, it stays ambiguous unless an independent barrel_anchor_camera_m resolves a unique branch. A temporal prior is not independent disambiguation.

For calibrated_multiview, each record contains source, independent=true, synchronization_verified=true, world_axes="x_pitcher_y_up_z_right_handed", projection_matrices (views×3×4) and endpoints_pixels (views×2×2). Projection matrices map the stated metre world frame into each view's pixels. Triangulation checks ray angle, cheirality and reprojection; rigid fitting checks measured length.

The measurement point lies 0.1524 m inward from the barrel along the shaft; the name "sweet spot" denotes this chosen point, not an experimentally verified optimum for every bat. Physical contact speed and attack direction additionally require valid world geometry, physical timestamps, contiguous direct support and a narrow confirmed contact interval. Attack angle is velocity direction relative to horizontal, not shaft tilt. Exit velocity remains unsupported.