Skip to content

Commit cb5d903

Browse files
Merge pull request #30 from ModiaSim/gh_useBeamInTutorialModels
Documentation/tutorial: Use Beam instead of Box for pendulum models
2 parents 1230006 + bfa1ba6 commit cb5d903

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed
-52.6 KB
Binary file not shown.
87.2 KB
Loading

docs/src/tutorial/GettingStarted.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ In the following example a simple pendulum is defined. This example is a copy of
1313
```julia
1414
module Pendulum1
1515

16-
using Modia
16+
using Modia
1717

1818
Pendulum = Model(
1919
world = Object3D(feature=Scene()),
@@ -27,6 +27,7 @@ simulate!(pendulum, stopTime=3.0)
2727

2828
@usingModiaPlot # use the plot package defined by ENV["MODIA_PLOT"]
2929
plot(pendulum, "rev.phi")
30+
3031
end
3132
```
3233
or
@@ -46,16 +47,16 @@ The commands above generate an instance of the model, simulate it and generate t
4647

4748
## 2. Pendulum with Animation
4849

49-
The Object3Ds of the first example are extended with [Visual](@ref) and [Solid](@ref) features in order that the pendulum parts are visualized and exported for offline animation by defining `animationFile = "Pendulum2.json"` in [Scene](@ref). The first Object3D `obj1` is defined as a solid [Box](@ref) with `"Blue"`color and its [Solid material](@ref) is made of `"Steel"`. Mass, center of mass and inertia tensor are computed from Steel density and from the [Box](@ref) shape. The second Object3D `obj2` is a visual red [Cylinder](@ref) that is used to visualize the axis of the revolute joint. Please, see example: `$(Modia3D.path)/test/Tutorial/Pendulum2.jl`
50+
The Object3Ds of the first example are extended with [Visual](@ref) and [Solid](@ref) features in order that the pendulum parts are visualized and exported for offline animation by defining `animationFile = "Pendulum2.json"` in [Scene](@ref). The first Object3D `obj1` is defined as a solid [Beam](@ref) with `"Blue"`color and its [Solid material](@ref) is made of `"Steel"`. Mass, center of mass and inertia tensor are computed from Steel density and from the [Beam](@ref) shape. The second Object3D `obj2` is a visual red [Cylinder](@ref) that is used to visualize the axis of the revolute joint. Please, see example: `$(Modia3D.path)/test/Tutorial/Pendulum2.jl`
5051

5152
```julia
5253
module Pendulum2
5354

54-
using Modia
55+
using Modia
5556

5657
Pendulum = Model(
5758
world = Object3D(feature=Scene(animationFile="Pendulum2.json")),
58-
obj1 = Object3D(feature=Solid(shape=Box(lengthX=1.0, lengthY=0.2, lengthZ=0.2),
59+
obj1 = Object3D(feature=Solid(shape=Beam(axis=1, length=1.0, width=0.2, thickness=0.2),
5960
solidMaterial="Steel", visualMaterial=VisualMaterial(color="Blue"))),
6061
obj2 = Object3D(parent=:obj1, feature=Visual(shape=Cylinder(diameter=0.1, length=0.21),
6162
visualMaterial=VisualMaterial(color="Red")), translation=[-0.5, 0.0, 0.0]),
@@ -67,6 +68,7 @@ simulate!(pendulum, stopTime=3.0)
6768

6869
@usingModiaPlot
6970
plot(pendulum, "rev.phi")
71+
7072
end
7173
```
7274
or
@@ -75,13 +77,13 @@ import Modia3D
7577
include("$(Modia3D.path)/test/Tutorial/Pendulum2.jl")
7678
```
7779

78-
Open [https://threejs.org/editor/](https://threejs.org/editor/), import the json file (File --> Import) and inspect the model in threejs:
80+
Open the [three.js editor](https://threejs.org/editor/), import (File --> Import) the [json file](https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4) `Pendulum2.json` in your working directory and inspect the model:
7981

80-
![Tutorial-Pendulum2](../../resources/images/Tutorial/threejs.png)
82+
![Tutorial-Pendulum2](../../resources/images/Tutorial/threejs_editor.png)
8183

84+
View the simulation animation by clicking the Play button in the Object tab.
8285

83-
Export the animation in glb format (File --> Export GLB) and use an glb/glTF-viewer to inspect the animation (for example the 3D-Viewer of Windows 10).
84-
86+
Export the animation in glb format (File --> Export GLB) to view it in a glb/[glTF](https://www.khronos.org/gltf/) viewer (for example the 3D-Viewer of Windows 10).
8587

8688

8789
## 3. Pendulum with Modia equations
@@ -91,14 +93,14 @@ The pendulum model from the previous section is extended with a damper that is d
9193
```julia
9294
module Pendulum3
9395

94-
using Modia
96+
using Modia
9597

9698
# Modia equation-based models
9799
include("$(Modia.modelsPath)/AllModels.jl")
98100

99101
Pendulum = Model(
100102
world = Object3D(feature=Scene(animationFile="Pendulum3.json")),
101-
obj1 = Object3D(feature=Solid(shape=Box(lengthX=1.0, lengthY=0.2, lengthZ=0.2),
103+
obj1 = Object3D(feature=Solid(shape=Beam(axis=1, length=1.0, width=0.2, thickness=0.2),
102104
solidMaterial="Steel", visualMaterial=VisualMaterial(color="Blue"))),
103105
obj2 = Object3D(parent=:obj1, feature=Visual(shape=Cylinder(diameter=0.1, length=0.21),
104106
visualMaterial=VisualMaterial(color="Red")), translation=[-0.5, 0.0, 0.0]),
@@ -115,6 +117,7 @@ simulate!(pendulum, stopTime=3.0)
115117

116118
@usingModiaPlot
117119
plot(pendulum, "rev.phi")
120+
118121
end
119122
```
120123
or
@@ -133,16 +136,20 @@ The commands above generate an instance of the model, simulate it and generate t
133136
All examples of this tutorial are stored in `$(Modia3D.path)/test/Tutorial`.
134137

135138
```julia
136-
import Modia3D
137139
include("$(Modia3D.path)/test/Tutorial/Pendulum1.jl")
138140
include("$(Modia3D.path)/test/Tutorial/Pendulum2.jl")
139141
include("$(Modia3D.path)/test/Tutorial/Pendulum3.jl")
140142
include("$(Modia3D.path)/test/Tutorial/BouncingSphere.jl")
141143
```
142144

143-
To run all tests, execute:
145+
To run all tests without graphics, execute:
144146

145147
```julia
146-
import Modia3D
147148
include("$(Modia3D.path)/test/runtests.jl")
148149
```
150+
151+
To run all tests with visualization and plots, execute:
152+
153+
```julia
154+
include("$(Modia3D.path)/test/runtestsWithGraphics.jl")
155+
```

test/Tutorial/Pendulum1.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Pendulum1
22

3-
using Modia
3+
using Modia
44

55
Pendulum = Model(
66
world = Object3D(feature=Scene()),
@@ -14,4 +14,5 @@ simulate!(pendulum, stopTime=3.0)
1414

1515
@usingModiaPlot # use the plot package defined by ENV["MODIA_PLOT"]
1616
plot(pendulum, "rev.phi")
17+
1718
end

test/Tutorial/Pendulum2.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module Pendulum2
22

3-
using Modia
3+
using Modia
44

55
Pendulum = Model(
66
world = Object3D(feature=Scene(animationFile="Pendulum2.json")),
7-
obj1 = Object3D(feature=Solid(shape=Box(lengthX=1.0, lengthY=0.2, lengthZ=0.2),
7+
obj1 = Object3D(feature=Solid(shape=Beam(axis=1, length=1.0, width=0.2, thickness=0.2),
88
solidMaterial="Steel", visualMaterial=VisualMaterial(color="Blue"))),
99
obj2 = Object3D(parent=:obj1, feature=Visual(shape=Cylinder(diameter=0.1, length=0.21),
1010
visualMaterial=VisualMaterial(color="Red")), translation=[-0.5, 0.0, 0.0]),
@@ -16,4 +16,5 @@ simulate!(pendulum, stopTime=3.0)
1616

1717
@usingModiaPlot
1818
plot(pendulum, "rev.phi")
19+
1920
end

test/Tutorial/Pendulum3.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module Pendulum3
22

3-
using Modia
3+
using Modia
44

55
# Modia equation-based models
66
include("$(Modia.modelsPath)/AllModels.jl")
77

88
Pendulum = Model(
99
world = Object3D(feature=Scene(animationFile="Pendulum3.json")),
10-
obj1 = Object3D(feature=Solid(shape=Box(lengthX=1.0, lengthY=0.2, lengthZ=0.2),
10+
obj1 = Object3D(feature=Solid(shape=Beam(axis=1, length=1.0, width=0.2, thickness=0.2),
1111
solidMaterial="Steel", visualMaterial=VisualMaterial(color="Blue"))),
1212
obj2 = Object3D(parent=:obj1, feature=Visual(shape=Cylinder(diameter=0.1, length=0.21),
1313
visualMaterial=VisualMaterial(color="Red")), translation=[-0.5, 0.0, 0.0]),
@@ -24,4 +24,5 @@ simulate!(pendulum, stopTime=3.0)
2424

2525
@usingModiaPlot
2626
plot(pendulum, "rev.phi")
27+
2728
end

0 commit comments

Comments
 (0)