---
url: /dyad/stable/stdlib/MultibodyComponents/components/PlanarMechanics.BasicRelativePosition.md
description: >-
  Dyad PlanarMechanics.BasicRelativePosition docs.  Measures relative position
  and orientation (frameb - framea) resolved in a configurable frame. Internal
  helper used by RelativePosition and ...
---

# `PlanarMechanics.BasicRelativePosition` {#PlanarMechanics.BasicRelativePosition}

Measures relative position and orientation (frame_b - frame_a) resolved in a configurable frame. Internal helper used by RelativePosition and by velocity/acceleration sensors.

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

## Usage {#Usage}

`MultibodyComponents.PlanarMechanics.BasicRelativePosition()`

## Parameters: {#Parameters:}

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

## Connectors {#Connectors}

* `frame_a` - Coordinate system (2-dim.) fixed to the component with one cut-force and cut-torque.

All variables are resolved in the planar world frame. ([`Frame2D`](/stdlib/Dyad/connectors/Frame2D#Frame2D))

* `frame_b` - Coordinate system (2-dim.) fixed to the component with one cut-force and cut-torque.

All variables are resolved in the planar world frame. ([`Frame2D`](/stdlib/Dyad/connectors/Frame2D#Frame2D))

* `frame_resolve` - Coordinate system (2-dim.) fixed to the component with one cut-force and cut-torque.

All variables are resolved in the planar world frame. ([`Frame2D`](/stdlib/Dyad/connectors/Frame2D#Frame2D))

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

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

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

## Variables {#Variables}

|              Name | Description | Units |
| -----------------:| -----------:| -----:|
| `rotation_matrix` |             |     – |
|               `r` |             |     – |

## Behavior {#Behavior}

$$ \begin{align}
\mathtt{frame_a.fx}\left( t \right) &= 0 \\
\mathtt{frame_a.fy}\left( t \right) &= 0 \\
\mathtt{frame_a.tau}\left( t \right) &= 0 \\
\mathtt{frame_b.fx}\left( t \right) &= 0 \\
\mathtt{frame_b.fy}\left( t \right) &= 0 \\
\mathtt{frame_b.tau}\left( t \right) &= 0 \\
\mathtt{rel_x}\left( t \right) &= r\_{1}\left( t \right) \\
\mathtt{rel_y}\left( t \right) &= r\_{2}\left( t \right) \\
\mathtt{rel_phi}\left( t \right) &= r\_{3}\left( t \right) \\
\mathtt{rotation_matrix}\_{1,1}\left( t \right) &= \cos\left( \mathtt{frame_a.phi}\left( t \right) \right) \\
\mathtt{rotation_matrix}\_{2,1}\left( t \right) &= \sin\left( \mathtt{frame_a.phi}\left( t \right) \right) \\
\mathtt{rotation_matrix}\_{3,1}\left( t \right) &= 0 \\
\mathtt{rotation_matrix}\_{1,2}\left( t \right) &=  - \sin\left( \mathtt{frame_a.phi}\left( t \right) \right) \\
\mathtt{rotation_matrix}\_{2,2}\left( t \right) &= \cos\left( \mathtt{frame_a.phi}\left( t \right) \right) \\
\mathtt{rotation_matrix}\_{3,2}\left( t \right) &= 0 \\
\mathtt{rotation_matrix}\_{1,3}\left( t \right) &= 0 \\
\mathtt{rotation_matrix}\_{2,3}\left( t \right) &= 0 \\
\mathtt{rotation_matrix}\_{3,3}\left( t \right) &= 1 \\
r\_{1}\left( t \right) &= \left(  - \mathtt{frame_a.phi}\left( t \right) + \mathtt{frame_b.phi}\left( t \right) \right) ~ \mathtt{rotation_matrix}\_{3,1}\left( t \right) + \left(  - \mathtt{frame_a.x}\left( t \right) + \mathtt{frame_b.x}\left( t \right) \right) ~ \mathtt{rotation_matrix}\_{1,1}\left( t \right) + \left(  - \mathtt{frame_a.y}\left( t \right) + \mathtt{frame_b.y}\left( t \right) \right) ~ \mathtt{rotation_matrix}\_{2,1}\left( t \right) \\
r\_{2}\left( t \right) &= \left(  - \mathtt{frame_a.phi}\left( t \right) + \mathtt{frame_b.phi}\left( t \right) \right) ~ \mathtt{rotation_matrix}\_{3,2}\left( t \right) + \left(  - \mathtt{frame_a.x}\left( t \right) + \mathtt{frame_b.x}\left( t \right) \right) ~ \mathtt{rotation_matrix}\_{1,2}\left( t \right) + \left(  - \mathtt{frame_a.y}\left( t \right) + \mathtt{frame_b.y}\left( t \right) \right) ~ \mathtt{rotation_matrix}\_{2,2}\left( t \right) \\
r\_{3}\left( t \right) &= \left(  - \mathtt{frame_a.phi}\left( t \right) + \mathtt{frame_b.phi}\left( t \right) \right) ~ \mathtt{rotation_matrix}\_{3,3}\left( t \right) + \left(  - \mathtt{frame_a.x}\left( t \right) + \mathtt{frame_b.x}\left( t \right) \right) ~ \mathtt{rotation_matrix}\_{1,3}\left( t \right) + \left(  - \mathtt{frame_a.y}\left( t \right) + \mathtt{frame_b.y}\left( t \right) \right) ~ \mathtt{rotation_matrix}\_{2,3}\left( t \right)
\end{align}
$$

## Source {#Source}

```dyad
"""
Measures relative position and orientation (frame_b - frame_a) resolved in a
configurable frame. Internal helper used by RelativePosition and by
velocity/acceleration sensors.
"""
component BasicRelativePosition
  extends PartialTwoFrameSensor
  frame_resolve = Frame2D() if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameResolve() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 950, "y1": 30, "x2": 1050, "y2": 130, "rot": 0}
      },
      "tags": []
    }
  }
  rel_x = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 130, "y1": 970, "x2": 230, "y2": 1070, "rot": 90}
      },
      "tags": []
    }
  }
  rel_y = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 960, "x2": 550, "y2": 1060, "rot": 90}
      },
      "tags": []
    }
  }
  rel_phi = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 770, "y1": 960, "x2": 870, "y2": 1060, "rot": 90}
      },
      "tags": []
    }
  }
  structural parameter resolve_in_frame::MultibodyComponents.ResolveInFrame = MultibodyComponents.ResolveInFrame.FrameA()
  variable rotation_matrix::Real[3, 3] if resolve_in_frame != MultibodyComponents.ResolveInFrame.World()
  variable r::Real[3]
relations
  frame_a.fx = 0
  frame_a.fy = 0
  frame_a.tau = 0
  frame_b.fx = 0
  frame_b.fy = 0
  frame_b.tau = 0
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.World()
    r = [frame_b.x - frame_a.x, frame_b.y - frame_a.y, frame_b.phi - frame_a.phi]
  end
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameA()
    rotation_matrix = [[cos(frame_a.phi), -sin(frame_a.phi), 0], [sin(frame_a.phi), cos(frame_a.phi), 0], [0, 0, 1]]
    r = transpose(rotation_matrix) * [frame_b.x - frame_a.x, frame_b.y - frame_a.y, frame_b.phi - frame_a.phi]
  end
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameB()
    rotation_matrix = [[cos(frame_b.phi), -sin(frame_b.phi), 0], [sin(frame_b.phi), cos(frame_b.phi), 0], [0, 0, 1]]
    r = transpose(rotation_matrix) * [frame_b.x - frame_a.x, frame_b.y - frame_a.y, frame_b.phi - frame_a.phi]
  end
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameResolve()
    frame_resolve.fx = 0
    frame_resolve.fy = 0
    frame_resolve.tau = 0
    rotation_matrix = [[cos(frame_resolve.phi), -sin(frame_resolve.phi), 0], [sin(frame_resolve.phi), cos(frame_resolve.phi), 0], [0, 0, 1]]
    r = transpose(rotation_matrix) * [frame_b.x - frame_a.x, frame_b.y - frame_a.y, frame_b.phi - frame_a.phi]
  end
  [rel_x, rel_y, rel_phi] = r
end
```

```dyad
"""
Measures relative position and orientation (frame_b - frame_a) resolved in a
configurable frame. Internal helper used by RelativePosition and by
velocity/acceleration sensors.
"""
component BasicRelativePosition
  frame_a = Frame2D() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 50, "y1": 450, "x2": 150, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  frame_b = Frame2D() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 850, "y1": 450, "x2": 950, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  frame_resolve = Frame2D() if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameResolve() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 950, "y1": 30, "x2": 1050, "y2": 130, "rot": 0}
      },
      "tags": []
    }
  }
  rel_x = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 130, "y1": 970, "x2": 230, "y2": 1070, "rot": 90}
      },
      "tags": []
    }
  }
  rel_y = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 960, "x2": 550, "y2": 1060, "rot": 90}
      },
      "tags": []
    }
  }
  rel_phi = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 770, "y1": 960, "x2": 870, "y2": 1060, "rot": 90}
      },
      "tags": []
    }
  }
  structural parameter resolve_in_frame::MultibodyComponents.ResolveInFrame = MultibodyComponents.ResolveInFrame.FrameA()
  variable rotation_matrix::Real[3, 3] if resolve_in_frame != MultibodyComponents.ResolveInFrame.World()
  variable r::Real[3]
relations
  frame_a.fx = 0
  frame_a.fy = 0
  frame_a.tau = 0
  frame_b.fx = 0
  frame_b.fy = 0
  frame_b.tau = 0
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.World()
    r = [frame_b.x - frame_a.x, frame_b.y - frame_a.y, frame_b.phi - frame_a.phi]
  end
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameA()
    rotation_matrix = [[cos(frame_a.phi), -sin(frame_a.phi), 0], [sin(frame_a.phi), cos(frame_a.phi), 0], [0, 0, 1]]
    r = transpose(rotation_matrix) * [frame_b.x - frame_a.x, frame_b.y - frame_a.y, frame_b.phi - frame_a.phi]
  end
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameB()
    rotation_matrix = [[cos(frame_b.phi), -sin(frame_b.phi), 0], [sin(frame_b.phi), cos(frame_b.phi), 0], [0, 0, 1]]
    r = transpose(rotation_matrix) * [frame_b.x - frame_a.x, frame_b.y - frame_a.y, frame_b.phi - frame_a.phi]
  end
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameResolve()
    frame_resolve.fx = 0
    frame_resolve.fy = 0
    frame_resolve.tau = 0
    rotation_matrix = [[cos(frame_resolve.phi), -sin(frame_resolve.phi), 0], [sin(frame_resolve.phi), cos(frame_resolve.phi), 0], [0, 0, 1]]
    r = transpose(rotation_matrix) * [frame_b.x - frame_a.x, frame_b.y - frame_a.y, frame_b.phi - frame_a.phi]
  end
  [rel_x, rel_y, rel_phi] = r
metadata {
  "Dyad": {"icons": {"default": "dyad://MultibodyComponents/TwoFrameSensor.svg"}}
}
end
```

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses
