---
url: /dyad/stable/stdlib/MultibodyComponents/components/RevoluteWithLengthConstraint.md
description: >-
  Dyad RevoluteWithLengthConstraint docs.  Revolute joint whose angle is
  determined analytically by a length constraint rather than being a free state.
  Used internally by JointUSR (an...
---

# `RevoluteWithLengthConstraint` {#RevoluteWithLengthConstraint}

Revolute joint whose angle is determined analytically by a length constraint rather than being a free state. Used internally by `JointUSR` (and similar joint assemblies) to solve a kinematic loop in closed form.

The position vectors to the two sides of the length constraint, `r_a` (resolved in `frame_a`) and `r_b` (resolved in `frame_b`), are supplied by the enclosing assembly. Given the fixed `length_constraint`, the joint angle is computed with `compute_angle`, which has two solutions (elbow up/down). Which one the mechanism is assembled in is determined automatically at initialization: `branch_sign` is solved for from the initial geometry as the solution closest to `phi_offset + phi_guess`, and stays fixed for the rest of the simulation. Set `positive_branch` to bypass that and force a branch.

This component is not balanced on its own — `r_a` and `r_b` are inputs that the parent assembly must drive. It is not intended to be used standalone.

This component extends from [`PartialTwoFrames`](../types/PartialTwoFrames.md)

## Usage {#Usage}

`MultibodyComponents.RevoluteWithLengthConstraint(branch_sign=missing, n=[0, 0, 1], n_sparse=[n[1] * n_nonzero[1], n[2] * n_nonzero[2], n[3] * n_nonzero[3]], phi_offset=0, phi_guess=0, length_constraint=1, e=n_sparse / norm_(n_sparse))`

## Parameters: {#Parameters:}

|                Name |                                                                                                                                                                      Description | Units |      Default value |
| -------------------:| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| -----:| ------------------:|
|   `positive_branch` |                                                              Force the elbow-up (`true`) or elbow-down (`false`) solution instead of selecting it automatically from `phi_guess` |     – |            missing |
|         `n_nonzero` |    Structural sparsity mask for the axis: components marked false are assembled as literal zeros (clean axis\*axis' in the Rodrigues formula). Must be set consistently with `n`. |     – | \[true, true, true] |
|       `branch_sign` | Sign of the square-root term picking the branch of the loop-closure solution. Determined at initialization, do not set (use `phi_guess`, or `positive_branch` to force a branch) |     – |            missing |
|                 `n` |                                                                                                                                    Axis of rotation, resolved in frame_a/frame_b |     – |          \[0, 0, 1] |
|        `phi_offset` |                                                                                                                                 Relative angle offset (angle = phi + phi_offset) |     – |                  0 |
|         `phi_guess` |                                                                                                             Guess value for the revolute angle, used to select the configuration |     – |                  0 |
| `length_constraint` |                                                                                                                                            Fixed length of the length constraint |     – |                  1 |

## Connectors {#Connectors}

* `frame_a` - Frame3D is the fundamental 3D connector used for 6DOF motion. Most components have one or several `Frame`

connectors that can be connected together ([`Frame3D`](/stdlib/Dyad/connectors/Frame3D#Frame3D))

* `frame_b` - Frame3D is the fundamental 3D connector used for 6DOF motion. Most components have one or several `Frame`

connectors that can be connected together ([`Frame3D`](/stdlib/Dyad/connectors/Frame3D#Frame3D))

* `axis` - This connector represents a rotational spline with angle and torque as the potential and flow variables, respectively. ([`Spline`](/stdlib/Dyad/connectors/Spline#Spline))

* `bearing` - This connector represents a rotational spline with angle and torque as the potential and flow variables, respectively. ([`Spline`](/stdlib/Dyad/connectors/Spline#Spline))

## Variables {#Variables}

|    Name |                                                                       Description | Units |
| -------:| ---------------------------------------------------------------------------------:| -----:|
|   `tau` |                                   Driving torque in direction of axis of rotation |   N.m |
|   `phi` |                                   Relative rotation angle from frame_a to frame_b |   rad |
| `angle` |                                                                = phi + phi_offset |   rad |
|   `r_a` | Position vector to the frame_a side of the length constraint, resolved in frame_a |     m |
|   `r_b` | Position vector to the frame_b side of the length constraint, resolved in frame_b |     m |

## Behavior {#Behavior}

$$ \begin{align}
\mathtt{angle}\left( t \right) &= \mathtt{phi}\left( t \right) + \mathtt{phi_offset} \\
\mathtt{axis.phi}\left( t \right) &= \mathtt{phi}\left( t \right) \\
\mathtt{axis.tau}\left( t \right) &= \mathtt{tau}\left( t \right) \\
\mathtt{bearing.phi}\left( t \right) &= 0 \\
\mathtt{frame_b.r_0}\_{1}\left( t \right) &= \mathtt{frame_a.r_0}\_{1}\left( t \right) \\
\mathtt{frame_b.r_0}\_{2}\left( t \right) &= \mathtt{frame_a.r_0}\_{2}\left( t \right) \\
\mathtt{frame_b.r_0}\_{3}\left( t \right) &= \mathtt{frame_a.r_0}\_{3}\left( t \right) \\
\mathtt{frame_b.R}\_{1,1}\left( t \right) &= \left( \left( e\_{1} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{1} \right)^{2} \right) \right) ~ \mathtt{frame_a.R}\_{1,1}\left( t \right) + \left( e\_{1} ~ e\_{2} + e\_{3} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{2} \right) ~ \mathtt{frame_a.R}\_{2,1}\left( t \right) + \left( e\_{1} ~ e\_{3} - e\_{2} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{3,1}\left( t \right) \\
\mathtt{frame_b.R}\_{2,1}\left( t \right) &= \left( e\_{1} ~ e\_{2} - e\_{3} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{2} \right) ~ \mathtt{frame_a.R}\_{1,1}\left( t \right) + \left( \left( e\_{2} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{2} \right)^{2} \right) \right) ~ \mathtt{frame_a.R}\_{2,1}\left( t \right) + \left( e\_{1} ~ \sin\left( \mathtt{angle}\left( t \right) \right) + e\_{2} ~ e\_{3} - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{2} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{3,1}\left( t \right) \\
\mathtt{frame_b.R}\_{3,1}\left( t \right) &= \left( e\_{1} ~ e\_{3} + e\_{2} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{1,1}\left( t \right) + \left(  - e\_{1} ~ \sin\left( \mathtt{angle}\left( t \right) \right) + e\_{2} ~ e\_{3} - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{2} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{2,1}\left( t \right) + \left( \left( e\_{3} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{3} \right)^{2} \right) \right) ~ \mathtt{frame_a.R}\_{3,1}\left( t \right) \\
\mathtt{frame_b.R}\_{1,2}\left( t \right) &= \left( \left( e\_{1} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{1} \right)^{2} \right) \right) ~ \mathtt{frame_a.R}\_{1,2}\left( t \right) + \left( e\_{1} ~ e\_{2} + e\_{3} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{2} \right) ~ \mathtt{frame_a.R}\_{2,2}\left( t \right) + \left( e\_{1} ~ e\_{3} - e\_{2} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{3,2}\left( t \right) \\
\mathtt{frame_b.R}\_{2,2}\left( t \right) &= \left( e\_{1} ~ e\_{2} - e\_{3} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{2} \right) ~ \mathtt{frame_a.R}\_{1,2}\left( t \right) + \left( \left( e\_{2} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{2} \right)^{2} \right) \right) ~ \mathtt{frame_a.R}\_{2,2}\left( t \right) + \left( e\_{1} ~ \sin\left( \mathtt{angle}\left( t \right) \right) + e\_{2} ~ e\_{3} - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{2} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{3,2}\left( t \right) \\
\mathtt{frame_b.R}\_{3,2}\left( t \right) &= \left( e\_{1} ~ e\_{3} + e\_{2} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{1,2}\left( t \right) + \left(  - e\_{1} ~ \sin\left( \mathtt{angle}\left( t \right) \right) + e\_{2} ~ e\_{3} - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{2} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{2,2}\left( t \right) + \left( \left( e\_{3} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{3} \right)^{2} \right) \right) ~ \mathtt{frame_a.R}\_{3,2}\left( t \right) \\
\mathtt{frame_b.R}\_{1,3}\left( t \right) &= \left( \left( e\_{1} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{1} \right)^{2} \right) \right) ~ \mathtt{frame_a.R}\_{1,3}\left( t \right) + \left( e\_{1} ~ e\_{2} + e\_{3} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{2} \right) ~ \mathtt{frame_a.R}\_{2,3}\left( t \right) + \left( e\_{1} ~ e\_{3} - e\_{2} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{3,3}\left( t \right) \\
\mathtt{frame_b.R}\_{2,3}\left( t \right) &= \left( e\_{1} ~ e\_{2} - e\_{3} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{2} \right) ~ \mathtt{frame_a.R}\_{1,3}\left( t \right) + \left( \left( e\_{2} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{2} \right)^{2} \right) \right) ~ \mathtt{frame_a.R}\_{2,3}\left( t \right) + \left( e\_{1} ~ \sin\left( \mathtt{angle}\left( t \right) \right) + e\_{2} ~ e\_{3} - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{2} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{3,3}\left( t \right) \\
\mathtt{frame_b.R}\_{3,3}\left( t \right) &= \left( e\_{1} ~ e\_{3} + e\_{2} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{1,3}\left( t \right) + \left(  - e\_{1} ~ \sin\left( \mathtt{angle}\left( t \right) \right) + e\_{2} ~ e\_{3} - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{2} ~ e\_{3} \right) ~ \mathtt{frame_a.R}\_{2,3}\left( t \right) + \left( \left( e\_{3} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{3} \right)^{2} \right) \right) ~ \mathtt{frame_a.R}\_{3,3}\left( t \right) \\
0 &= \mathtt{frame_a.f}\_{1}\left( t \right) + \left( \left( e\_{1} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{1} \right)^{2} \right) \right) ~ \mathtt{frame_b.f}\_{1}\left( t \right) + \left( e\_{1} ~ e\_{2} - e\_{3} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{2} \right) ~ \mathtt{frame_b.f}\_{2}\left( t \right) + \left( e\_{1} ~ e\_{3} + e\_{2} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{3} \right) ~ \mathtt{frame_b.f}\_{3}\left( t \right) \\
0 &= \mathtt{frame_a.f}\_{2}\left( t \right) + \left( e\_{1} ~ e\_{2} + e\_{3} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{2} \right) ~ \mathtt{frame_b.f}\_{1}\left( t \right) + \left( \left( e\_{2} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{2} \right)^{2} \right) \right) ~ \mathtt{frame_b.f}\_{2}\left( t \right) + \left(  - e\_{1} ~ \sin\left( \mathtt{angle}\left( t \right) \right) + e\_{2} ~ e\_{3} - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{2} ~ e\_{3} \right) ~ \mathtt{frame_b.f}\_{3}\left( t \right) \\
0 &= \mathtt{frame_a.f}\_{3}\left( t \right) + \left( e\_{1} ~ e\_{3} - e\_{2} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{3} \right) ~ \mathtt{frame_b.f}\_{1}\left( t \right) + \left( e\_{1} ~ \sin\left( \mathtt{angle}\left( t \right) \right) + e\_{2} ~ e\_{3} - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{2} ~ e\_{3} \right) ~ \mathtt{frame_b.f}\_{2}\left( t \right) + \left( \left( e\_{3} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{3} \right)^{2} \right) \right) ~ \mathtt{frame_b.f}\_{3}\left( t \right) \\
0 &= \mathtt{frame_a.tau}\_{1}\left( t \right) + \left( \left( e\_{1} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{1} \right)^{2} \right) \right) ~ \mathtt{frame_b.tau}\_{1}\left( t \right) + \left( e\_{1} ~ e\_{2} - e\_{3} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{2} \right) ~ \mathtt{frame_b.tau}\_{2}\left( t \right) + \left( e\_{1} ~ e\_{3} + e\_{2} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{3} \right) ~ \mathtt{frame_b.tau}\_{3}\left( t \right) \\
0 &= \mathtt{frame_a.tau}\_{2}\left( t \right) + \left( e\_{1} ~ e\_{2} + e\_{3} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{2} \right) ~ \mathtt{frame_b.tau}\_{1}\left( t \right) + \left( \left( e\_{2} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{2} \right)^{2} \right) \right) ~ \mathtt{frame_b.tau}\_{2}\left( t \right) + \left(  - e\_{1} ~ \sin\left( \mathtt{angle}\left( t \right) \right) + e\_{2} ~ e\_{3} - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{2} ~ e\_{3} \right) ~ \mathtt{frame_b.tau}\_{3}\left( t \right) \\
0 &= \mathtt{frame_a.tau}\_{3}\left( t \right) + \left( e\_{1} ~ e\_{3} - e\_{2} ~ \sin\left( \mathtt{angle}\left( t \right) \right) - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{1} ~ e\_{3} \right) ~ \mathtt{frame_b.tau}\_{1}\left( t \right) + \left( e\_{1} ~ \sin\left( \mathtt{angle}\left( t \right) \right) + e\_{2} ~ e\_{3} - \cos\left( \mathtt{angle}\left( t \right) \right) ~ e\_{2} ~ e\_{3} \right) ~ \mathtt{frame_b.tau}\_{2}\left( t \right) + \left( \left( e\_{3} \right)^{2} + \cos\left( \mathtt{angle}\left( t \right) \right) ~ \left( 1 - \left( e\_{3} \right)^{2} \right) \right) ~ \mathtt{frame_b.tau}\_{3}\left( t \right) \\
\mathtt{angle}\left( t \right) &= \arctan\left( 2 ~ \mathtt{branch_sign} ~ \left( \mathtt{r_a}\_{1}\left( t \right) ~ \mathtt{r_b}\_{1}\left( t \right) + \mathtt{r_a}\_{2}\left( t \right) ~ \mathtt{r_b}\_{2}\left( t \right) + \mathtt{r_a}\_{3}\left( t \right) ~ \mathtt{r_b}\_{3}\left( t \right) - \left( e\_{1} ~ \mathtt{r_a}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_a}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{3}\left( t \right) \right) ~ \left( e\_{1} ~ \mathtt{r_b}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_b}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_b}\_{3}\left( t \right) \right) \right) ~ \sqrt{max\left( 4 ~ \left( \left( e\_{1} ~ \mathtt{r_a}\_{2}\left( t \right) - e\_{2} ~ \mathtt{r_a}\_{1}\left( t \right) \right) ~ \mathtt{r_b}\_{3}\left( t \right) + \left(  - e\_{1} ~ \mathtt{r_a}\_{3}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{1}\left( t \right) \right) ~ \mathtt{r_b}\_{2}\left( t \right) + \left( e\_{2} ~ \mathtt{r_a}\_{3}\left( t \right) - e\_{3} ~ \mathtt{r_a}\_{2}\left( t \right) \right) ~ \mathtt{r_b}\_{1}\left( t \right) \right)^{2} - \left(  - \mathtt{length_constraint}^{2} + \mathtt{r_a}\_{1}\left( t \right)^{2} + \mathtt{r_a}\_{2}\left( t \right)^{2} + \mathtt{r_a}\_{3}\left( t \right)^{2} + \mathtt{r_b}\_{1}\left( t \right)^{2} + \mathtt{r_b}\_{2}\left( t \right)^{2} + \mathtt{r_b}\_{3}\left( t \right)^{2} - 2 ~ \left( e\_{1} ~ \mathtt{r_a}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_a}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{3}\left( t \right) \right) ~ \left( e\_{1} ~ \mathtt{r_b}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_b}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_b}\_{3}\left( t \right) \right) \right)^{2} + 4 ~ \left( \mathtt{r_a}\_{1}\left( t \right) ~ \mathtt{r_b}\_{1}\left( t \right) + \mathtt{r_a}\_{2}\left( t \right) ~ \mathtt{r_b}\_{2}\left( t \right) + \mathtt{r_a}\_{3}\left( t \right) ~ \mathtt{r_b}\_{3}\left( t \right) - \left( e\_{1} ~ \mathtt{r_a}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_a}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{3}\left( t \right) \right) ~ \left( e\_{1} ~ \mathtt{r_b}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_b}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_b}\_{3}\left( t \right) \right) \right)^{2}, 1 \cdot 10^{-12} \right)} - 2 ~ \left(  - \mathtt{length_constraint}^{2} + \mathtt{r_a}\_{1}\left( t \right)^{2} + \mathtt{r_a}\_{2}\left( t \right)^{2} + \mathtt{r_a}\_{3}\left( t \right)^{2} + \mathtt{r_b}\_{1}\left( t \right)^{2} + \mathtt{r_b}\_{2}\left( t \right)^{2} + \mathtt{r_b}\_{3}\left( t \right)^{2} - 2 ~ \left( e\_{1} ~ \mathtt{r_a}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_a}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{3}\left( t \right) \right) ~ \left( e\_{1} ~ \mathtt{r_b}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_b}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_b}\_{3}\left( t \right) \right) \right) ~ \left( \left( e\_{1} ~ \mathtt{r_a}\_{2}\left( t \right) - e\_{2} ~ \mathtt{r_a}\_{1}\left( t \right) \right) ~ \mathtt{r_b}\_{3}\left( t \right) + \left(  - e\_{1} ~ \mathtt{r_a}\_{3}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{1}\left( t \right) \right) ~ \mathtt{r_b}\_{2}\left( t \right) + \left( e\_{2} ~ \mathtt{r_a}\_{3}\left( t \right) - e\_{3} ~ \mathtt{r_a}\_{2}\left( t \right) \right) ~ \mathtt{r_b}\_{1}\left( t \right) \right), 2 ~ \mathtt{branch_sign} ~ \left( \left( e\_{1} ~ \mathtt{r_a}\_{2}\left( t \right) - e\_{2} ~ \mathtt{r_a}\_{1}\left( t \right) \right) ~ \mathtt{r_b}\_{3}\left( t \right) + \left(  - e\_{1} ~ \mathtt{r_a}\_{3}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{1}\left( t \right) \right) ~ \mathtt{r_b}\_{2}\left( t \right) + \left( e\_{2} ~ \mathtt{r_a}\_{3}\left( t \right) - e\_{3} ~ \mathtt{r_a}\_{2}\left( t \right) \right) ~ \mathtt{r_b}\_{1}\left( t \right) \right) ~ \sqrt{max\left( 4 ~ \left( \left( e\_{1} ~ \mathtt{r_a}\_{2}\left( t \right) - e\_{2} ~ \mathtt{r_a}\_{1}\left( t \right) \right) ~ \mathtt{r_b}\_{3}\left( t \right) + \left(  - e\_{1} ~ \mathtt{r_a}\_{3}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{1}\left( t \right) \right) ~ \mathtt{r_b}\_{2}\left( t \right) + \left( e\_{2} ~ \mathtt{r_a}\_{3}\left( t \right) - e\_{3} ~ \mathtt{r_a}\_{2}\left( t \right) \right) ~ \mathtt{r_b}\_{1}\left( t \right) \right)^{2} - \left(  - \mathtt{length_constraint}^{2} + \mathtt{r_a}\_{1}\left( t \right)^{2} + \mathtt{r_a}\_{2}\left( t \right)^{2} + \mathtt{r_a}\_{3}\left( t \right)^{2} + \mathtt{r_b}\_{1}\left( t \right)^{2} + \mathtt{r_b}\_{2}\left( t \right)^{2} + \mathtt{r_b}\_{3}\left( t \right)^{2} - 2 ~ \left( e\_{1} ~ \mathtt{r_a}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_a}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{3}\left( t \right) \right) ~ \left( e\_{1} ~ \mathtt{r_b}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_b}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_b}\_{3}\left( t \right) \right) \right)^{2} + 4 ~ \left( \mathtt{r_a}\_{1}\left( t \right) ~ \mathtt{r_b}\_{1}\left( t \right) + \mathtt{r_a}\_{2}\left( t \right) ~ \mathtt{r_b}\_{2}\left( t \right) + \mathtt{r_a}\_{3}\left( t \right) ~ \mathtt{r_b}\_{3}\left( t \right) - \left( e\_{1} ~ \mathtt{r_a}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_a}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{3}\left( t \right) \right) ~ \left( e\_{1} ~ \mathtt{r_b}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_b}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_b}\_{3}\left( t \right) \right) \right)^{2}, 1 \cdot 10^{-12} \right)} + 2 ~ \left( \mathtt{r_a}\_{1}\left( t \right) ~ \mathtt{r_b}\_{1}\left( t \right) + \mathtt{r_a}\_{2}\left( t \right) ~ \mathtt{r_b}\_{2}\left( t \right) + \mathtt{r_a}\_{3}\left( t \right) ~ \mathtt{r_b}\_{3}\left( t \right) - \left( e\_{1} ~ \mathtt{r_a}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_a}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{3}\left( t \right) \right) ~ \left( e\_{1} ~ \mathtt{r_b}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_b}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_b}\_{3}\left( t \right) \right) \right) ~ \left(  - \mathtt{length_constraint}^{2} + \mathtt{r_a}\_{1}\left( t \right)^{2} + \mathtt{r_a}\_{2}\left( t \right)^{2} + \mathtt{r_a}\_{3}\left( t \right)^{2} + \mathtt{r_b}\_{1}\left( t \right)^{2} + \mathtt{r_b}\_{2}\left( t \right)^{2} + \mathtt{r_b}\_{3}\left( t \right)^{2} - 2 ~ \left( e\_{1} ~ \mathtt{r_a}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_a}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_a}\_{3}\left( t \right) \right) ~ \left( e\_{1} ~ \mathtt{r_b}\_{1}\left( t \right) + e\_{2} ~ \mathtt{r_b}\_{2}\left( t \right) + e\_{3} ~ \mathtt{r_b}\_{3}\left( t \right) \right) \right) \right)
\end{align}
$$

## Source {#Source}

```dyad
"""
Revolute joint whose angle is determined analytically by a length constraint
rather than being a free state. Used internally by `JointUSR` (and similar
joint assemblies) to solve a kinematic loop in closed form.

The position vectors to the two sides of the length constraint, `r_a` (resolved
in `frame_a`) and `r_b` (resolved in `frame_b`), are supplied by the enclosing
assembly. Given the fixed `length_constraint`, the joint angle is computed with
`compute_angle`, which has two solutions (elbow up/down). Which one the mechanism
is assembled in is determined automatically at initialization: `branch_sign` is
solved for from the initial geometry as the solution closest to
`phi_offset + phi_guess`, and stays fixed for the rest of the simulation. Set
`positive_branch` to bypass that and force a branch.

This component is not balanced on its own — `r_a` and `r_b` are inputs that the
parent assembly must drive. It is not intended to be used standalone.
"""
component RevoluteWithLengthConstraint
  extends PartialTwoFrames()
  axis = Spline() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 650, "y1": 950, "x2": 750, "y2": 1050, "rot": 0}
      },
      "tags": []
    }
  }
  bearing = Spline() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 230, "y1": 950, "x2": 330, "y2": 1050, "rot": 0}
      },
      "tags": []
    }
  }
  "Force the elbow-up (`true`) or elbow-down (`false`) solution instead of selecting it automatically from `phi_guess`"
  structural parameter positive_branch::Boolean = missing
  "Sign of the square-root term picking the branch of the loop-closure solution. Determined at initialization, do not set (use `phi_guess`, or `positive_branch` to force a branch)"
  parameter branch_sign::Real = missing
  "Axis of rotation, resolved in frame_a/frame_b"
  parameter n::Real[3] = [0, 0, 1]
  "Structural sparsity mask for the axis: components marked false are assembled as literal zeros (clean axis*axis' in the Rodrigues formula). Must be set consistently with `n`."
  structural parameter n_nonzero::Boolean[3] = [true, true, true]
  final parameter n_sparse::Real[3] = [n[1] * n_nonzero[1], n[2] * n_nonzero[2], n[3] * n_nonzero[3]]
  "Relative angle offset (angle = phi + phi_offset)"
  parameter phi_offset::Real = 0
  "Guess value for the revolute angle, used to select the configuration"
  parameter phi_guess::Real = 0
  "Fixed length of the length constraint"
  parameter length_constraint::Real = 1
  final parameter e::Real[3] = n_sparse / norm_(n_sparse)
  "Driving torque in direction of axis of rotation"
  variable tau::Dyad.Torque
  "Relative rotation angle from frame_a to frame_b"
  variable phi::Angle
  "= phi + phi_offset"
  variable angle::Angle
  "Position vector to the frame_a side of the length constraint, resolved in frame_a"
  variable r_a::Position[3]
  "Position vector to the frame_b side of the length constraint, resolved in frame_b"
  variable r_b::Position[3]
relations
  guess phi = phi_guess
  guess branch_sign = 1
  initial branch_sign = select_branch_angle(length_constraint, e, r_a, r_b, phi_offset + phi_guess, positive_branch)
  angle = phi + phi_offset
  axis.phi = phi
  axis.tau = tau
  bearing.phi = 0
  frame_b.r_0 = frame_a.r_0
  RotationMatrix(frame_b.R) = absolute_rotation(frame_a, planar_rotation(e, angle, der(angle)))
  [0, 0, 0] = frame_a.f + resolve1(planar_rotation(e, angle, der(angle)), frame_b.f)
  [0, 0, 0] = frame_a.tau + resolve1(planar_rotation(e, angle, der(angle)), frame_b.tau)
  angle = compute_angle(length_constraint, e, r_a, r_b, branch_sign)
metadata {
  "Dyad": {
    "icons": {"default": "dyad://MultibodyComponents/RevoluteWithLengthConstraint.svg"},
    "labels": [
      {
        "label": "$(instance)",
        "x": 500,
        "y": 200,
        "rot": 0,
        "attrs": {"font-size": "160"}
      }
    ]
  }
}
end
```

```dyad
"""
Revolute joint whose angle is determined analytically by a length constraint
rather than being a free state. Used internally by `JointUSR` (and similar
joint assemblies) to solve a kinematic loop in closed form.

The position vectors to the two sides of the length constraint, `r_a` (resolved
in `frame_a`) and `r_b` (resolved in `frame_b`), are supplied by the enclosing
assembly. Given the fixed `length_constraint`, the joint angle is computed with
`compute_angle`, which has two solutions (elbow up/down). Which one the mechanism
is assembled in is determined automatically at initialization: `branch_sign` is
solved for from the initial geometry as the solution closest to
`phi_offset + phi_guess`, and stays fixed for the rest of the simulation. Set
`positive_branch` to bypass that and force a branch.

This component is not balanced on its own — `r_a` and `r_b` are inputs that the
parent assembly must drive. It is not intended to be used standalone.
"""
component RevoluteWithLengthConstraint
  frame_a = Frame3D() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -50, "y1": 450, "x2": 50, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  frame_b = Frame3D() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 950, "y1": 450, "x2": 1050, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  axis = Spline() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 650, "y1": 950, "x2": 750, "y2": 1050, "rot": 0}
      },
      "tags": []
    }
  }
  bearing = Spline() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 230, "y1": 950, "x2": 330, "y2": 1050, "rot": 0}
      },
      "tags": []
    }
  }
  "Force the elbow-up (`true`) or elbow-down (`false`) solution instead of selecting it automatically from `phi_guess`"
  structural parameter positive_branch::Boolean = missing
  "Sign of the square-root term picking the branch of the loop-closure solution. Determined at initialization, do not set (use `phi_guess`, or `positive_branch` to force a branch)"
  parameter branch_sign::Real = missing
  "Axis of rotation, resolved in frame_a/frame_b"
  parameter n::Real[3] = [0, 0, 1]
  "Structural sparsity mask for the axis: components marked false are assembled as literal zeros (clean axis*axis' in the Rodrigues formula). Must be set consistently with `n`."
  structural parameter n_nonzero::Boolean[3] = [true, true, true]
  final parameter n_sparse::Real[3] = [n[1] * n_nonzero[1], n[2] * n_nonzero[2], n[3] * n_nonzero[3]]
  "Relative angle offset (angle = phi + phi_offset)"
  parameter phi_offset::Real = 0
  "Guess value for the revolute angle, used to select the configuration"
  parameter phi_guess::Real = 0
  "Fixed length of the length constraint"
  parameter length_constraint::Real = 1
  final parameter e::Real[3] = n_sparse / norm_(n_sparse)
  "Driving torque in direction of axis of rotation"
  variable tau::Dyad.Torque
  "Relative rotation angle from frame_a to frame_b"
  variable phi::Angle
  "= phi + phi_offset"
  variable angle::Angle
  "Position vector to the frame_a side of the length constraint, resolved in frame_a"
  variable r_a::Position[3]
  "Position vector to the frame_b side of the length constraint, resolved in frame_b"
  variable r_b::Position[3]
relations
  guess phi = phi_guess
  guess branch_sign = 1
  initial branch_sign = select_branch_angle(length_constraint, e, r_a, r_b, phi_offset + phi_guess, positive_branch)
  angle = phi + phi_offset
  axis.phi = phi
  axis.tau = tau
  bearing.phi = 0
  frame_b.r_0 = frame_a.r_0
  RotationMatrix(frame_b.R) = absolute_rotation(frame_a, planar_rotation(e, angle, der(angle)))
  [0, 0, 0] = frame_a.f + resolve1(planar_rotation(e, angle, der(angle)), frame_b.f)
  [0, 0, 0] = frame_a.tau + resolve1(planar_rotation(e, angle, der(angle)), frame_b.tau)
  angle = compute_angle(length_constraint, e, r_a, r_b, branch_sign)
metadata {
  "Dyad": {
    "icons": {"default": "dyad://MultibodyComponents/RevoluteWithLengthConstraint.svg"},
    "labels": [
      {
        "label": "$(instance)",
        "x": 500,
        "y": 200,
        "rot": 0,
        "attrs": {"font-size": "160"}
      }
    ]
  }
}
end
```

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses
