Algorithm Search⌘K

Techniqueadvanced

Kinematic fixture analysis

Also called Asada-By fixture analysis.

Asada and By's test that point locators fix a part deterministically, by the rank of a matrix of locator normals and positions, and allow loading and unloading.

Kinematic fixture analysis decides from the locator layout alone whether a fixture positions a part in one well-defined place. Asada and By (1985) wrote the first-order gap change at each frictionless point locator as a row of a matrix, the locator Jacobian, and showed that the part is positioned deterministically if and only if this matrix has rank 6. The same matrix answers a second question with a sign test instead of a rank test: can the part be loaded and unloaded, that is, is there a small motion that moves it away from the locators without pushing into any of them? This page gives the template, proves both tests, and shows an exact implementation in rational arithmetic.

In plain words

Each locator is a pin that touches the part at one point. If you move the part a tiny bit, each pin sees a small gap open or close. Write down, for each pin, how its gap changes for each of the six ways the part can move: three slides and three turns. That gives a table with one row per pin and six columns. If some motion leaves every gap unchanged, the part can drift along that motion and its position is not fixed. This happens exactly when the rows do not fill all six directions, which is a rank test. A second question is whether the part can be put in and taken out. That needs a motion that opens some gaps and closes none. Pins can only push, so this is a test about signs, not about rank.

When it applies

  • The part is rigid and the locators are point contacts with no friction. Friction and part deformation are outside the model.
  • Motions are small. The test is first order: it uses the tangent plane at each contact, not the curvature of the part or of the locator. A rank 6 result is a sufficient condition for a fixed position. A rank deficient result means the part is free to first order, and a second-order analysis can still find that curvature holds it.
  • The question is about the layout, before forces: is the position unique, which locators are needed, can the part be loaded. Holding the part against cutting forces is a later step of fixture planning.

The template

A contact is a point pip_i on the part surface and a normal nin_i from the locator into the part. A small motion is a twist ξ=(δ,ω)∈R6\xi = (\delta, \omega) \in \mathbb{R}^6 that moves a body point pp to p+δ+ω×pp + \delta + \omega \times p. The gap at contact ii changes by ni⋅δ+(pi×ni)⋅ωn_i \cdot \delta + (p_i \times n_i) \cdot \omega, so the row Ji=[ niT    (pi×ni)T ]J_i = [\, n_i^{\mathsf T} \;\; (p_i \times n_i)^{\mathsf T} \,] is the gradient of gap ii. It is also the wrench of a unit push of locator ii on the part.

  1. KINEMATIC-FIXTURE-ANALYSIS((p_1, n_1), …, (p_m, n_m))
  2. 1for i ← 1 to m do J_i ← (n_i, p_i × n_i) ▷ hole: the contact model
  3. 2r ← rank of J, by elimination in exact arithmetic
  4. 3if r < 6 then report NOT DETERMINISTIC and a basis of {ξ : Jξ = 0}
  5. 4for each set T of r − 1 linearly independent rows of J do ▷ hole: the cone test
  6. 5choose ξ with J_T ξ = 0 and Jξ ≠ 0
  7. 6if Jξ ≥ 0 then return DETACHABLE along ξ
  8. 7if Jξ ≤ 0 then return DETACHABLE along −ξ
  9. 8return NOT DETACHABLE ▷ with r = 6 this is form closure

Line L1 has a hole for the contact model: a point on a plane, a point on a sphere and a point in a hole all give one row each, with the normal at the contact. A cylindrical pin in a hole is often modeled as two rows, one per direction across the axis. Lines L4 to L7 have a hole for the cone test: the exact enumeration shown here, or a linear program.

Theorem 1 (determinism, Asada and By). No nonzero twist leaves every gap unchanged to first order if and only if rank⁡J=6\operatorname{rank} J = 6. Proof. The twists that leave every gap unchanged to first order are the solutions of Jξ=0J\xi = 0. By rank and nullity, this space has dimension 6−rank⁡J6 - \operatorname{rank} J, so it is {0}\{0\} exactly when the rank is 6. □\square When the rank is less than 6, line L3 returns the null twists: each is a motion along which every contact slides on its face.

Detachability. A twist ξ\xi is detaching if Jξ≥0J\xi \ge 0 and Jξ≠0J\xi \ne 0: no gap closes and at least one opens. Asada and By call the conditions for loading and unloading accessibility and detachability. With rank 6 and no detaching twist, every motion closes some gap, so the contacts alone stop all small motions: this is first-order form closure.

Theorem 2 (the cone test is exact). A detaching twist exists if and only if lines L4 to L7 find one. Proof. The "if" part holds because L6 and L7 return a twist that they have checked. For "only if", let r=rank⁡Jr = \operatorname{rank} J, let VV be the row space of JJ, and let D={ξ∈V:Jξ≥0}D = \{\xi \in V : J\xi \ge 0\}. A twist and its projection on VV give the same JξJ\xi, because the difference lies in V⊥V^\perp, the null space of JJ. So if a detaching twist exists, DD contains a nonzero vector. DD is a polyhedral cone, and it is pointed: if ξ\xi and −ξ-\xi are both in DD, then Jξ=0J\xi = 0, so ξ∈V∩V⊥={0}\xi \in V \cap V^\perp = \{0\}. A nonzero pointed polyhedral cone in the rr-dimensional space VV has an extreme ray, and on an extreme ray r−1r - 1 linearly independent constraints Jiξ≥0J_i \xi \ge 0 hold with equality (Schrijver, Chapter 8). Let TT be these rows and ξ∗\xi^\ast a twist on the ray. The solutions of JTξ=0J_T \xi = 0 form the null space of JJ plus one more dimension, so the vectors JξJ\xi for these solutions form a single line through 0. The twist ξ\xi of L5 and ξ∗\xi^\ast give two nonzero points of this line, so JξJ\xi is a nonzero multiple of Jξ∗≥0J\xi^\ast \ge 0, and L6 or L7 returns. □\square

A second view of the same test is Stiemke's theorem, a variant of the Farkas lemma: there is no detaching twist if and only if some λ\lambda with all entries strictly positive has JTλ=0J^{\mathsf T} \lambda = 0. The easy half takes one line: if such a λ\lambda exists and Jξ≥0J\xi \ge 0, then 0=λTJξ0 = \lambda^{\mathsf T} J \xi is a sum of nonnegative terms with positive weights, so Jξ=0J\xi = 0. The other half is in Schrijver, Chapter 7. In the language of wrenches, the locator wrenches positively span their own span. With rank 6 they positively span R6\mathbb{R}^6, which is the usual statement of form closure.

Six locators never hold. If m=6m = 6 and rank⁡J=6\operatorname{rank} J = 6, then ξ=J−1(1,…,1)T\xi = J^{-1}(1, \dots, 1)^{\mathsf T} is detaching. So a deterministic fixture with six locators can always be loaded and unloaded, and it never has form closure. At least seven contacts are needed in space and four in the plane, with equality for almost all parts (Markenscoff, Ni and Papadimitriou 1990). The fixture planning page proves the lower bound.

Locator errors. For six locators with rank 6, if locator ii is off by a small εi\varepsilon_i along its normal, the part comes to rest at the twist ξ=J−1ε\xi = J^{-1} \varepsilon. The norm of J−1J^{-1} measures how much the layout amplifies locator errors, and a well-spread layout keeps it small.

Cost. Line L1 takes O(m)O(m) time and L2 takes O(m)O(m) row operations on rows of length 6, so the rank test is linear in the number of contacts. The exact cone test of L4 to L7 tries up to (mr−1)\binom{m}{r-1} sets, which is fine for the 6 to 12 contacts of a real fixture. A linear program decides the same question in polynomial time for large mm.

Implementation. The code works in Fraction arithmetic, so a rank or a sign is never wrong because of rounding. The tests compare the rank with the largest nonzero minor found by Laplace expansion. They move the part by exact finite rigid motions, with rational rotations from the Cayley transform, and check that each gap changes by tJiξt J_i \xi up to O(t2)O(t^2), that each reported null twist changes no gap to first order, and that no twist in {−1,0,1}6\{-1, 0, 1\}^6 is a null twist when the rank is 6. They compare the cone test with a brute-force positive span test over all bases of rows, by Carathéodory's theorem.

Classic examples

  • The 3-2-1 locating principle. Three locators on the plane z=0z = 0, two on y=0y = 0 and one on x=0x = 0. The rank is 6 if and only if the first three are not collinear and the next two are not one above the other, and ∣det⁡J∣=2A ∣a2−a1∣|\det J| = 2A\,|a_2 - a_1|. For the block on that page, J−1(1,…,1)T=(1,1,1,0,0,0)J^{-1}(1, \dots, 1)^{\mathsf T} = (1, 1, 1, 0, 0, 0), a translation away from the corner that unloads the part.
  • A cylinder in a V-block. A shaft of radius 1 along the xx axis lies in a V-block with two contacts at x=0x = 0 and two at x=4x = 4, at the points (x,±35,−45)(x, \pm\tfrac35, -\tfrac45) with normals toward the axis, and an end stop at (0,15,0)(0, \tfrac15, 0) with normal (1,0,0)(1, 0, 0). The rank is 5 and the null twist is (0,0,0,1,0,0)(0, 0, 0, 1, 0, 0), a turn about the axis. This is not a bad choice of points: for a contact on the cylinder the normal meets the axis, and for a contact on a flat end the normal is parallel to the axis, so the column of ωx\omega_x is zero for every such contact. A sixth locator on a milled flat at (2,12,45)(2, \tfrac12, \tfrac45) with normal (0,0,−1)(0, 0, -1) gives rank 6.
  • Modular fixture design. In the plane a twist has three entries (δx,δy,ω)(\delta_x, \delta_y, \omega) and the rows are (nx,ny,pxny−pynx)(n_x, n_y, p_x n_y - p_y n_x). The Brost and Goldberg algorithm keeps a placement of three locators and a clamp only if the four rows have rank 3 and positively span R3\mathbb{R}^3, which is the planar form closure test of this page.
  • Infinitesimal rigidity of a bar framework is the same idea for a different body: the rows of the rigidity matrix are the gradients of the bar lengths, and the framework is rigid to first order if the rank is as large as possible.

Variations

  • Clamps and forces. The clamps add rows with the same form. With friction, each contact gives a cone of forces instead of one direction, and the question becomes force closure: can the contact forces resist every external wrench? A grasp wrench space measures how well.
  • Quality of a layout. Among layouts with rank 6, planners prefer a small error amplification, for example a large smallest singular value of JJ or a large det⁡(JTJ)\det(J^{\mathsf T} J). These are criteria for search over candidate locator positions, not part of the test.
  • Second order. When the rank is less than 6, the curvatures of the part and of the locators at the contacts decide whether the part is still held. A part with concave curvature at a contact can be immobilized by fewer contacts than the first-order count (Rimon and Burdick 1998, cited on fixture planning).
  • Bilateral contacts. A pin in a tight hole constrains motion in both senses. Its rows enter the rank test as usual, and in the cone test each such row is added with both signs.

Pitfalls

  • A full rank is not a hold. Rank 6 says the position is unique. It says nothing about whether the part stays there: with six locators it never does without a clamp.
  • Inward normals. The sign of nin_i does not change the rank, but it flips the cone test. Use one convention for all rows: here nin_i points from the locator into the part.
  • Floating point rank. Locator layouts are often exactly degenerate, for example three locators at equal heights on one line. A rank found with a floating point tolerance can report 6 for a layout that is singular. Exact arithmetic, or a tolerance tied to the size of the part, avoids this.
  • Surfaces of revolution. Contacts on a cylinder, a cone or a sphere cannot stop a turn about the axis, whatever their number, as the V-block shows. A flat, a keyway or a pin in a hole must take the last degree of freedom.
  • Points on edges and vertices. The model needs a tangent plane at each contact. At an edge or a vertex the normal is not defined, and a locator there must be modeled as two or three rows, or moved.

Code

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

kinematic_fixture_analysis.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/kinematic-fixture-analysis/. The authors are listed in prov/E79S9A.jsonl.

"""Kinematic fixture analysis in the sense of Asada and By (1985).

Model: a rigid part, frictionless point contacts, small motions. A contact
is a pair (p, n): the contact point p and the normal n that points from the
locator into the part. n need not have unit length; every answer here is
unchanged when a normal is scaled by a positive number.

A twist is xi = (dx, dy, dz, wx, wy, wz). The first-order change of the gap
at contact i is J_i . xi with J_i = (n_i, p_i x n_i).

All arithmetic is exact (Fraction), so a rank or a sign is never wrong
because of rounding.
"""

from collections import namedtuple
from fractions import Fraction
from itertools import combinations
from math import gcd

FixtureReport = namedtuple(
    "FixtureReport", ["rank", "deterministic", "null_twists", "detach_twist", "form_closure"]
)


def cross(a, b):
    return (
        a[1] * b[2] - a[2] * b[1],
        a[2] * b[0] - a[0] * b[2],
        a[0] * b[1] - a[1] * b[0],
    )


def dot(a, b):
    return sum(x * y for x, y in zip(a, b))


def jacobian(contacts):
    """The locator Jacobian: one row (n, p x n) per contact, as Fractions."""
    rows = []
    for p, n in contacts:
        m = cross(p, n)
        rows.append([Fraction(v) for v in (n[0], n[1], n[2], m[0], m[1], m[2])])  # @line L1
    return rows


def _echelon(rows, ncols):
    """Reduced row echelon form. Returns (matrix, pivot columns)."""
    a = [[Fraction(v) for v in r] for r in rows]
    pivots = []
    r = 0
    for c in range(ncols):
        if r == len(a):
            break
        piv = None
        for i in range(r, len(a)):
            if a[i][c] != 0:
                piv = i
                break
        if piv is None:
            continue
        a[r], a[piv] = a[piv], a[r]
        inv = 1 / a[r][c]
        a[r] = [v * inv for v in a[r]]
        for i in range(len(a)):
            if i != r and a[i][c] != 0:
                f = a[i][c]
                a[i] = [x - f * y for x, y in zip(a[i], a[r])]
        pivots.append(c)
        r += 1
    return a, pivots


def rank(rows, ncols=6):
    return len(_echelon(rows, ncols)[1])


def null_space(rows, ncols=6):
    """A basis of {x : rows x = 0}, each vector with integer entries."""
    a, pivots = _echelon(rows, ncols)
    free = [c for c in range(ncols) if c not in pivots]
    basis = []
    for f in free:
        x = [Fraction(0)] * ncols
        x[f] = Fraction(1)
        for i, c in enumerate(pivots):
            x[c] = -a[i][f]
        basis.append(_integer(x))
    return basis


def _integer(x):
    """Scale a rational vector by a positive number to coprime integers."""
    den = 1
    for v in x:
        den = den * v.denominator // gcd(den, v.denominator)
    ints = [int(v * den) for v in x]
    g = 0
    for v in ints:
        g = gcd(g, abs(v))
    if g > 1:
        ints = [v // g for v in ints]
    return [Fraction(v) for v in ints]


def solve_square(rows, b):
    """Solve rows x = b for a square invertible matrix; None if singular."""
    n = len(rows)
    aug = [list(r) + [Fraction(v)] for r, v in zip(rows, b)]
    a, pivots = _echelon(aug, n)
    if len(pivots) < n:
        return None
    return [a[i][n] for i in range(n)]


def apply(rows, xi):
    return [dot(r, xi) for r in rows]


def detach_twist(rows):
    """A twist xi with J xi >= 0 and J xi != 0, or None if there is none.

    If the cone spanned by the rows is not their whole span, it has a facet,
    and a facet contains rank - 1 independent rows. The twists that are
    orthogonal to those rows give, modulo the null space of J, a single
    line of gap vectors J xi, and one of its two directions is >= 0.
    So trying every independent set of rank - 1 rows finds a detaching
    twist whenever one exists.
    """
    r = rank(rows)
    if r == 0:
        return None
    for subset in combinations(range(len(rows)), r - 1):  # @line L4
        sub = [rows[i] for i in subset]
        if rank(sub) != r - 1:
            continue
        for b in null_space(sub):  # @line L5
            g = apply(rows, b)
            if all(v == 0 for v in g):
                continue
            if all(v >= 0 for v in g):  # @line L6
                return b
            if all(v <= 0 for v in g):  # @line L7
                return [-v for v in b]
            break
    return None  # @line L8


def analyze(contacts):
    """Rank, first-order determinism, and loading or unloading of a fixture.

    deterministic: rank J = 6, so J xi = 0 only for xi = 0.
    null_twists: a basis of the twists that change no gap to first order.
    detach_twist: a twist that opens some gap and closes none, or None.
    form_closure: deterministic and no detaching twist, so the contacts
    alone stop every small motion.
    """
    rows = jacobian(contacts)
    r = rank(rows)  # @line L2
    nulls = null_space(rows) if r < 6 else []  # @line L3
    d = detach_twist(rows)
    return FixtureReport(r, r == 6, nulls, d, r == 6 and d is None)


def error_twist(contacts, errors):
    """For six locators with rank 6: the twist that a set of small locator
    errors causes, the solution of J xi = errors. None if J is singular."""
    rows = jacobian(contacts)
    if len(rows) != 6:
        raise ValueError("error_twist needs exactly six locators")
    return solve_square(rows, errors)
test_kinematic_fixture_analysis.py 299 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/kinematic-fixture-analysis/. The authors are listed in prov/E79S9A.jsonl.

import random
import unittest
from fractions import Fraction
from itertools import combinations, product

from kinematic_fixture_analysis import (
    analyze,
    apply,
    cross,
    detach_twist,
    dot,
    error_twist,
    jacobian,
    rank,
)

# Faces of the box [0, 2]^3: (axis, value, inward normal).
FACES = [
    (0, 0, (1, 0, 0)),
    (0, 2, (-1, 0, 0)),
    (1, 0, (0, 1, 0)),
    (1, 2, (0, -1, 0)),
    (2, 0, (0, 0, 1)),
    (2, 2, (0, 0, -1)),
]

EZ, EY, EX = (0, 0, 1), (0, 1, 0), (1, 0, 0)
BLOCK = [
    ((20, 10, 0), EZ),
    ((80, 10, 0), EZ),
    ((50, 50, 0), EZ),
    ((20, 0, 20), EY),
    ((80, 0, 20), EY),
    ((0, 30, 20), EX),
]
CLAMPS = [((100, 30, 20), (-1, 0, 0)), ((50, 60, 20), (0, -1, 0)), ((50, 30, 40), (0, 0, -1))]


def box_contact(rng):
    axis, value, n = rng.choice(FACES)
    p = [rng.randint(0, 2) for _ in range(3)]
    p[axis] = value
    return (tuple(p), n)


def det(m):
    """Determinant by Laplace expansion along the first row."""
    if len(m) == 1:
        return m[0][0]
    total = 0
    for j in range(len(m)):
        if m[0][j] == 0:
            continue
        minor = [row[:j] + row[j + 1 :] for row in m[1:]]
        total += (-1) ** j * m[0][j] * det(minor)
    return total


def rank_by_minors(rows):
    """The largest k with a nonzero k x k minor."""
    for k in range(min(len(rows), 6), 0, -1):
        for rs in combinations(range(len(rows)), k):
            for cs in combinations(range(6), k):
                if det([[rows[r][c] for c in cs] for r in rs]) != 0:
                    return k
    return 0


def cayley(w):
    """The exact rational rotation (I - C)^-1 (I + C) with C = [w / 2]x."""
    c = [Fraction(v) / 2 for v in w]
    s = 2 / (1 + dot(c, c))
    cm = [[0, -c[2], c[1]], [c[2], 0, -c[0]], [-c[1], c[0], 0]]
    c2 = [[sum(cm[i][k] * cm[k][j] for k in range(3)) for j in range(3)] for i in range(3)]
    return [[int(i == j) + s * (cm[i][j] + c2[i][j]) for j in range(3)] for i in range(3)]


def mat_vec(r, v):
    return [sum(r[i][k] * v[k] for k in range(3)) for i in range(3)]


def finite_gaps(contacts, xi, t):
    """The gaps after the finite rigid motion R = cayley(t w), d = t delta.

    The part surface at contact i is the plane through p_i with normal n_i.
    After the motion it is the plane through R p_i + d with normal R n_i,
    and the gap is the signed distance of the fixed locator p_i from it,
    times |n_i|.
    """
    delta = [t * v for v in xi[:3]]
    r = cayley([t * v for v in xi[3:]])
    gaps = []
    for p, n in contacts:
        moved = mat_vec(r, p)
        rn = mat_vec(r, n)
        gaps.append(dot(rn, [moved[k] + delta[k] - p[k] for k in range(3)]))
    return gaps


def in_cone(rows, target, r):
    """Is target a nonnegative combination of rows? (Caratheodory: try every
    basis of r rows of the span; target is assumed to lie in the span.)"""
    for subset in combinations(range(len(rows)), r):
        cols = [rows[i] for i in subset]
        aug = [[cols[j][k] for j in range(r)] + [target[k]] for k in range(6)]
        coeffs = _solve_consistent(aug, r)
        if coeffs is not None and all(c >= 0 for c in coeffs):
            return True
    return False


def _solve_consistent(aug, r):
    """Solve a 6 x r system with full column rank, or None if the columns are dependent."""
    a = [list(row) for row in aug]
    row = 0
    for c in range(r):
        piv = next((i for i in range(row, 6) if a[i][c] != 0), None)
        if piv is None:
            return None
        a[row], a[piv] = a[piv], a[row]
        a[row] = [v / a[row][c] for v in a[row]]
        for i in range(6):
            if i != row and a[i][c] != 0:
                f = a[i][c]
                a[i] = [x - f * y for x, y in zip(a[i], a[row])]
        row += 1
    return [a[i][r] for i in range(r)]


def positively_spans_its_span(rows):
    r = rank(rows)
    return all(in_cone(rows, [-v for v in w], r) for w in rows)


class TestWorkedBlock(unittest.TestCase):
    def test_rank_and_det(self):
        j = jacobian(BLOCK)
        self.assertEqual(j[0], [0, 0, 1, 10, -20, 0])
        self.assertEqual(rank(j), 6)
        self.assertEqual(abs(det(j)), 144000)  # 2 * area 1200 * spacing 60

    def test_locating_is_not_holding(self):
        rep = analyze(BLOCK)
        self.assertTrue(rep.deterministic)
        self.assertFalse(rep.form_closure)
        g = apply(jacobian(BLOCK), rep.detach_twist)
        self.assertTrue(all(v >= 0 for v in g) and any(v > 0 for v in g))
        self.assertEqual(error_twist(BLOCK, [1] * 6), [1, 1, 1, 0, 0, 0])

    def test_error_amplification(self):
        xi = error_twist(BLOCK, [0, 0, 0, 0, Fraction(1, 100), 0])
        self.assertEqual(xi[5], Fraction(1, 6000))  # 0.01 / 60

    def test_clamps(self):
        self.assertFalse(analyze(BLOCK + CLAMPS[2:]).form_closure)
        self.assertTrue(analyze(BLOCK + CLAMPS).form_closure)

    def test_degenerate_layouts(self):
        collinear = list(BLOCK)
        collinear[2] = ((50, 10, 0), EZ)
        rep = analyze(collinear)
        self.assertEqual(rep.rank, 5)
        self.assertEqual(rep.null_twists, [[0, 20, -10, 1, 0, 0]])
        stacked = list(BLOCK)
        stacked[4] = ((20, 0, 30), EY)
        rep = analyze(stacked)
        self.assertEqual(rep.rank, 5)
        self.assertEqual(rep.null_twists, [[30, -20, 0, 0, 0, 1]])


class TestVBlock(unittest.TestCase):
    def test_cylinder_turns_about_its_axis(self):
        a, b = Fraction(3, 5), Fraction(4, 5)
        vee = [
            ((0, a, -b), (0, -a, b)),
            ((0, -a, -b), (0, a, b)),
            ((4, a, -b), (0, -a, b)),
            ((4, -a, -b), (0, a, b)),
            ((0, Fraction(1, 5), 0), (1, 0, 0)),
        ]
        rep = analyze(vee)
        self.assertEqual(rep.rank, 5)
        self.assertEqual(rep.null_twists, [[0, 0, 0, 1, 0, 0]])
        flat = ((2, Fraction(1, 2), b), (0, 0, -1))
        self.assertEqual(analyze(vee + [flat]).rank, 6)


class TestAgainstBruteForce(unittest.TestCase):
    def test_rank_matches_minors(self):
        rng = random.Random(7)
        for _ in range(60):
            contacts = [box_contact(rng) for _ in range(rng.randint(1, 7))]
            j = jacobian(contacts)
            self.assertEqual(rank(j), rank_by_minors(j))

    def test_first_order_gaps(self):
        """The finite motion of size t changes gap i by t J_i xi + O(t^2)."""
        rng = random.Random(11)
        t = Fraction(1, 10**6)
        for _ in range(40):
            contacts = [box_contact(rng) for _ in range(6)]
            xi = [rng.randint(-3, 3) for _ in range(6)]
            first = apply(jacobian(contacts), xi)
            for g, f in zip(finite_gaps(contacts, xi, t), first):
                self.assertLess(abs(g / t - f), Fraction(1, 1000))

    def test_null_twists_move_no_gap(self):
        rng = random.Random(3)
        t = Fraction(1, 10**6)
        seen = 0
        for _ in range(60):
            contacts = [box_contact(rng) for _ in range(rng.randint(3, 7))]
            rep = analyze(contacts)
            self.assertEqual(rep.deterministic, rep.rank == 6)
            self.assertEqual(len(rep.null_twists), 6 - rep.rank)
            for xi in rep.null_twists:
                seen += 1
                self.assertTrue(any(v != 0 for v in xi))
                for g in finite_gaps(contacts, xi, t):
                    self.assertLess(abs(g / t), Fraction(1, 1000))
        self.assertGreater(seen, 20)

    def test_full_rank_has_no_grid_null_twist(self):
        """Search all twists in {-1, 0, 1}^6 with exact finite motions."""
        rng = random.Random(5)
        t = Fraction(1, 10**6)
        grid = [xi for xi in product((-1, 0, 1), repeat=6) if any(xi)]
        done = 0
        while done < 4:
            contacts = [box_contact(rng) for _ in range(6)]
            j = jacobian(contacts)
            if rank(j) != 6:
                continue
            done += 1
            for xi in grid:
                if all(v == 0 for v in apply(j, xi)):
                    self.fail("full rank but a null twist")
            xi = grid[rng.randrange(len(grid))]
            gaps = finite_gaps(contacts, xi, t)
            self.assertTrue(any(abs(g / t) > Fraction(1, 2) for g in gaps))

    def test_detach_matches_positive_span(self):
        """Stiemke: no detaching twist exactly when the rows positively span their span."""
        rng = random.Random(13)
        closed = 0
        for trial in range(80):
            contacts = [box_contact(rng) for _ in range(rng.randint(2, 8))]
            if trial % 2:
                # Pair some contacts with the point straight across the box:
                # the two rows are opposite, so the cone holds a line.
                for p, n in contacts[: rng.randint(1, 4)]:
                    axis = [abs(v) for v in n].index(1)
                    q = list(p)
                    q[axis] = 2 - q[axis]
                    contacts.append((tuple(q), tuple(-v for v in n)))
            j = jacobian(contacts)
            d = detach_twist(j)
            if d is not None:
                g = apply(j, d)
                self.assertTrue(all(v >= 0 for v in g) and any(v > 0 for v in g))
            self.assertEqual(d is None, positively_spans_its_span(j))
            closed += d is None
        self.assertGreater(closed, 0)
        for contacts, expect in ((BLOCK + CLAMPS, True), (BLOCK + CLAMPS[2:], False)):
            j = jacobian(contacts)
            self.assertEqual(positively_spans_its_span(j), expect)
            self.assertEqual(detach_twist(j) is None, expect)

    def test_six_contacts_never_close(self):
        rng = random.Random(17)
        for _ in range(40):
            contacts = [box_contact(rng) for _ in range(6)]
            self.assertFalse(analyze(contacts).form_closure)

    def test_positive_scaling_and_order(self):
        rng = random.Random(19)
        for _ in range(20):
            contacts = [box_contact(rng) for _ in range(rng.randint(4, 8))]
            rep = analyze(contacts)
            scaled = [(p, tuple(3 * v for v in n)) for p, n in contacts]
            shuffled = list(contacts)
            rng.shuffle(shuffled)
            for other in (scaled, shuffled):
                rep2 = analyze(other)
                self.assertEqual(rep.rank, rep2.rank)
                self.assertEqual(rep.form_closure, rep2.form_closure)
                self.assertEqual(rep.detach_twist is None, rep2.detach_twist is None)

    def test_cross_product_rows(self):
        p, n = (1, 2, 0), (0, 0, 1)
        self.assertEqual(cross(p, n), (2, -1, 0))
        self.assertEqual(jacobian([(p, n)])[0], [0, 0, 1, 2, -1, 0])


if __name__ == "__main__":
    unittest.main()

Exercises

  1. Show that for the planar model the rows (nx,ny,pxny−pynx)(n_x, n_y, p_x n_y - p_y n_x) of three contacts have rank less than 3 if the three normal lines meet in one point or are all parallel. (Hint: the meeting point is the center of a turn that moves each contact along its tangent.)
  2. Three locators on z=0z = 0 at (0,0,0)(0, 0, 0), (2,0,0)(2, 0, 0), (0,2,0)(0, 2, 0), two on y=0y = 0 at (0,0,1)(0, 0, 1) and (2,0,1)(2, 0, 1), and one on x=0x = 0 at (0,1,1)(0, 1, 1). Compute ∣det⁡J∣|\det J| with the formula of the 3-2-1 page. (Answer: 2⋅2⋅2=82 \cdot 2 \cdot 2 = 8.)
  3. A part is held by eight contacts whose rows come in four pairs JiJ_i and −Ji-J_i. Show that it has no detaching twist, and say when it is deterministic.

References

  1. Haruhiko Asada and Andre B. By, Kinematic analysis of workpart fixturing for flexible assembly with automatically reconfigurable fixtures, IEEE Journal of Robotics and Automation 1(2), 1985, 86 to 94, the locator Jacobian of frictionless point contacts, deterministic positioning as rank 6, and the accessibility and detachability conditions for loading and unloading
  2. Alexander Schrijver, Theory of Linear and Integer Programming, Wiley, 1986 (paperback 1998), Chapter 7 (Farkas' lemma and its variants) and Chapter 8 (the structure of polyhedra, faces and extreme rays of cones)
  3. Xanthippi Markenscoff, Luqun Ni and Christos H. Papadimitriou, The geometry of grasping, International Journal of Robotics Research 9(1), 1990, 61 to 74, frictionless form closure needs and, for almost all parts, can be had with 4 contacts in the plane and 7 in space

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • five exercises