FixedArrow

model FixedArrow "Visualizing an arrow with dynamically varying size in frame_a"
    import Modelica.Mechanics.MultiBody.Types;

    extends Modelica.Mechanics.MultiBody.Interfaces.PartialVisualizer;

    parameter Boolean animation = true "= true, if animation shall be enabled";
    input SI.Position r_tail[3] = {0, 0, 0} "Vector from frame_a to arrow tail, resolved in frame_a"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input Types.Axis n = {1, 0, 0} "Vector in arrow direction, resolved in frame_a"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input SI.Length length = 0.1 "Length of complete arrow"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input SI.Diameter diameter = world.defaultArrowDiameter "Diameter of arrow line"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input Types.Color color = {0, 0, 255} "Color of arrow"
        annotation (Dialog(
            colorSelector = true,
            group = "if animation = true",
            enable = animation));
    input Types.SpecularCoefficient specularCoefficient = world.defaultSpecularCoefficient "Reflection of ambient light (= 0: light is completely absorbed)"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
protected
    SI.Length headLength = min(length, diameter * Types.Defaults.ArrowHeadLengthFraction);
    SI.Length headWidth = diameter * Types.Defaults.ArrowHeadWidthFraction;
    SI.Length lineLength = max(0, length - headLength);
    Visualizers.Advanced.Shape arrowLine(shapeType = "cylinder", length = lineLength, width = diameter, height = diameter, lengthDirection = n, widthDirection = {0, 1, 0}, color = color, specularCoefficient = specularCoefficient, r_shape = r_tail, r = frame_a.r_0, R = frame_a.R) if world.enableAnimation and animation;
    Visualizers.Advanced.Shape arrowHead(shapeType = "cone", length = headLength, width = headWidth, height = headWidth, lengthDirection = n, widthDirection = {0, 1, 0}, color = color, specularCoefficient = specularCoefficient, r_shape = r_tail + Modelica.Math.Vectors.normalize(n) * lineLength, r = frame_a.r_0, R = frame_a.R) if world.enableAnimation and animation;
equation
    frame_a.f = zeros(3);
    frame_a.t = zeros(3);

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Rectangle(
                    extent = {
                        {-100, 28}, 
                        {20, -28}},
                    lineColor = {128, 128, 128},
                    fillColor = {128, 128, 128},
                    fillPattern = FillPattern.Solid), 
                Polygon(
                    points = {
                        {20, 60}, 
                        {100, 0}, 
                        {20, -60}, 
                        {20, 60}},
                    lineColor = {128, 128, 128},
                    fillColor = {128, 128, 128},
                    fillPattern = FillPattern.Solid), 
                Text(
                    extent = {
                        {-150, 105}, 
                        {150, 65}},
                    textString = "%name",
                    lineColor = {0, 0, 255}), 
                Text(
                    extent = {
                        {-150, -75}, 
                        {150, -105}},
                    textString = "%length")}),
        Documentation(info = "<html>\n<p>\nModel <strong>FixedArrow</strong> defines an arrow that is\nshown at the location of its frame_a.\n<br>&nbsp;\n</p>\n\n<p>\n<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/Arrow.png\" alt=\"model Visualizers.FixedArrow\">\n</p>\n\n<p>\nThe direction of the arrow specified with vector\n<strong>n</strong> is with respect to frame_a, i.e., the local frame to which the\narrow component is attached. The direction and length of the arrow, its diameter\nand color can vary dynamically by\nproviding appropriate expressions in the input fields of the\nparameter menu.\n</p>\n</html>"));
end FixedArrow;