---
url: /dyad/stable/stdlib/MultibodyComponents/components/RelativeVelocity.md
description: >-
  Dyad RelativeVelocity docs.  Measures the relative velocity between the
  origins of two frame connectors.
---

# `RelativeVelocity` {#RelativeVelocity}

Measures the relative velocity between the origins of two frame connectors.

Always differentiates the relative position resolved in FrameA first, then rotates the result into `resolve_in_frame` – matching Modelica's RelativeVelocity. Note this differs from `RelativeSensor`'s `v_rel` output, which differentiates in whatever `resolve_in_frame` is set to.

This is a sensor: no forces or torques are exerted.

## Usage {#Usage}

`MultibodyComponents.RelativeVelocity()`

## Parameters: {#Parameters:}

|               Name | Description | Units |           Default value |
| ------------------:| -----------:| -----:| -----------------------:|
| `resolve_in_frame` |             |     – | ResolveInFrame.FrameA() |

## 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))

* `frame_resolve` - 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))

* `v_rel_x` - This connector represents a real signal as an output from a component ([`RealOutput`](/stdlib/Dyad/connectors/RealOutput#RealOutput))

* `v_rel_y` - This connector represents a real signal as an output from a component ([`RealOutput`](/stdlib/Dyad/connectors/RealOutput#RealOutput))

* `v_rel_z` - This connector represents a real signal as an output from a component ([`RealOutput`](/stdlib/Dyad/connectors/RealOutput#RealOutput))

## Variables {#Variables}

|      Name |                            Description | Units |
| ---------:| --------------------------------------:| -----:|
| `r_rel_a` | Relative position, resolved in frame_a |     m |
| `v_rel_a` | Relative velocity, resolved in frame_a |   m/s |
|   `v_rel` |                                        |   m/s |

## Behavior {#Behavior}

$$ \begin{align}
\mathtt{frame_a.f}\_{1}\left( t \right) &= 0 \\
\mathtt{frame_a.f}\_{2}\left( t \right) &= 0 \\
\mathtt{frame_a.f}\_{3}\left( t \right) &= 0 \\
\mathtt{frame_a.tau}\_{1}\left( t \right) &= 0 \\
\mathtt{frame_a.tau}\_{2}\left( t \right) &= 0 \\
\mathtt{frame_a.tau}\_{3}\left( t \right) &= 0 \\
\mathtt{frame_b.f}\_{1}\left( t \right) &= 0 \\
\mathtt{frame_b.f}\_{2}\left( t \right) &= 0 \\
\mathtt{frame_b.f}\_{3}\left( t \right) &= 0 \\
\mathtt{frame_b.tau}\_{1}\left( t \right) &= 0 \\
\mathtt{frame_b.tau}\_{2}\left( t \right) &= 0 \\
\mathtt{frame_b.tau}\_{3}\left( t \right) &= 0 \\
\mathtt{r_rel_a}\_{1}\left( t \right) &= \mathtt{frame_a.R}\_{1,1}\left( t \right) ~ \left(  - \mathtt{frame_a.r_0}\_{1}\left( t \right) + \mathtt{frame_b.r_0}\_{1}\left( t \right) \right) + \mathtt{frame_a.R}\_{1,2}\left( t \right) ~ \left(  - \mathtt{frame_a.r_0}\_{2}\left( t \right) + \mathtt{frame_b.r_0}\_{2}\left( t \right) \right) + \mathtt{frame_a.R}\_{1,3}\left( t \right) ~ \left(  - \mathtt{frame_a.r_0}\_{3}\left( t \right) + \mathtt{frame_b.r_0}\_{3}\left( t \right) \right) \\
\mathtt{r_rel_a}\_{2}\left( t \right) &= \mathtt{frame_a.R}\_{2,1}\left( t \right) ~ \left(  - \mathtt{frame_a.r_0}\_{1}\left( t \right) + \mathtt{frame_b.r_0}\_{1}\left( t \right) \right) + \mathtt{frame_a.R}\_{2,2}\left( t \right) ~ \left(  - \mathtt{frame_a.r_0}\_{2}\left( t \right) + \mathtt{frame_b.r_0}\_{2}\left( t \right) \right) + \mathtt{frame_a.R}\_{2,3}\left( t \right) ~ \left(  - \mathtt{frame_a.r_0}\_{3}\left( t \right) + \mathtt{frame_b.r_0}\_{3}\left( t \right) \right) \\
\mathtt{r_rel_a}\_{3}\left( t \right) &= \mathtt{frame_a.R}\_{3,1}\left( t \right) ~ \left(  - \mathtt{frame_a.r_0}\_{1}\left( t \right) + \mathtt{frame_b.r_0}\_{1}\left( t \right) \right) + \mathtt{frame_a.R}\_{3,2}\left( t \right) ~ \left(  - \mathtt{frame_a.r_0}\_{2}\left( t \right) + \mathtt{frame_b.r_0}\_{2}\left( t \right) \right) + \mathtt{frame_a.R}\_{3,3}\left( t \right) ~ \left(  - \mathtt{frame_a.r_0}\_{3}\left( t \right) + \mathtt{frame_b.r_0}\_{3}\left( t \right) \right) \\
\mathtt{v_rel_a}\_{1}\left( t \right) &= \frac{\mathrm{d}\mathtt{r_rel_a}\_{1}\left( t \right)}{\mathrm{d}t} \\
\mathtt{v_rel_a}\_{2}\left( t \right) &= \frac{\mathrm{d}\mathtt{r_rel_a}\_{2}\left( t \right)}{\mathrm{d}t} \\
\mathtt{v_rel_a}\_{3}\left( t \right) &= \frac{\mathrm{d}\mathtt{r_rel_a}\_{3}\left( t \right)}{\mathrm{d}t} \\
\mathtt{v_rel_x}\left( t \right) &= \mathtt{v_rel}\_{1}\left( t \right) \\
\mathtt{v_rel_y}\left( t \right) &= \mathtt{v_rel}\_{2}\left( t \right) \\
\mathtt{v_rel_z}\left( t \right) &= \mathtt{v_rel}\_{3}\left( t \right) \\
\mathtt{v_rel}\_{1}\left( t \right) &= \mathtt{v_rel_a}\_{1}\left( t \right) \\
\mathtt{v_rel}\_{2}\left( t \right) &= \mathtt{v_rel_a}\_{2}\left( t \right) \\
\mathtt{v_rel}\_{3}\left( t \right) &= \mathtt{v_rel_a}\_{3}\left( t \right)
\end{align}
$$

## Source {#Source}

```dyad
"""
Measures the relative velocity between the origins of two frame connectors.

Always differentiates the relative position resolved in FrameA first, then
rotates the result into `resolve_in_frame` -- matching Modelica's
RelativeVelocity. Note this differs from `RelativeSensor`'s `v_rel` output,
which differentiates in whatever `resolve_in_frame` is set to.

This is a sensor: no forces or torques are exerted.
"""
component RelativeVelocity
  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": []
    }
  }
  frame_resolve = Frame3D() if case(resolve_in_frame, ResolveInFrame.FrameResolve) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": -50, "x2": 550, "y2": 50, "rot": 0}
      },
      "tags": []
    }
  }
  v_rel_x = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 130, "y1": 960, "x2": 230, "y2": 1060, "rot": 90}
      },
      "tags": []
    }
  }
  v_rel_y = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 960, "x2": 550, "y2": 1060, "rot": 90}
      },
      "tags": []
    }
  }
  v_rel_z = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 770, "y1": 960, "x2": 870, "y2": 1060, "rot": 90}
      },
      "tags": []
    }
  }
  structural parameter resolve_in_frame::ResolveInFrame = ResolveInFrame.FrameA()
  "Relative position, resolved in frame_a"
  variable r_rel_a::Position[3]
  "Relative velocity, resolved in frame_a"
  variable v_rel_a::Velocity[3]
  variable v_rel::Velocity[3]
relations
  frame_a.f = [0, 0, 0]
  frame_a.tau = [0, 0, 0]
  frame_b.f = [0, 0, 0]
  frame_b.tau = [0, 0, 0]
  if case(resolve_in_frame, ResolveInFrame.FrameResolve)
    frame_resolve.f = [0, 0, 0]
    frame_resolve.tau = [0, 0, 0]
  end
  r_rel_a = resolve2(frame_a.R, frame_b.r_0 - frame_a.r_0)
  v_rel_a = der(r_rel_a)
  switch resolve_in_frame
    case FrameA
      v_rel = v_rel_a
    case World
      v_rel = resolve1(frame_a.R, v_rel_a)
    case FrameB
      v_rel = resolve_relative(v_rel_a, frame_a.R, frame_b.R)
    case FrameResolve
      v_rel = resolve_relative(v_rel_a, frame_a.R, frame_resolve.R)
  end
  [v_rel_x, v_rel_y, v_rel_z] = v_rel
metadata {
  "Dyad": {
    "icons": {"default": "dyad://MultibodyComponents/TwoFrameSensor.svg"},
    "labels": [
      {
        "label": "$(instance)",
        "x": 500,
        "y": 150,
        "rot": 0,
        "attrs": {"font-size": "140"}
      },
      {"label": "rel vel", "x": 500, "y": 680, "rot": 0}
    ]
  }
}
end
```

```dyad
"""
Measures the relative velocity between the origins of two frame connectors.

Always differentiates the relative position resolved in FrameA first, then
rotates the result into `resolve_in_frame` -- matching Modelica's
RelativeVelocity. Note this differs from `RelativeSensor`'s `v_rel` output,
which differentiates in whatever `resolve_in_frame` is set to.

This is a sensor: no forces or torques are exerted.
"""
component RelativeVelocity
  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": []
    }
  }
  frame_resolve = Frame3D() if case(resolve_in_frame, ResolveInFrame.FrameResolve) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": -50, "x2": 550, "y2": 50, "rot": 0}
      },
      "tags": []
    }
  }
  v_rel_x = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 130, "y1": 960, "x2": 230, "y2": 1060, "rot": 90}
      },
      "tags": []
    }
  }
  v_rel_y = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 960, "x2": 550, "y2": 1060, "rot": 90}
      },
      "tags": []
    }
  }
  v_rel_z = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 770, "y1": 960, "x2": 870, "y2": 1060, "rot": 90}
      },
      "tags": []
    }
  }
  structural parameter resolve_in_frame::ResolveInFrame = ResolveInFrame.FrameA()
  "Relative position, resolved in frame_a"
  variable r_rel_a::Position[3]
  "Relative velocity, resolved in frame_a"
  variable v_rel_a::Velocity[3]
  variable v_rel::Velocity[3]
relations
  frame_a.f = [0, 0, 0]
  frame_a.tau = [0, 0, 0]
  frame_b.f = [0, 0, 0]
  frame_b.tau = [0, 0, 0]
  if case(resolve_in_frame, ResolveInFrame.FrameResolve)
    frame_resolve.f = [0, 0, 0]
    frame_resolve.tau = [0, 0, 0]
  end
  r_rel_a = resolve2(frame_a.R, frame_b.r_0 - frame_a.r_0)
  v_rel_a = der(r_rel_a)
  switch resolve_in_frame
    case FrameA
      v_rel = v_rel_a
    case World
      v_rel = resolve1(frame_a.R, v_rel_a)
    case FrameB
      v_rel = resolve_relative(v_rel_a, frame_a.R, frame_b.R)
    case FrameResolve
      v_rel = resolve_relative(v_rel_a, frame_a.R, frame_resolve.R)
  end
  [v_rel_x, v_rel_y, v_rel_z] = v_rel
metadata {
  "Dyad": {
    "icons": {"default": "dyad://MultibodyComponents/TwoFrameSensor.svg"},
    "labels": [
      {
        "label": "$(instance)",
        "x": 500,
        "y": 150,
        "rot": 0,
        "attrs": {"font-size": "140"}
      },
      {"label": "rel vel", "x": 500, "y": 680, "rot": 0}
    ]
  }
}
end
```

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`SensorsTest`](RelativeVelocity.md)
