Module: graphics
This module newly introduces revised graphics functions, coherent with Exudyn terminology; it provides basic graphics elements like cuboid, cylinder, sphere, solid of revolution, etc.; offers also some advanced functions for STL import and mesh manipulation; for some advanced functions see graphicsDataUtilties; GraphicsData helper functions generate dictionaries which contain line, text or triangle primitives for drawing in Exudyn using OpenGL.
Author: Johannes Gerstmayr
Date: 2024-05-10 (created)
Function: Sphere
Sphere(point = [0,0,0], radius = 0.1, color = [0.,0.,0.,1.], nTiles = 8, addEdges = False, edgeColor = color.black, addFaces = True)
- function description:generate graphics data for a sphere with point p and radius
- input:
point: center of sphere (3D list or np.array)radius: positive valuecolor: provided as list of 4 RGBA valuesnTiles: used to determine resolution of sphere >=3; use larger values for finer resolutionaddEdges: True or number of edges along sphere shell (under development); for optimal drawing, nTiles shall be multiple of 4 or 8edgeColor: optional color for edgesaddFaces: if False, no faces are added (only edges) - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
bicycleIftommBenchmark.py (Ex), bungeeJump.py (Ex), chatGPTupdate.py (Ex), contactCurvePolynomial.py (Ex), graphicsDataExample.py (Ex), connectorGravityTest.py (TM), contactCoordinateTest.py (TM), contactCurveExample.py (TM)
Function: Lines
Lines(pList, color = [0.,0.,0.,1.])
- function description:generate graphics data for lines, given by list of points and color; transforms to GraphicsData dictionary
- input:
pList: list of 3D numpy arrays or lists (to achieve closed curve, set last point equal to first point)color: provided as list of 4 RGBA values - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
- example:
#create simple 3-point lines
gLine=graphics.Lines([[0,0,0],[1,0,0],[2,0.5,0]], color=color.red)
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
ANCFcontactCircle2.py (Ex), doublePendulum2D.py (Ex), simple4linkPendulumBing.py (Ex), doublePendulum2DControl.py (TM)
Function: Circle
Circle(point = [0,0,0], radius = 1, color = [0.,0.,0.,1.])
- function description:generate graphics data for a single circle; currently the plane normal = [0,0,1], just allowing to draw planar circles – this may be extended in future!
- input:
point: center point of circleradius: radius of circlecolor: provided as list of 4 RGBA values - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
- notes:the tiling (number of segments to draw circle) can be adjusted by visualizationSettings.general.circleTiling
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
Function: Text
Text(point = [0,0,0], text = '', color = [0.,0.,0.,1.])
- function description:generate graphics data for a text drawn at a 3D position
- input:
point: position of texttext: string representing textcolor: provided as list of 4 RGBA values**nodes: text size can be adjusted with visualizationSettings.general.textSize, which affects the text size (=font size) globally - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
ANCFcontactCircle2.py (Ex), NGsolveGeometry.py (Ex)
Function: Cuboid
Cuboid(pList, color = [0.,0.,0.,1.], faces = [1,1,1,1,1,1], addNormals = False, addEdges = False, edgeColor = color.black, addFaces = True)
- function description:generate graphics data for general block with endpoints, according to given vertex definition
- input:
pList: is a list of points [[x0,y0,z0],[x1,y1,z1],…]color: provided as list of 4 RGBA valuesfaces: includes the list of six binary values (0/1), denoting active faces (value=1); set index to zero to hide faceaddNormals: if True, normals are added and there are separate points for every triangleaddEdges: if True, edges are added in TriangleList of GraphicsDataedgeColor: optional color for edgesaddFaces: if False, no faces are added (only edges) - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
Function: BrickXYZ
BrickXYZ(xMin, yMin, zMin, xMax, yMax, zMax, color = [0.,0.,0.,1.], addNormals = False, addEdges = False, edgeColor = color.black, addFaces = True)
- function description:generate graphics data for orthogonal 3D block with min and max dimensions
- input:
x/y/z/Min/Max: minimal and maximal cartesian coordinates for orthogonal cubecolor: list of 4 RGBA valuesaddNormals: add face normals to triangle informationaddEdges: if True, edges are added in TriangleList of GraphicsDataedgeColor: optional color for edgesaddFaces: if False, no faces are added (only edges) - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
- notes:DEPRECATED
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
Function: Brick
Brick(centerPoint = [0,0,0], size = [0.1,0.1,0.1], color = [0.,0.,0.,1.], addNormals = False, addEdges = False, edgeColor = color.black, addFaces = True, roundness = 0, nTiles = 12)
- function description:generate graphics data for orthogonal 3D box with center point and size; using roundness=1, it draws an ellipsoid inside the box and in case 0 < roundness < 1, it draws a body blended between box and ellipsoid
- input:
centerPoint: center of box as 3D list or np.arraysize: size as 3D list or np.arraycolor: list of 4 RGBA valuesaddNormals: add face normals to triangle informationaddEdges: if True, edges are added in TriangleList of GraphicsDataedgeColor: optional color for edgesaddFaces: if False, no faces are added (only edges)roundness: if > 0, it draws an ellipsoid, using nTiles for drawing; edges are not available if roundness > 0nTiles: only apply if roundness > 0; discretization of whole ellipsoid; should be multiple of 4 to avoid artifacts - output:graphicsData dictionary, to be used in visualization of EXUDYN objects; if addEdges=True, it returns a list of two dictionaries
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
addPrismaticJoint.py (Ex), addRevoluteJoint.py (Ex), ANCFrotatingCable2D.py (Ex), ballBearningModel.py (Ex), beltDrivesComparison.py (Ex), ballBearingTest.py (TM), bricardMechanism.py (TM), carRollingDiscTest.py (TM)
Function: Cylinder
Cylinder(pAxis = [0,0,0], vAxis = [0,0,1], radius = 0.1, color = [0.,0.,0.,1.], nTiles = 16, radiusInner = None, angleRange = [0,2*pi], lastFace = True, cutPlain = True, addEdges = False, edgeColor = color.black, addFaces = True, **kwargs)
- function description:generate graphics data for a cylinder with given axis, radius and color; nTiles gives the number of tiles (minimum=3)
- input:
pAxis: axis point of one face of cylinder (3D list or np.array)vAxis: vector representing the cylinder’s axis (3D list or np.array)radius: positive value representing radius of cylindercolor: provided as list of 4 RGBA valuesnTiles: used to determine resolution of cylinder >=3; use larger values for finer resolutionradiusInner: if not equal 0, this represents the inner radius of a hollow cylinder; some options like angleRange, lastFace, etc. do not work in this caseangleRange: given in rad, to draw only part of cylinder (halfcylinder, etc.); for full range use [0..2 * pi]lastFace: if angleRange != [0,2*pi], then the faces of the open cylinder are shown with lastFace = TruecutPlain: only used for angleRange != [0,2*pi]; if True, a plane is cut through the part of the cylinder; if False, the cylinder becomes a cake shape …addEdges: if True, edges are added in TriangleList of GraphicsData; if addEdges is integer, additional int(addEdges) lines are added on the cylinder mantleedgeColor: optional color for edgesaddFaces: if False, no faces are added (only edges)alternatingColor: if given, optionally another color in order to see rotation of solid; only works, if angleRange=[0,2*pi] - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
beltDriveALE.py (Ex), beltDriveReevingSystem.py (Ex), beltDrivesComparison.py (Ex), bicycleIftommBenchmark.py (Ex), chainDriveExample.py (Ex), ANCFbeltDrive.py (TM), ANCFgeneralContactCircle.py (TM), coordinateSpringDamperExt.py (TM)
Function: Tube
Tube(points, axes, radius = 0.1, color = [0.,0.,0.,1.], nTiles = 16)
- function description:generate graphics data for a tube with given list of points and axes, radius and color; nTiles gives the number of tiles (minimum=3)
- input:
points: list of 3D vectors (or numpy arrays) representing the center points of the tube lineaxes: list of 3D vectors (or numpy arrays) representing the axis according to the pointsradius: positive value representing radius of tubecolor: provided as list of 4 RGBA valuesnTiles: used to determine resolution of cylinder >=3; use larger values for finer resolution - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
Function: Torus
Torus(point, axis, radiusMajor = 0.5, radiusMinor = 0.1, color = [0., 0., 0., 1.], nTilesMajor = 24, nTilesMinor = 12, minorAngleStart = 0, minorAngleEnd = 2*np.pi, smoothNormals = True, invert = False)
- function description:generate graphics data for a torus with given major and minor radius, center point and axis
- input:
point: 3D vector (or numpy array) representing the center point of the torusaxis: 3D vector (or numpy array) representing the axis of revolution of the torusradiusMajor: major radius of torusradiusMinor: minor radius of toruscolor: provided as list of 4 RGBA valuesnTilesMajor: used to for resolution of tube with major radius; use larger values for finer resolutionnTilesMinor: used to for resolution of circle with minor radius; use larger values for finer resolutionminorAngleStart: starting angle for minor radius; 0 is the angle at outmost radius of torus, pi is at insideminorAngleEnd: end angle for minor radius; use -0.5*pi / 0.5*pi to draw only the outer half of the torussmoothNormals: if True, the normals are added to create a smooth contour, otherwise triangles are flatinvert: if False, the outside faces are visible; if invert=True, the inside faces are visible (influences reflections, light, etc.) - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
Function: RigidLink
RigidLink(p0, p1, axis0 = [0,0,0], axis1 = [0,0,0], radius = [0.1,0.1], thickness = 0.05, width = [0.05,0.05], color = [0.,0.,0.,1.], nTiles = 16)
- function description:generate graphics data for a planar Link between the two joint positions, having two axes
- input:
p0: joint0 center positionp1: joint1 center positionaxis0: direction of rotation axis at p0, if drawn as a cylinder; [0,0,0] otherwiseaxis1: direction of rotation axis of p1, if drawn as a cylinder; [0,0,0] otherwiseradius: list of two radii [radius0, radius1], being the two radii of the joints drawn by a cylinder or spherewidth: list of two widths [width0, width1], being the two widths of the joints drawn by a cylinder; ignored for spherethickness: the thickness of the link (shaft) between the two joint positions; thickness in z-direction or diameter (cylinder)color: provided as list of 4 RGBA valuesnTiles: used to determine resolution of cylinder >=3; use larger values for finer resolution - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
fourBarMechanism3D.py (Ex), geneticOptimizationSliderCrank.py (Ex), multiMbsTest.py (Ex), openVRengine.py (Ex), pistonEngine.py (Ex), fourBarMechanismIftomm.py (TM), rollingDiscTangentialForces.py (TM), sliderCrank3Dbenchmark.py (TM)
Function: SolidOfRevolution
SolidOfRevolution(pAxis, vAxis, contour, color = [0.,0.,0.,1.], nTiles = 16, smoothContour = False, addEdges = False, edgeColor = color.black, addFaces = True, smoothingAngle = 2*np.pi, **kwargs)
- function description:generate graphics data for a solid of revolution with given 3D point and axis, 2D point list for contour, (optional)2D normals and color;
- input:
pAxis: axis point of one face of solid of revolution (3D list or np.array)vAxis: vector representing the solid of revolution’s axis (3D list or np.array)contour: a list of 2D-points, specifying the contour (x=axis, y=radius), e.g.: [[0,0],[0,0.1],[1,0.1]]color: provided as list of 4 RGBA valuesnTiles: used to determine resolution of solid; use larger values for finer resolutionsmoothContour: if True, the contour is made smooth by auto-computing normals to the contouraddEdges: True or number of edges along revolution mantle; for optimal drawing, nTiles shall be multiple addEdgesedgeColor: optional color for edgesaddFaces: if False, no faces are added (only edges)smoothingAngle: if angle between two edges is smaller than smoothingAngle, smoothing is appliedalternatingColor: add a second color, which enables to see the rotation of the solid - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
- example:
#simple contour, using list of 2D points:
contour=[[0,0.2],[0.3,0.2],[0.5,0.3],[0.7,0.4],[1,0.4],[1,0.]]
rev1 = graphics.SolidOfRevolution(pAxis=[0,0.5,0], vAxis=[1,0,0],
contour=contour, color=color.red,
alternatingColor=color.grey)
#draw torus:
contour=[]
r = 0.2 #small radius of torus
R = 0.5 #big radius of torus
nc = 16 #discretization of torus
for i in range(nc+3): #+3 in order to remove boundary effects
contour+=[[r*cos(i/nc*pi*2),R+r*sin(i/nc*pi*2)]]
#use smoothContour to make torus looking smooth
rev2 = graphics.SolidOfRevolution(pAxis=[0,0.5,0], vAxis=[1,0,0],
contour=contour, color=color.red,
nTiles = 64, smoothContour=True)
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
ballBearningModel.py (Ex), graphicsDataExample.py (Ex), gyroStability.py (Ex), involuteGearGraphics.py (Ex), particlesSilo.py (Ex), ballBearingTest.py (TM), ConvexContactTest.py (TM)
Function: Arrow
Arrow(pAxis, vAxis, radius, color = [0.,0.,0.,1.], headFactor = 2, headStretch = 4, nTiles = 12)
- function description:generate graphics data for an arrow with given origin, axis, shaft radius, optional size factors for head and color; nTiles gives the number of tiles (minimum=3)
- input:
pAxis: axis point of the origin (base) of the arrow (3D list or np.array)vAxis: vector representing the vector pointing from the origin to the tip (head) of the error (3D list or np.array)radius: positive value representing radius of shaft cylinderheadFactor: positive value representing the ratio between head’s radius and the shaft radiusheadStretch: positive value representing the ratio between the head’s radius and the head’s lengthcolor: provided as list of 4 RGBA valuesnTiles: used to determine resolution of arrow (of revolution object) >=3; use larger values for finer resolution - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
beltDriveALE.py (Ex), beltDriveReevingSystem.py (Ex), beltDrivesComparison.py (Ex), graphicsDataExample.py (Ex), reevingSystem.py (Ex), ACFtest.py (TM), ANCFbeltDrive.py (TM), ANCFgeneralContactCircle.py (TM)
Function: Basis
Basis(origin = [0,0,0], rotationMatrix = np.eye(3), length = 1, colors = [color.red, color.green, color.blue], headFactor = 2, headStretch = 4, nTiles = 12, **kwargs)
- function description:generate graphics data for three arrows representing an orthogonal basis with point of origin, shaft radius, optional size factors for head and colors; nTiles gives the number of tiles (minimum=3)
- input:
origin: point of the origin of the base (3D list or np.array)rotationMatrix: optional transformation, which rotates the basis vectorslength: positive value representing lengths of arrows for basiscolors: provided as list of 3 colors (list of 4 RGBA values)headFactor: positive value representing the ratio between head’s radius and the shaft radiusheadStretch: positive value representing the ratio between the head’s radius and the head’s lengthnTiles: used to determine resolution of arrows of basis (of revolution object) >=3; use larger values for finer resolutionradius: positive value representing radius of arrows; default: radius = 0.01*length - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
ballBearningModel.py (Ex), camFollowerExample.py (Ex), fourBarMechanism3D.py (Ex), graphicsDataExample.py (Ex), gyroStability.py (Ex), ballBearingTest.py (TM), bricardMechanism.py (TM), contactCurveExample.py (TM)
Function: Frame
Frame(HT = np.eye(4), length = 1, colors = [color.red, color.green, color.blue], headFactor = 2, headStretch = 4, nTiles = 12, **kwargs)
- function description:generate graphics data for frame (similar to Basis), showing three arrows representing an orthogonal basis for the homogeneous transformation HT; optional shaft radius, optional size factors for head and colors; nTiles gives the number of tiles (minimum=3)
- input:
HT: homogeneous transformation representing framelength: positive value representing lengths of arrows for basiscolors: provided as list of 3 colors (list of 4 RGBA values)headFactor: positive value representing the ratio between head’s radius and the shaft radiusheadStretch: positive value representing the ratio between the head’s radius and the head’s lengthnTiles: used to determine resolution of arrows of basis (of revolution object) >=3; use larger values for finer resolutionradius: positive value representing radius of arrows; default: radius = 0.01*length - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
Function: Quad
Quad(pList, color = [0.,0.,0.,1.], **kwargs)
- function description:generate graphics data for simple quad with option for checkerboard pattern;points are arranged counter-clock-wise, e.g.: p0=[0,0,0], p1=[1,0,0], p2=[1,1,0], p3=[0,1,0]
- input:
pList: list of 4 quad points [[x0,y0,z0],[x1,y1,z1],…]color: provided as list of 4 RGBA valuesalternatingColor: second color; if defined, a checkerboard pattern (default: 10x10) is drawn with color and alternatingColornTiles: number of tiles for checkerboard pattern (default: 10)nTilesY: if defined, use number of tiles in y-direction different from x-direction (=nTiles) - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
- example:
plane = graphics.Quad([[-8, 0, -8],[ 8, 0, -8,],[ 8, 0, 8],[-8, 0, 8]],
color.darkgrey, nTiles=8,
alternatingColor=color.lightgrey)
oGround=mbs.AddObject(ObjectGround(referencePosition=[0,0,0],
visualization=VObjectGround(graphicsData=[plane])))
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
massSpringFrictionInteractive.py (Ex), nMassOscillator.py (Ex), nMassOscillatorEigenmodes.py (Ex), nMassOscillatorInteractive.py (Ex), simulateInteractively.py (Ex), sphereTriangleTest.py (TM)
Function: CheckerBoard
CheckerBoard(point = [0,0,0], normal = [0,0,1], size = 1, color = color.lightgrey, alternatingColor = color.lightgrey2, nTiles = 10, **kwargs)
- function description:function to generate checkerboard background;points are arranged counter-clock-wise, e.g.:
- input:
point: midpoint of pattern provided as list or np.arraynormal: normal to plane provided as list or np.arraysize: dimension of first side length of quadsize2: dimension of second side length of quadcolor: provided as list of 4 RGBA valuesalternatingColor: second color; if defined, a checkerboard pattern (default: 10x10) is drawn with color and alternatingColornTiles: number of tiles for checkerboard pattern in first directionnTiles2: number of tiles for checkerboard pattern in second direction; default: nTilesmaterialIndex: use special graphics material for both colors - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
- example:
plane = graphics.CheckerBoard(normal=[0,0,1], size=5)
oGround=mbs.AddObject(ObjectGround(referencePosition=[0,0,0],
visualization=VObjectGround(graphicsData=[plane])))
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
ANCFrotatingCable2D.py (Ex), ballBearningModel.py (Ex), bicycleIftommBenchmark.py (Ex), camFollowerExample.py (Ex), chainDriveExample.py (Ex), ANCFoutputTest.py (TM), ballBearingTest.py (TM), bricardMechanism.py (TM)
Function: SolidExtrusion
SolidExtrusion(vertices, segments, height, rot = np.diag([1,1,1]), pOff = [0,0,0], relRot = np.diag([1,1,1]), relOff = [0,0,0], color = [0,0,0,1], smoothNormals = False, addEdges = False, edgeColor = color.black, addFaces = True)
- function description:create graphicsData for solid extrusion based on 2D points and segments; by default, the extrusion is performed in z-direction;additional transformations are possible to translate and rotate the extruded body;
- input:
vertices: list of pairs of coordinates of vertices in mesh [x,y], see ComputeTriangularMesh(…)segments: list of segments, which are pairs of node numbers [i,j], defining the boundary of the mesh;the ordering of the nodes is such that left triangle = inside, right triangle = outside; see ComputeTriangularMesh(…)height: height of extruded objectrot: rotation matrix, which the whole extruded object point coordinates are multiplied with before adding offsetpOff: 3D offset vector added to all extruded coordinates (both planes); the z-coordinate of the extrusion object obtains 0 for the base plane, z=height for the top planerelRot: rotation matrix for transformation of top (second) plane of extrusion objectrelOff: 3D offset vector added top (second) plane of extrusion object; the z-coordinate is added to height, which is the base z-valuecolor: provided as list of 4 RGBA valuessmoothNormals: if True, algorithm tries to smoothen normals at vertices and normals are added; creates more points; if False, triangle normals are used internallyaddEdges: if True or 1, edges at bottom/top are included in the GraphicsData dictionary; if 2, also mantle edges are includededgeColor: optional color for edgesaddFaces: if False, no faces are added (only edges) - output:graphicsData dictionary, to be used in visualization of EXUDYN objects
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
chainDriveExample.py (Ex), graphicsDataExample.py (Ex), simulatorCouplingTwoMbs.py (TM)
Function: BallBearingRings
BallBearingRings(axis, outsideDiameter, boreDiameter, width, radiusCage, innerRingShoulderRadius, outerRingShoulderRadius, widthCage, heightCage, innerEdgeChamfer, outerEdgeChamfer, innerGrooveRadius, outerGrooveRadius, innerGrooveTorusRadius, outerGrooveTorusRadius, nTilesRings = 32, nTilesGrooves = 12, colorCage = [0.6,0.5,0.5,0.4], colorInnerRing = [0.5,0.5,0.5,0.5], colorOuterRing = [0.5,0.5,0.5,0.5], **kwargs)
- function description:generate graphics for ball bearing rings, in particular for inner and outer rings; note that base parameters are identical as in function GetBallBearingData, assuming that the dictionary of the latter function is used as input for BallBearingRings
- input:
innerGrooveTorusRadius: major radius of torus for inner grooveouterGrooveTorusRadius: major radius of torus for outer groovenTilesRings: circumferential tiling of ringsnTilesGrooves: tiling of groovescolorCage: cage RGBA colorcolorInnerRing: inner ring RGBA colorcolorOuterRing: outer ring RGBA color - output:dictionary of graphics data containing ‘innerRingGraphics’, ‘outerRingGraphics’ and ‘cageGraphics’; Note: graphics data is in the local bearing coordinate system, which should align with inner ring, outer ring and cage bodies!
- example:
import exudyn.graphics as graphics
from machines import GetBallBearingData
data = GetBallBearingData(axis=[0,0,1], outsideDiameter=0.080,
boreDiameter=0.050, width=0.010, nBalls=12)
graphicsData = graphics.BallBearingRings(**data)
#... graphicsData now contains graphics of rings
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
ballBearningModel.py (Ex), ballBearingTest.py (TM)
Function: InvoluteGear
InvoluteGear(involuteGear, width, centerPoint = np.zeros(3), rotationMatrix = np.eye(3), helixAngleDeg = 0, radius = 0, relativeAngleOffset = 0, color = [0,0,0,1], nTilesCylinder = 32, smoothNormals = False, addEdges = False, edgeColor = color.black, addFaces = True)
- function description:create graphics for involute gear, using data from machines.InvoluteGear
- input:
involuteGear: an instance of the class machines.InvoluteGear, containing gear datawidth: width of gearcenterPoint: used to shift the center point of the gear; if 0, the center is in the middle of the gearrotationMatrix: the gear is constructed in the x-y plane, with the gear axis [0,0,1]; to get any other axis, provide the rotation matrixhelixAngleDeg: optional angle for helix gears in degree; note that this is only an approximation to real helical gear geometry!radius: in case of internal gear, this is the outer radius; for regular gear, this is the bore radiusrelativeAngleOffset: angular offset (about gear wheel axis) relative to the angle of one tooth and gap; 0.5 means that the tooth goes to the position of the gapcolor: provided as list of 4 RGBA valuessmoothNormals: if True, algorithm tries to smoothen normals at vertices and normals are added; creates more points; if False, triangle normals are used internallyaddEdges: if True or 1, edges at bottom/top are included in the GraphicsData dictionary; if 2, also mantle edges are includededgeColor: optional color for edgesaddFaces: if False, no faces are added (only edges) - output:single graphics data for gear
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
Function: ToothedRack
ToothedRack(module, nTeeth, width, toothHeight, rackBaseHeight, pressureAngleDeg = 20, centerPoint = np.zeros(3), rotationMatrix = np.eye(3), color = [0,0,0,1], nTilesCylinder = 32, addEdges = False, edgeColor = color.black, addFaces = True)
- function description:create graphics for toothed rack
- input:
module: the module in m; thus, m*pi represents the mid-distance of one tooth to the next onewidth: width of gearnTeeth: number of teeth used; this gives the length; if this is a float number, only part of the last root or tooth are drawn accordinglytoothHeight: height of tooth from root to headrackBaseHeight: height of rack below rootpressureAngleDeg: pressure angle in degree for tooth shapecenterPoint: used to shift the center point of the gear; if 0, the center is at the start point of the generated toothed rack (x=0,y=0), z=0 is in the middle of the rackrotationMatrix: the gear is constructed in the x-y plane, with width along z-axiscolor: provided as list of 4 RGBA valuessmoothNormals: if True, algorithm tries to smoothen normals at vertices and normals are added; creates more points; if False, triangle normals are used internallyaddEdges: if True or 1, edges at bottom/top are included in the GraphicsData dictionary; if 2, also mantle edges are includededgeColor: optional color for edgesaddFaces: if False, no faces are added (only edges) - output:single graphics data for gear
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
Function: FromPointsAndTrigs
FromPointsAndTrigs(points, triangles, color = [0.,0.,0.,1.], normals = None)
- function description:convert triangles and points as returned from graphics.ToPointsAndTrigs(…) to GraphicsData; additionally, normals and color(s) can be provided
- input:
points: list or np.array with np rows of 3 columns (floats) per point (with np points)triangles: list or np.array with 3 int per triangle (0-based indices to triangles), giving a matrix with nt rows and 3 columns (with nt triangles)color: provided as list of 4 RGBA values or single list of (np)*[4 RGBA values]normals: if not None, they have to be provided per point (as matrix, list of lists or flattened) and will be added to returned GraphicsData - output:returns GraphicsData with type TriangleList
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
NGsolveGeometry.py (Ex), NGsolveOCCgeometry.py (Ex), particlesSilo.py (Ex), distanceSensor.py (TM), generalContactFrictionTests.py (TM)
Function: ToPointsAndTrigs
- function description:convert graphics data into list of points and list of triangle indices (triplets)
- input:g contains a GraphicsData with type TriangleList
- output:returns [points, triangles], with points as list of np.array with 3 floats per point and triangles as a list of np.array with 3 int per triangle (0-based indices to points)
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
mobileMecanumWheelRobotWithLidar.py (Ex), particleClusters.py (Ex), particlesSilo.py (Ex), reinforcementLearningRobot.py (Ex), serialRobotKinematicTreeDigging.py (Ex), distanceSensor.py (TM), generalContactCylinderTest.py (TM), generalContactCylinderTrigsTest.py (TM)
Function: Move
Move(g, pOff, Aoff = None)
- function description:add rigid body transformation to GraphicsData, using position offset (global) pOff (list or np.array) and rotation Aoff (transforms local to global coordinates; list of lists or np.array); see Aoff how to scale coordinates!
- input:
g: graphicsData to be transformedpOff: 3D offset as list or numpy.array added to rotated pointsAoff: 3D rotation matrix as list of lists or numpy.array with shape (3,3); if A is scaled by factor, e.g. using 0.001*np.eye(3), you can also scale the coordinates; if Aoff=None, no rotation is performed - output:returns new graphcsData object to be used for drawing in objects
- notes:transformation corresponds to HomogeneousTransformation(Aoff, pOff), transforming original coordinates v into vNew = pOff + Aoff @ v
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
ballBearningModel.py (Ex), graphicsDataExample.py (Ex), humanRobotInteraction.py (Ex), kinematicTreeAndMBS.py (Ex), openVRengine.py (Ex), rigidBodyAsUserFunctionTest.py (TM)
Function: MergeTriangleLists
MergeTriangleLists(g1, g2)
- function description:merge 2 different graphics data with triangle lists
- input:graphicsData dictionaries g1 and g2 obtained from GraphicsData functions
- output:one graphicsData dictionary with single triangle lists and compatible points and normals, to be used in visualization of EXUDYN objects; edges are merged; edgeColor is taken from graphicsData g1
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
graphicsDataExample.py (Ex), mobileMecanumWheelRobotWithLidar.py (Ex), particleClusters.py (Ex), particlesSilo.py (Ex), serialRobotKinematicTreeDigging.py (Ex), distanceSensor.py (TM), generalContactFrictionTests.py (TM), laserScannerTest.py (TM)
Function: InvertTriangles
InvertTriangles(graphicsData, invertTriangles = True, invertVertexNormals = True)
- function description:invert triangle orientation and triangle normals (or only one of these tasks); can also check consistency of normals
- input:
graphicsData: graphicsData as returned e.g. from graphics.SphereinvertTriangles: if True, it inverts the triangle orientation (changing vertex index 0 and 1)invertVertexNormals: if True, the direction of normal is flipped - output:returns new graphicsData (copy) with modified triangles and normals
Function: InconsistentTriangles
InconsistentTriangles(graphicsData)
- function description:check consistency of orientation of triangles and vertex (point) normals
- input:graphicsData: graphicsData as returned e.g. from graphics.Sphere
- output:returns number of cases in which triangle normals and vertex normals are inconsistent (scalar product is negative)
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
Function: NGsolveMesh2PointsAndTrigs
NGsolveMesh2PointsAndTrigs(mesh = None, ngMesh = None, meshOrder = 2, scale = 1, addNormals = True, verbose = False)
- function description:convert NGsolve (surface) mesh into (surface) points and triangles; clearly, it requires to have ngsolve installed
- input:
mesh: a ngsolve mesh; having a geometry geo = OCCGeometry(…), mesh is returned from ngsolve.Mesh(geo.GenerateMesh(…))ngMesh: a netgen mesh; having a geometry geo = OCCGeometry(…), ngMesh is returned from geo.GenerateMesh(…)meshOrder: either 1 (linear, flat triangles) or 2 (quadratic, smooth triangles)scale: additional scaling factor for geometry, as it is recommended to define netgen geometries in mm due to tolerancesaddNormals: if True, it computes and adds normalsverbose: print debug information - output:[points, triangles] or if addNormals=True, [points, triangles, normals] for further usage in graphics.FromPointsAndTrigs(…)
- example:
#assume having already a body of netgen OCCGeometry
geo = OCCGeometry(body)
ngMesh = geo.GenerateMesh(maxh=maxh)
#convert mesh into points, triangles and normals (with second-order elements!)
[points, triangles, normals] = graphics.NGsolveMesh2PointsAndTrigs(mesh=ngMesh)
#convert into graphicsData
gMesh = graphics.FromPointsAndTrigs( points, triangles, normals=normals,
color=graphics.color.red)
#use the mesh on a ground object
mbs.CreateGround(graphicsDataList=[gMesh])
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
NGsolveOCCgeometry.py (Ex), NGsolvePistonEngine.py (Ex)
Function: FromSTLfileASCII
FromSTLfileASCII(fileName, color = [0.,0.,0.,1.], verbose = False, invertNormals = True, invertTriangles = True)
- function description:generate graphics data from STL file (text format!) and use color for visualization; this function is slow, use stl binary files with FromSTLfile(…)
- input:
fileName: string containing directory and filename of STL-file (in text / SCII format) to loadcolor: provided as list of 4 RGBA valuesverbose: if True, useful information is provided during readinginvertNormals: if True, orientation of normals (usually pointing inwards in STL mesh) are inverted for compatibility in ExudyninvertTriangles: if True, triangle orientation (based on local indices) is inverted for compatibility in Exudyn - output:creates graphicsData, inverting the STL graphics regarding normals and triangle orientations (interchanged 2nd and 3rd component of triangle index)
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
NGsolveOCCgeometry.py (Ex), stlFileImport.py (Ex)
Function: FromSTLfile
FromSTLfile(fileName, color = [0.,0.,0.,1.], verbose = False, density = 0., scale = 1., Aoff = [], pOff = [], invertNormals = True, invertTriangles = True)
- function description:generate graphics data from STL file, allowing text or binary format; requires numpy-stl to be installed; additionally can scale, rotate and translate
- input:
fileName: string containing directory and filename of STL-file (in text / SCII format) to loadcolor: provided as list of 4 RGBA valuesverbose: if True, useful information is provided during readingdensity: if given and if verbose, mass, volume, inertia, etc. are computedscale: point coordinates are transformed by scaling factorinvertNormals: if True, orientation of normals (usually pointing inwards in STL mesh) are inverted for compatibility in ExudyninvertTriangles: if True, triangle orientation (based on local indices) is inverted for compatibility in Exudyn - output:creates graphicsData, inverting the STL graphics regarding normals and triangle orientations (interchanged 2nd and 3rd component of triangle index)
- notes:the model is first scaled, then rotated, then the offset pOff is added; finally min, max, mass, volume, inertia, com are computed!
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
humanRobotInteraction.py (Ex), ROSTurtle.py (Ex), stlFileImport.py (Ex)
Function: AddEdgesAndSmoothenNormals
AddEdgesAndSmoothenNormals(graphicsData, edgeColor = color.black, edgeAngle = 0.25*pi, pointTolerance = 5, addEdges = True, smoothNormals = True, roundDigits = 5, triangleColor = [])
- function description:compute and return GraphicsData with edges and smoothend normals for mesh consisting of points and triangles (e.g., as returned from GraphicsData2PointsAndTrigs)
graphicsData: single GraphicsData object of type TriangleList; existing edges are ignorededgeColor: optional color for edgesedgeAngle: angle above which edges are added to geometryroundDigits: number of digits, relative to max dimensions of object, at which points are assumed to be equalsmoothNormals: if True, algorithm tries to smoothen normals at vertices; otherwise, uses triangle normalsaddEdges: if True, edges are added in TriangleList of GraphicsDatatriangleColor: if triangleColor is set to a RGBA color, this color is used for the new triangle mesh throughout - output:returns GraphicsData with added edges and smoothed normals
- notes:this function is suitable for STL import; it assumes that all colors in graphicsData are the same and only takes the first color!
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
humanRobotInteraction.py (Ex), NGsolveGeometry.py (Ex), NGsolveOCCgeometry.py (Ex), stlFileImport.py (Ex)
Function: ExportSTL
ExportSTL(graphicsData, fileName, solidName = 'ExudynSolid', invertNormals = True, invertTriangles = True)
- function description:export given graphics data (only type TriangleList allowed!) to STL ascii file using fileName
- input:
graphicsData: a single GraphicsData dictionary with type=’TriangleList’, no list of GraphicsDatafileName: file name including (local) path to export STL filesolidName: optional name used in STL fileinvertNormals: if True, orientation of normals (usually pointing inwards in STL mesh) are inverted for compatibility in ExudyninvertTriangles: if True, triangle orientation (based on local indices) is inverted for compatibility in Exudyn
Relevant Examples (Ex) and TestModels (TM) with weblink to github:
NGsolveOCCgeometry.py (Ex), stlFileImport.py (Ex)