Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.8 kB
2
Indexable
Never
public class FingerConstraints {

    // Define anatomical range of motion (ROM) for each finger joint in degrees (adjust these values based on your reference data)
    public static final int THUMB_META_CARPAL_MIN = -30;
    public static final int THUMB_META_CARPAL_MAX = 90;
    public static final int THUMB_PROXIMAL_MIN = 0;
    public static final int THUMB_PROXIMAL_MAX = 90;
    public static final int THUMB_DISTAL_MIN = -45;
    public static final int THUMB_DISTAL_MAX = 20;

    public static final int INDEX_PROXIMAL_MIN = 0;
    public static final int INDEX_PROXIMAL_MAX = 90;
    public static final int INDEX_MIDDLE_MIN = 0;
    public static final int INDEX_MIDDLE_MAX = 90;
    public static final int INDEX_DISTAL_MIN = -45;
    public static final int INDEX_DISTAL_MAX = 20;

    public static final int MIDDLE_PROXIMAL_MIN = 0;
    public static final int MIDDLE_PROXIMAL_MAX = 90;
    public static final int MIDDLE_MIDDLE_MIN = 0;
    public static final int MIDDLE_MIDDLE_MAX = 90;
    public static final int MIDDLE_DISTAL_MIN = -45;
    public static final int MIDDLE_DISTAL_MAX = 20;

    public static final int RING_PROXIMAL_MIN = 0;
    public static final int RING_PROXIMAL_MAX = 90;
    public static final int RING_MIDDLE_MIN = 0;
    public static final int RING_MIDDLE_MAX = 90;
    public static final int RING_DISTAL_MIN = -45;
    public static final int RING_DISTAL_MAX = 20;

    public static final int PINKY_PROXIMAL_MIN = 0;
    public static final int PINKY_PROXIMAL_MAX = 90;
    public static final int PINKY_MIDDLE_MIN = 0;
    public static final int PINKY_MIDDLE_MAX = 90;
    public static final int PINKY_DISTAL_MIN = -45;
    public static final int PINKY_DISTAL_MAX = 20;

    public static float[] applyConstraints(float[] rotations) {
        // Assumes rotations array contains rotation data for all finger joints in a specific order (e.g., thumb joints, index joints, etc.)
        for (int i = 0; i < rotations.length; i++) {
            switch (i) {
                case 0:  // Thumb Metacarpal
                    rotations[i] = clampRotation(rotations[i], THUMB_META_CARPAL_MIN, THUMB_META_CARPAL_MAX);
                    break;
                case 1:  // Thumb Proximal
                    rotations[i] = clampRotation(rotations[i], THUMB_PROXIMAL_MIN, THUMB_PROXIMAL_MAX);
                    break;
                case 2:  // Thumb Distal
                    rotations[i] = clampRotation(rotations[i], THUMB_DISTAL_MIN, THUMB_DISTAL_MAX);
                    break;
                // ... (similar cases for other finger joints based on their order in the rotations array)
            }
        }
        return rotations;
    }

    private static float clampRotation(float rotation, float min, float max) {
        return Math.min(Math.max(rotation, min), max);
    }
}
Leave a Comment