PlanarMechanics.Distance
Measures the distance between the origins of two frame connectors.
This is a sensor component: it reads kinematic quantities without exerting forces or torques. The output is the scalar Euclidean distance between frame_a and frame_b origins. A small regularization parameter s_small prevents numerical issues when the distance approaches zero.
This component extends from PartialTwoFrameSensor This component extends from MultibodyComponents.Renderable
Usage
MultibodyComponents.PlanarMechanics.Distance(render=true, color=[0.5, 0.5, 0.5, 1.0], specular_coefficient=0.7, s_small=1e-10, arrow_diameter=0.03, z_position=0)
Parameters:
| Name | Description | Units | Default value |
|---|---|---|---|
render | – | true | |
color | – | [0.5, 0.5, 0.5, 1] | |
specular_coefficient | – | 0.7 | |
s_small | Small distance threshold for regularization | m | 1e-10 |
arrow_diameter | Diameter of the visualization arrow | – | 0.03 |
z_position | z-position of the arrow in animations | – | 0 |
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)
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)
distance- This connector represents a real signal as an output from a component (RealOutput)
Variables
| Name | Description | Units |
|---|---|---|
L2 | Squared distance | – |
s_small2 | Squared regularization threshold | – |
Behavior
Dict{MIME{Symbol("text/plain")}, String} with 1 entry: MIME type text/plain => "Error displaying result"
Source
"""
Measures the distance between the origins of two frame connectors.
This is a sensor component: it reads kinematic quantities without exerting
forces or torques. The output is the scalar Euclidean distance between frame_a
and frame_b origins. A small regularization parameter `s_small` prevents
numerical issues when the distance approaches zero.
"""
component Distance
extends PartialTwoFrameSensor
extends MultibodyComponents.Renderable(color = [0.5, 0.5, 0.5, 1.0])
"Scalar distance output"
distance = RealOutput() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 450, "y1": 960, "x2": 550, "y2": 1060, "rot": 90}
},
"tags": []
}
}
"Arrow visualization from frame_a to frame_b"
arrow = MultibodyComponents.ArrowShape(render = render, color = color, head_at_origin = false, diameter = arrow_diameter)
"Small distance threshold for regularization"
parameter s_small::Length = 1e-10
"Diameter of the visualization arrow"
parameter arrow_diameter::Real = 0.03
"z-position of the arrow in animations"
parameter z_position::Real = 0
"Squared distance"
variable L2::Real
"Squared regularization threshold"
variable s_small2::Real
relations
# Sensor: zero forces and torques
frame_a.fx = 0
frame_a.fy = 0
frame_a.tau = 0
frame_b.fx = 0
frame_b.fy = 0
frame_b.tau = 0
# Squared distance
L2 = (frame_b.x - frame_a.x) ^ 2 + (frame_b.y - frame_a.y) ^ 2
s_small2 = s_small ^ 2
# Smooth distance (regularized near zero)
distance = ifelse(L2 > s_small2, sqrt(L2), L2 / (2 * s_small) + s_small / 2)
# Arrow visualization from frame_a to frame_b
arrow.r = [frame_a.x, frame_a.y, z_position]
arrow.R = MultibodyComponents.RR(MultibodyComponents.nullrotation())
arrow.r_shape = [0, 0, 0]
arrow.length_direction = [frame_b.x - frame_a.x, frame_b.y - frame_a.y, 0]
arrow.width_direction = [0, 0, 1]
arrow.length = distance
arrow.width = arrow_diameter
arrow.height = arrow_diameter
metadata {
"Dyad": {
"icons": {"default": "dyad://MultibodyComponents/TwoFrameSensor.svg"},
"labels": [{"label": "distance", "x": 500, "y": 680, "rot": 0}]
}
}
endFlattened Source
"""
Measures the distance between the origins of two frame connectors.
This is a sensor component: it reads kinematic quantities without exerting
forces or torques. The output is the scalar Euclidean distance between frame_a
and frame_b origins. A small regularization parameter `s_small` prevents
numerical issues when the distance approaches zero.
"""
component Distance
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": []
}
}
parameter render::Boolean = true
parameter color::Real[4] = [0.5, 0.5, 0.5, 1.0]
parameter specular_coefficient::Real = 0.7
"Scalar distance output"
distance = RealOutput() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 450, "y1": 960, "x2": 550, "y2": 1060, "rot": 90}
},
"tags": []
}
}
"Arrow visualization from frame_a to frame_b"
arrow = MultibodyComponents.ArrowShape(render = render, color = color, head_at_origin = false, diameter = arrow_diameter)
"Small distance threshold for regularization"
parameter s_small::Length = 1e-10
"Diameter of the visualization arrow"
parameter arrow_diameter::Real = 0.03
"z-position of the arrow in animations"
parameter z_position::Real = 0
"Squared distance"
variable L2::Real
"Squared regularization threshold"
variable s_small2::Real
relations
# Sensor: zero forces and torques
frame_a.fx = 0
frame_a.fy = 0
frame_a.tau = 0
frame_b.fx = 0
frame_b.fy = 0
frame_b.tau = 0
# Squared distance
L2 = (frame_b.x - frame_a.x) ^ 2 + (frame_b.y - frame_a.y) ^ 2
s_small2 = s_small ^ 2
# Smooth distance (regularized near zero)
distance = ifelse(L2 > s_small2, sqrt(L2), L2 / (2 * s_small) + s_small / 2)
# Arrow visualization from frame_a to frame_b
arrow.r = [frame_a.x, frame_a.y, z_position]
arrow.R = MultibodyComponents.RR(MultibodyComponents.nullrotation())
arrow.r_shape = [0, 0, 0]
arrow.length_direction = [frame_b.x - frame_a.x, frame_b.y - frame_a.y, 0]
arrow.width_direction = [0, 0, 1]
arrow.length = distance
arrow.width = arrow_diameter
arrow.height = arrow_diameter
metadata {
"Dyad": {
"icons": {"default": "dyad://MultibodyComponents/TwoFrameSensor.svg"},
"labels": [{"label": "distance", "x": 500, "y": 680, "rot": 0}]
}
}
endTest Cases
No test cases defined.
Related
Examples
Experiments
Analyses
Tests