---
url: /dyad/stable/stdlib/MultibodyComponents/components/PlanarMechanics.RelativeForce.md
description: >-
  Dyad PlanarMechanics.RelativeForce docs.  Relative force and torque acting
  between framea and frameb, defined by input signals.
---

# `PlanarMechanics.RelativeForce` {#PlanarMechanics.RelativeForce}

Relative force and torque acting between frame_a and frame_b, defined by input signals.

Applies the input force to frame_b and the reaction (equal and opposite) to frame_a. The force inputs (force_x, force_y) and torque input are resolved in the frame selected by the structural parameter `resolve_in_frame` (world, frame_a, or frame_b).

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

## Usage {#Usage}

`MultibodyComponents.PlanarMechanics.RelativeForce(render=true, color=MultibodyComponents.world_default_force_color(), specular_coefficient=1.5, scale=0.1, arrow_diameter=MultibodyComponents.world_default_arrow_diameter(), z_position=0)`

## Parameters: {#Parameters:}

|                   Name |                                                   Description | Units |             Default value |
| ----------------------:| -------------------------------------------------------------:| -----:| -------------------------:|
|     `resolve_in_frame` |                                                               |     – | MultibodyCo...me.FrameA() |
|               `render` |                                                               |     – |                      true |
|                `color` |                                                               |     – | MultibodyCo...rce_color() |
| `specular_coefficient` |                                                               |     – |                       1.5 |
|                `scale` | Scale factor for force visualization (length = force \* scale) |     – |                       0.1 |
|       `arrow_diameter` |                             Diameter of the force arrow shaft |     – | MultibodyCo...\_diameter() |
|           `z_position` |                         z-position of the arrow in animations |     – |                         0 |

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

* `force_x` - This connector represents a real signal as an input to a component ([`RealInput`](/stdlib/Dyad/connectors/RealInput#RealInput))

* `force_y` - This connector represents a real signal as an input to a component ([`RealInput`](/stdlib/Dyad/connectors/RealInput#RealInput))

* `torque` - This connector represents a real signal as an input to a component ([`RealInput`](/stdlib/Dyad/connectors/RealInput#RealInput))

## Variables {#Variables}

|  Name |               Description | Units |
| -----:| -------------------------:| -----:|
| `phi` | Angle of resolution frame |   rad |

## Behavior {#Behavior}

## Source {#Source}

```dyad
"""
Relative force and torque acting between frame_a and frame_b, defined by input signals.

Applies the input force to frame_b and the reaction (equal and opposite) to frame_a.
The force inputs (force_x, force_y) and torque input are resolved in the frame
selected by the structural parameter `resolve_in_frame` (world, frame_a, or frame_b).
"""
component RelativeForce
  extends MultibodyComponents.Renderable(color = MultibodyComponents.world_default_force_color())
  frame_a = Frame2D() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -50, "y1": 450, "x2": 50, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  frame_b = Frame2D() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 950, "y1": 450, "x2": 1050, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  force_x = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 90, "y1": -50, "x2": 190, "y2": 50, "rot": 90}
      },
      "tags": []
    }
  }
  force_y = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": -50, "x2": 550, "y2": 50, "rot": 90}
      },
      "tags": []
    }
  }
  torque = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 810, "y1": -50, "x2": 910, "y2": 50, "rot": 90}
      },
      "tags": []
    }
  }
  "Force arrow visualization at frame_b"
  force_arrow = MultibodyComponents.ArrowShape(render = render, color = color, head_at_origin = true, diameter = arrow_diameter, r = [frame_b.x, frame_b.y, z_position], R = MultibodyComponents.RR(MultibodyComponents.planar_rotation([0, 0, 1], phi, 0)), length_direction = [force_x, force_y, 0], width_direction = [0, 0, 1], length = sqrt(force_x ^ 2 + force_y ^ 2) * scale, width = arrow_diameter, height = arrow_diameter)
  structural parameter resolve_in_frame::MultibodyComponents.ResolveInFrame = MultibodyComponents.ResolveInFrame.FrameA()
  "Scale factor for force visualization (length = force * scale)"
  parameter scale::Real = 0.1
  "Diameter of the force arrow shaft"
  parameter arrow_diameter::Real = MultibodyComponents.world_default_arrow_diameter()
  "z-position of the arrow in animations"
  parameter z_position::Real = 0
  "Angle of resolution frame"
  variable phi::Angle
relations
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.World()
    phi = 0
  end
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameA()
    phi = frame_a.phi
  end
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameB()
    phi = frame_b.phi
  end
  # Apply rotated force to frame_b
  frame_b.fx + cos(phi) * force_x - sin(phi) * force_y = 0
  frame_b.fy + sin(phi) * force_x + cos(phi) * force_y = 0
  frame_b.tau + torque = 0
  # Reaction forces on frame_a (equal and opposite)
  frame_a.fx + frame_b.fx = 0
  frame_a.fy + frame_b.fy = 0
  frame_a.tau + frame_b.tau = 0
metadata {"Dyad": {"icons": {"default": "dyad://MultibodyComponents/RelativeForce.svg"}}}
end
```

```dyad
"""
Relative force and torque acting between frame_a and frame_b, defined by input signals.

Applies the input force to frame_b and the reaction (equal and opposite) to frame_a.
The force inputs (force_x, force_y) and torque input are resolved in the frame
selected by the structural parameter `resolve_in_frame` (world, frame_a, or frame_b).
"""
component RelativeForce
  parameter render::Boolean = true
  parameter color::Real[4] = [0.5, 0.5, 0.5, 1.0]
  parameter specular_coefficient::Real = 1.5
  frame_a = Frame2D() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -50, "y1": 450, "x2": 50, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  frame_b = Frame2D() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 950, "y1": 450, "x2": 1050, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  force_x = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 90, "y1": -50, "x2": 190, "y2": 50, "rot": 90}
      },
      "tags": []
    }
  }
  force_y = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": -50, "x2": 550, "y2": 50, "rot": 90}
      },
      "tags": []
    }
  }
  torque = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 810, "y1": -50, "x2": 910, "y2": 50, "rot": 90}
      },
      "tags": []
    }
  }
  "Force arrow visualization at frame_b"
  force_arrow = MultibodyComponents.ArrowShape(render = render, color = color, head_at_origin = true, diameter = arrow_diameter, r = [frame_b.x, frame_b.y, z_position], R = MultibodyComponents.RR(MultibodyComponents.planar_rotation([0, 0, 1], phi, 0)), length_direction = [force_x, force_y, 0], width_direction = [0, 0, 1], length = sqrt(force_x ^ 2 + force_y ^ 2) * scale, width = arrow_diameter, height = arrow_diameter)
  structural parameter resolve_in_frame::MultibodyComponents.ResolveInFrame = MultibodyComponents.ResolveInFrame.FrameA()
  "Scale factor for force visualization (length = force * scale)"
  parameter scale::Real = 0.1
  "Diameter of the force arrow shaft"
  parameter arrow_diameter::Real = MultibodyComponents.world_default_arrow_diameter()
  "z-position of the arrow in animations"
  parameter z_position::Real = 0
  "Angle of resolution frame"
  variable phi::Angle
relations
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.World()
    phi = 0
  end
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameA()
    phi = frame_a.phi
  end
  if resolve_in_frame == MultibodyComponents.ResolveInFrame.FrameB()
    phi = frame_b.phi
  end
  # Apply rotated force to frame_b
  frame_b.fx + cos(phi) * force_x - sin(phi) * force_y = 0
  frame_b.fy + sin(phi) * force_x + cos(phi) * force_y = 0
  frame_b.tau + torque = 0
  # Reaction forces on frame_a (equal and opposite)
  frame_a.fx + frame_b.fx = 0
  frame_a.fy + frame_b.fy = 0
  frame_a.tau + frame_b.tau = 0
metadata {"Dyad": {"icons": {"default": "dyad://MultibodyComponents/RelativeForce.svg"}}}
end
```

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`RelativeForceTest`](PlanarMechanics.RelativeForce.md)
