---
url: /dyad/stable/stdlib/TranslationalComponents/components/Components.RelativeStates.md
description: Dyad Components.RelativeStates docs.  Definition of relative state variables.
---

# `Components.RelativeStates` {#Components.RelativeStates}

Definition of relative state variables.

This component defines **relative position** and **relative velocity** between two flanges as preferred state variables. It transmits zero force and is used purely for state selection purposes.

Connect an instance of this model between two flange connectors to use the relative position `s_rel` and relative velocity `v_rel` as state variables instead of the default absolute quantities.

The equations are:

$$s\_{rel} = flange_b.s - flange_a.s$$

$$v\_{rel} = \frac{d(s\_{rel})}{dt}$$

$$a\_{rel} = \frac{d(v\_{rel})}{dt}$$

$$flange_a.f = 0$$

$$flange_b.f = 0$$

This component extends from [`TranslationalComponents.Interfaces.PartialTwoFlanges`](../types/Interfaces.PartialTwoFlanges.md)

## Usage {#Usage}

`TranslationalComponents.Components.RelativeStates()`

## Connectors {#Connectors}

* `flange_a` - This connector represents a mechanical flange with position and force as the potential and flow variables, respectively. ([`Flange`](/stdlib/Dyad/connectors/Flange#Flange))

* `flange_b` - This connector represents a mechanical flange with position and force as the potential and flow variables, respectively. ([`Flange`](/stdlib/Dyad/connectors/Flange#Flange))

## Variables {#Variables}

|    Name |                              Description | Units |
| -------:| ----------------------------------------:| -----:|
| `s_rel` | Relative position used as state variable |     m |
| `v_rel` | Relative velocity used as state variable |   m/s |
| `a_rel` |                    Relative acceleration |  m/s2 |

## Behavior {#Behavior}

$$ \begin{align}
\mathtt{s_rel}\left( t \right) &=  - \mathtt{flange_a.s}\left( t \right) + \mathtt{flange_b.s}\left( t \right) \\
\mathtt{v_rel}\left( t \right) &= \frac{\mathrm{d}\mathtt{s_rel}\left( t \right)}{\mathrm{d}t} \\
\mathtt{a_rel}\left( t \right) &= \frac{\mathrm{d}\mathtt{v_rel}\left( t \right)}{\mathrm{d}t} \\
\mathtt{flange_a.f}\left( t \right) &= 0 \\
\mathtt{flange_b.f}\left( t \right) &= 0
\end{align}
$$

## Source {#Source}

````dyad
"""
Definition of relative state variables.

This component defines **relative position** and **relative velocity** between two
flanges as preferred state variables. It transmits zero force and is used purely
for state selection purposes.

Connect an instance of this model between two flange connectors to use
the relative position `s_rel` and relative velocity `v_rel` as state variables
instead of the default absolute quantities.

The equations are:
```math
s_{rel} = flange\_b.s - flange\_a.s
```
```math
v_{rel} = \\frac{d(s_{rel})}{dt}
```
```math
a_{rel} = \\frac{d(v_{rel})}{dt}
```
```math
flange\_a.f = 0
```
```math
flange\_b.f = 0
```
"""
component RelativeStates
  extends TranslationalComponents.Interfaces.PartialTwoFlanges
  "Relative position used as state variable"
  variable s_rel::Distance(statePriority = 50)
  "Relative velocity used as state variable"
  variable v_rel::Velocity(statePriority = 50)
  "Relative acceleration"
  variable a_rel::Acceleration
relations
  s_rel = flange_b.s - flange_a.s
  v_rel = der(s_rel)
  a_rel = der(v_rel)
  flange_a.f = 0
  flange_b.f = 0
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/RelativeStates.svg"},
    "labels": [{"label": "$(instance)", "layer": "icon", "x": 500, "y": 904, "rot": 0}]
  }
}
end
````

````dyad
"""
Definition of relative state variables.

This component defines **relative position** and **relative velocity** between two
flanges as preferred state variables. It transmits zero force and is used purely
for state selection purposes.

Connect an instance of this model between two flange connectors to use
the relative position `s_rel` and relative velocity `v_rel` as state variables
instead of the default absolute quantities.

The equations are:
```math
s_{rel} = flange\_b.s - flange\_a.s
```
```math
v_{rel} = \\frac{d(s_{rel})}{dt}
```
```math
a_{rel} = \\frac{d(v_{rel})}{dt}
```
```math
flange\_a.f = 0
```
```math
flange\_b.f = 0
```
"""
component RelativeStates
  "Left mechanical translational flange (connector)"
  flange_a = Flange() {"Dyad": {"placement": {"icon": {"x1": -50, "y1": 450, "x2": 50, "y2": 550}}}}
  "Right mechanical translational flange (connector)"
  flange_b = Flange() {"Dyad": {"placement": {"icon": {"x1": 950, "y1": 450, "x2": 1050, "y2": 550}}}}
  "Relative position used as state variable"
  variable s_rel::Distance(statePriority = 50)
  "Relative velocity used as state variable"
  variable v_rel::Velocity(statePriority = 50)
  "Relative acceleration"
  variable a_rel::Acceleration
relations
  s_rel = flange_b.s - flange_a.s
  v_rel = der(s_rel)
  a_rel = der(v_rel)
  flange_a.f = 0
  flange_b.f = 0
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/RelativeStates.svg"},
    "labels": [{"label": "$(instance)", "layer": "icon", "x": 500, "y": 904, "rot": 0}]
  }
}
end
````

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`AllComponents`](Components.RelativeStates.md)
