graphicsDataExample.py
You can view and download this file on Github: graphicsDataExample.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: Example for graphicsData
5#
6# Author: Johannes Gerstmayr
7# Date: 2023-03-26
8#
9# Copyright:This file is part of Exudyn. Exudyn is free software. You can redistribute it and/or modify it under the terms of the Exudyn license. See 'LICENSE.txt' for more details.
10#
11#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
13import exudyn as exu
14from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities
15import exudyn.graphics as graphics #only import if it does not conflict
16
17SC = exu.SystemContainer()
18mbs = SC.AddSystem()
19
20
21#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22#rigid pendulum:
23# L = 1 #x-dim of pendulum
24# b = 0.1 #y-dim of pendulum
25
26#create list of graphics data for background
27gList = []
28
29gList += [graphics.CheckerBoard(point=[0,0,-2], normal=[0,0,1], size=5)]
30gList += [graphics.Arrow(pAxis=[-2,-2,-1], vAxis=[0,0,2], radius=0.04, color=graphics.color.yellow)]
31gList += [graphics.Basis(origin=[-2,-1,-1], length=0.5)]
32gList += [graphics.Cylinder(pAxis=[-2,0,-1], vAxis=[0,0,2], radius=0.3, addEdges=4, color=graphics.color.white, nTiles=32)]
33gList += [graphics.Sphere(point=[-2,1,0], radius=0.5, color=graphics.color.white, nTiles=16,
34 addEdges=6, addFaces=True)]
35
36#for hollow solid, use closed contour list:
37contour=[[0,0.],[0,0.1],[0.4,0.1],[0.4,0.2],[0.8,0.3],[1.2,0.]] #if wrong orientation (check normals): contour.reverse()
38gList += [graphics.SolidOfRevolution(pAxis=[0,-2,-1], vAxis=[0,0,1],
39 contour=contour, color=[0.8,0.1,0.1,1], nTiles = 40, addEdges=5)]
40
41#the next two graphics lists are merged into a single list:
42contour=[[0,0.1],[0.,0.2],[1.5,0.3],[1.5,0.15],[0,0.1]]
43g1 = graphics.SolidOfRevolution(pAxis=[0,0,-1], vAxis=[0,0,1],
44 contour=contour, color=[0.8,0.1,0.1,1], nTiles = 6, smoothContour=False, addEdges=6)
45g2 = graphics.SolidExtrusion(vertices=[[-0.4,-0.4], [0.4,-0.4], [ 0.4,0.4], [0.1,0.4],
46 [0.1, 0.2], [-0.1,0.2], [-0.1,0.4], [-0.4,0.4]],
47 segments=[[0,1], [1,2], [2,3], [3,4], [4,5], [5,6], [6,7], [7,0]],
48 pOff = [0,2,-1], height=1.5,
49 color=graphics.color.steelblue, addEdges=2)
50g3 = graphics.MergeTriangleLists(g1,g2)
51#now move and rotate graphicsData:
52g3 = graphics.Move(g3, pOff=[0.25,0,1], Aoff=RotationMatrixX(0.125*pi))
53
54gList+=[g3]
55
56oGround=mbs.AddObject(ObjectGround(referencePosition= [0,0,0], visualization=VObjectGround(graphicsData= gList)))
57
58# graphicsCube = graphics.Brick(size= [L,b,b], color= graphics.color.dodgerblue, addEdges=True)
59# graphicsJoint = graphics.Cylinder(pAxis=[-0.5*L,0,-0.6*b], vAxis= [0,0,1.2*b], radius = 0.55*b, color=graphics.color.darkgrey, addEdges=True)
60
61mbs.CreateRigidBody(inertia = InertiaSphere(1, 0.5),
62 referencePosition = [1,1,0],
63 initialAngularVelocity =[1,0,0],
64 graphicsDataList = [graphics.Sphere(radius=0.5, color=graphics.color.orange, nTiles=32,
65 addEdges=4, addFaces=True)])
66
67
68mbs.Assemble()
69print(mbs)
70
71simulationSettings = exu.SimulationSettings() #takes currently set values or default values
72
73simulationSettings.timeIntegration.numberOfSteps = 100000
74simulationSettings.timeIntegration.endTime = 2000
75simulationSettings.timeIntegration.verboseMode = 1
76simulationSettings.timeIntegration.simulateInRealtime = True
77
78SC.visualizationSettings.openGL.multiSampling = 4
79SC.visualizationSettings.openGL.lineWidth = 2
80SC.visualizationSettings.general.graphicsUpdateInterval = 0.02
81SC.visualizationSettings.window.renderWindowSize=[1920,1200]
82
83exu.StartRenderer()
84mbs.SolveDynamic(simulationSettings)
85
86SC.WaitForRenderEngineStopFlag()
87exu.StopRenderer() #safely close rendering window!