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 *
15
16SC = exu.SystemContainer()
17mbs = SC.AddSystem()
18
19
20#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21#rigid pendulum:
22# L = 1    #x-dim of pendulum
23# b = 0.1  #y-dim of pendulum
24
25#create list of graphics data for background
26gList = []
27
28gList += [GraphicsDataCheckerBoard(point=[0,0,-2], normal=[0,0,1], size=5)]
29gList += [GraphicsDataArrow(pAxis=[-2,-2,-1], vAxis=[0,0,2], radius=0.04, color=color4yellow)]
30gList += [GraphicsDataBasis(origin=[-2,-1,-1], length=0.5)]
31gList += [GraphicsDataCylinder(pAxis=[-2,0,-1], vAxis=[0,0,2], radius=0.3, addEdges=4, color=color4white, nTiles=32)]
32gList += [GraphicsDataSphere(point=[-2,1,0], radius=0.5, color=color4white, nTiles=16,
33                                       addEdges=6, addFaces=True)]
34
35#for hollow solid, use closed contour list:
36contour=[[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()
37gList += [GraphicsDataSolidOfRevolution(pAxis=[0,-2,-1], vAxis=[0,0,1],
38        contour=contour, color=[0.8,0.1,0.1,1], nTiles = 40, addEdges=5)]
39
40#the next two graphics lists are merged into a single list:
41contour=[[0,0.1],[0.,0.2],[1.5,0.3],[1.5,0.15],[0,0.1]]
42g1 = GraphicsDataSolidOfRevolution(pAxis=[0,0,-1], vAxis=[0,0,1],
43        contour=contour, color=[0.8,0.1,0.1,1], nTiles = 6, smoothContour=False, addEdges=6)
44g2 = GraphicsDataSolidExtrusion(vertices=[[-0.4,-0.4], [0.4,-0.4], [ 0.4,0.4], [0.1,0.4],
45                                               [0.1,  0.2], [-0.1,0.2], [-0.1,0.4], [-0.4,0.4]],
46                                     segments=[[0,1], [1,2], [2,3], [3,4], [4,5], [5,6], [6,7], [7,0]],
47                                     pOff = [0,2,-1], height=1.5,
48                                     color=color4steelblue, addEdges=2)
49g3 = MergeGraphicsDataTriangleList(g1,g2)
50#now move and rotate graphicsData:
51g3 = MoveGraphicsData(g3, pOff=[0.25,0,1], Aoff=RotationMatrixX(0.125*pi))
52
53gList+=[g3]
54
55oGround=mbs.AddObject(ObjectGround(referencePosition= [0,0,0], visualization=VObjectGround(graphicsData= gList)))
56
57# graphicsCube = GraphicsDataOrthoCubePoint(size= [L,b,b], color= color4dodgerblue, addEdges=True)
58# graphicsJoint = GraphicsDataCylinder(pAxis=[-0.5*L,0,-0.6*b], vAxis= [0,0,1.2*b], radius = 0.55*b, color=color4darkgrey, addEdges=True)
59
60mbs.CreateRigidBody(inertia = InertiaSphere(1, 0.5),
61             referencePosition = [1,1,0],
62             initialAngularVelocity =[1,0,0],
63             graphicsDataList = [GraphicsDataSphere(radius=0.5, color=color4orange, nTiles=32,
64                                                    addEdges=4, addFaces=True)])
65
66
67mbs.Assemble()
68print(mbs)
69
70simulationSettings = exu.SimulationSettings() #takes currently set values or default values
71
72simulationSettings.timeIntegration.numberOfSteps = 100000
73simulationSettings.timeIntegration.endTime = 2000
74simulationSettings.timeIntegration.verboseMode = 1
75simulationSettings.timeIntegration.simulateInRealtime = True
76
77SC.visualizationSettings.openGL.multiSampling = 4
78SC.visualizationSettings.openGL.lineWidth = 2
79SC.visualizationSettings.general.graphicsUpdateInterval = 0.02
80SC.visualizationSettings.window.renderWindowSize=[1920,1200]
81
82exu.StartRenderer()
83mbs.SolveDynamic(simulationSettings)
84
85SC.WaitForRenderEngineStopFlag()
86exu.StopRenderer() #safely close rendering window!