Torus

model Torus "Visualizing a torus"
    extends Modelica.Mechanics.MultiBody.Interfaces.PartialVisualizer;

    parameter Boolean animation = true "= true, if animation shall be enabled";
    parameter Modelica.SIunits.Radius ri = 0.5 "Major radius (distance from center of torus to center of tube)"
        annotation (Dialog(enable = animation));
    parameter Modelica.SIunits.Radius ro = 0.1 "Minor radius (radius of tube)"
        annotation (Dialog(enable = animation));
    parameter Modelica.SIunits.Angle opening = 0 "Opening angle of torus"
        annotation (Dialog(enable = animation));
    parameter Modelica.SIunits.Angle startAngle = -3.1415926535898 "Start angle of torus slice"
        annotation (Dialog(enable = animation));
    parameter Modelica.SIunits.Angle stopAngle = 3.1415926535898 "End angle of torus slice"
        annotation (Dialog(enable = animation));
    parameter Boolean wireframe = false "= true: 3D model will be displayed without faces"
        annotation (
            Dialog(
                enable = animation,
                group = "Material properties"),
            choices(checkBox = true));
    input Modelica.Mechanics.MultiBody.Types.RealColor color = {0, 128, 255} "Color of surface"
        annotation (Dialog(
            enable = animation,
            colorSelector = true,
            group = "Material properties"));
    input Types.SpecularCoefficient specularCoefficient = 0.7 "Reflection of ambient light (= 0: light is completely absorbed)"
        annotation (Dialog(
            enable = animation,
            group = "Material properties"));
    input Real transparency = 0 "Transparency of shape: 0 (= opaque) ... 1 (= fully transparent)"
        annotation (Dialog(
            enable = animation,
            group = "Material properties"));
    parameter Integer n_ri = 40 "Number of points along major radius ri"
        annotation (Dialog(
            enable = animation,
            tab = "Discretization"));
    parameter Integer n_ro = 20 "Number of points along minor radius ro"
        annotation (Dialog(
            enable = animation,
            tab = "Discretization"));
protected
    Advanced.Surface surface(redeclare function surfaceCharacteristic = Modelica.Mechanics.MultiBody.Visualizers.Advanced.SurfaceCharacteristics.torus(ri = ri, ro = ro, opening = opening, startAngle = startAngle, stopAngle = stopAngle), nu = n_ri, nv = n_ro, multiColoredSurface = false, wireframe = wireframe, color = color, specularCoefficient = specularCoefficient, transparency = transparency, R = frame_a.R, r_0 = frame_a.r_0) if world.enableAnimation and animation annotation (Placement(transformation(extent = {
        {-20, -10}, 
        {0, 10}})));
equation
    frame_a.f = zeros(3);
    frame_a.t = zeros(3);

    annotation (
        Icon(graphics = {
            Bitmap(
                extent = {
                    {-98, -98}, 
                    {98, 98}},
                fileName = "modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/TorusIcon.png"), 
            Text(
                extent = {
                    {-150, 100}, 
                    {150, 140}},
                lineColor = {0, 0, 255},
                textString = "%name")}),
        Documentation(
            info = "<html>\n<p>\nModel <strong>Torus</strong> visualizes a torus. The center of the torus is located at\nconnector frame_a (visualized by the red coordinate system in the figure below).\nThe left image below shows a torus with ri=0.5 m and ro = 0.2 m.\nThe right images below shows the torus with the additional parameter\nsettings:\n</p>\n<pre>\n  opening    =   45 degree\n  startAngle = -135 degree\n  stopAngle  =  135 degree\n</pre>\n\n<blockquote>\n<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/Torus.png\">\n</blockquote>\n\n<p>\nIn the advanced menu the discretization of the surface visualization can be defined by\nthe number of points of the inner radius of the torus (n_ri) and by\nthe number of points of the outer radius of the torus (n_ro).\nIn case the torus is closed (that is, opening = 0 degree),\nthe actual number of points is one less (that is n_ri-1, n_ro-1), because the first and\nthe last point of the parametrization coincide in this case.\n</p>\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 Torus;