VoluminousWheel

model VoluminousWheel "Visualizing a voluminous wheel"
    extends Modelica.Mechanics.MultiBody.Interfaces.PartialVisualizer;

    parameter Boolean animation = true "= true, if animation shall be enabled";
    parameter SI.Radius rTire = 0.25 "Radius of the tire";
    parameter SI.Radius rRim = 0.14 "Radius of the rim";
    parameter SI.Radius width = 0.25 "Width of the tire";
    parameter SI.Radius rCurvature = 0.3 "Radius of the tire's cross section";
    parameter Modelica.Mechanics.MultiBody.Types.RealColor color = {64, 64, 64} "Color of tire"
        annotation (Dialog(
            enable = animation,
            colorSelector = true,
            group = "Material properties"));
    parameter Types.SpecularCoefficient specularCoefficient = 0.5 "Reflection of ambient light (= 0: light is completely absorbed)"
        annotation (Dialog(
            enable = animation,
            group = "Material properties"));
    parameter Integer n_rTire = 40 "Number of points along rTire"
        annotation (Dialog(
            enable = animation,
            tab = "Discretization"));
    parameter Integer n_rCurvature = 20 "Number of points along rCurvature"
        annotation (Dialog(
            enable = animation,
            tab = "Discretization"));
protected
    parameter SI.Radius rw = 0.5 * width;
    parameter SI.Radius rCurvature2 = if rw < rCurvature then rCurvature else rw;
    parameter SI.Radius h = sqrt(1 - rw / rCurvature2 * (rw / rCurvature2)) * rCurvature2;
    parameter SI.Length ri = rTire - rCurvature2;
    parameter SI.Radius rRim2 = if rRim < 0 then 0 else if ri + h < rRim then ri + h else rRim;
    Visualizers.Advanced.Shape pipe(shapeType = "pipe", color = color, length = width, width = 2 * (ri + h), height = 2 * (ri + h), lengthDirection = {0, 1, 0}, widthDirection = {0, 0, 1}, extra = rRim2 / (ri + h), r = frame_a.r_0, r_shape = -{0, 1, 0} * (0.5 * width), R = frame_a.R, specularCoefficient = specularCoefficient) if world.enableAnimation and animation annotation (Placement(transformation(extent = {
        {-20, -10}, 
        {0, 10}})));
    Visualizers.Advanced.Surface torus(redeclare function surfaceCharacteristic = Modelica.Mechanics.MultiBody.Visualizers.Advanced.SurfaceCharacteristics.torus(ri = ri, ro = rCurvature2, opening = Modelica.Constants.pi - Modelica.Math.asin(rw / rCurvature2)), nu = n_rTire, nv = n_rCurvature, multiColoredSurface = false, wireframe = false, color = color, specularCoefficient = specularCoefficient, transparency = 0, R = frame_a.R, r_0 = frame_a.r_0) if world.enableAnimation and animation annotation (Placement(transformation(extent = {
        {-50, -10}, 
        {-30, 10}})));
equation
    frame_a.f = zeros(3);
    frame_a.t = zeros(3);

    annotation (
        Icon(graphics = {
            Text(
                extent = {
                    {-150, 100}, 
                    {150, 140}},
                lineColor = {0, 0, 255},
                textString = "%name"), 
            Bitmap(
                extent = {
                    {-96, -96}, 
                    {102, 96}},
                fileName = "modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/VoluminousWheelIcon.png"), 
            Rectangle(
                extent = {
                    {-96, 8}, 
                    {-18, -8}},
                lineColor = {95, 95, 95},
                fillColor = {215, 215, 215},
                fillPattern = FillPattern.HorizontalCylinder)}),
        Documentation(
            info = "<html>\n<p>\nModel <strong>VoluminousWheel</strong> provides a simple visualization of a tire using\na torus and a pipe shape object. The center of the wheel is located at\nconnector frame_a (visualized by the red coordinate system in the figure below).\n</p>\n\n<blockquote>\n<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/VoluminousWheel.png\">\n</blockquote>\n</html>",
            revisions = "<html>\n  <ul>\n  <li> July 2010 by Martin Otter<br>\n       Adapted to the new Surface model.</li>\n  <li> July 2005 by Dirk Zimmer (practical training at DLR)<br>\n       First version to visualize a multi-level tyre wheel model.</li>\n  </ul>\n</html>"));
end VoluminousWheel;