(sec-module-graphicsdatautilities)= # Module: graphicsDataUtilities Utility functions for visualization, which provides functions for special graphics manipulation, colors, mesh manipulation, etc.; note that specific function for GraphicsData creation now moved into the graphics submodule; includes functionality like mesh manipulation and some helper functions - **Author**: Johannes Gerstmayr - **Date**: 2020-07-26 (created) Modified: 2024-05-10 (moved primitive functions to graphics) - **Notes**: Some useful colors are defined, using RGBA (Red, Green, Blue and Alpha = opacity) channels in the range [0,1], e.g., red = [1,0,0,1]. Available colors are: color4red, color4green, color4blue, color4cyan, color4magenta, color4yellow, color4orange, color4pink, color4lawngreen, color4violet, color4springgreen, color4dodgerblue, color4grey, color4darkgrey, color4lightgrey, color4lightred, color4lightgreen, color4steelblue, color4brown, color4black, color4darkgrey2, color4lightgrey2, color4white Additionally, a list of 16 colors 'color4list' is available, which is intended to be used, e.g., for creating n bodies with different colors (sec-graphicsdatautilities-switchtripletorder)= ## Function: SwitchTripletOrder [`SwitchTripletOrder(vector)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/graphicsDataUtilities.py#L96) - **function description**: helper function to switch order of three items in a list; mostly used for reverting normals in triangles - **input**: 3D vector as list or as np.array - **output**: interchanged 2nd and 3rd component of list (sec-graphicsdatautilities-computetrianglenormal)= ## Function: ComputeTriangleNormal [`ComputeTriangleNormal(p0, p1, p2)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/graphicsDataUtilities.py#L111) - **function description**: compute normalized normal for 3 triangle points - **input**: 3D vector as list or as np.array - **output**: normal as np.array (sec-graphicsdatautilities-computetrianglearea)= ## Function: ComputeTriangleArea [`ComputeTriangleArea(p0, p1, p2)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/graphicsDataUtilities.py#L129) - **function description**: compute area of triangle given by 3 points - **input**: 3D vector as list or as np.array - **output**: area as float (sec-graphicsdatautilities-compute6nodetrigsnormals)= ## Function: Compute6NodeTrigsNormals [`Compute6NodeTrigsNormals(elementNodes)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/graphicsDataUtilities.py#L141) - **function description**: Internal function: compute normals to 6-node triangular surface given by elementNodes input: elementNodes given as np.array with 6 node vectors in rows; node ordering must follow Netgen order, see the local coordinates in the function - **output**: returns np.array with 6 normals in rows (sec-graphicsdatautilities-refinemesh)= ## Function: RefineMesh [`RefineMesh(points, triangles)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/graphicsDataUtilities.py#L212) - **function description**: refine triangle mesh; every triangle is subdivided into 4 triangles - **input**: - `points`: list of np.array with 3 floats per point - `triangles`: list of np.array with 3 int per triangle (0-based indices to triangles) - **output**: returns [points2, triangles2] containing the refined mesh; if the original mesh is consistent, no points are duplicated; if the mesh is not consistent, some mesh points are duplicated! - **notes**: becomes slow for meshes with more than 5000 points Relevant Examples (Ex) and TestModels (TM) with weblink to github: [`particleClusters.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/particleClusters.py) (Ex), [`particlesSilo.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/particlesSilo.py) (Ex), [`tippeTop.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/tippeTop.py) (Ex), [`distanceSensor.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/TestModels/distanceSensor.py) (TM), [`generalContactCylinderTest.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/TestModels/generalContactCylinderTest.py) (TM), [`generalContactFrictionTests.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/TestModels/generalContactFrictionTests.py) (TM), [`generalContactImplicit1.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/TestModels/generalContactImplicit1.py) (TM), [`generalContactImplicit2.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/TestModels/generalContactImplicit2.py) (TM) (sec-graphicsdatautilities-shrinkmeshnormaltosurface)= ## Function: ShrinkMeshNormalToSurface [`ShrinkMeshNormalToSurface(points, triangles, distance)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/graphicsDataUtilities.py#L269) - **function description**: shrink mesh using triangle normals; every point is at least moved a distance 'distance' normal from boundary - **input**: - `points`: list of np.array with 3 floats per point - `triangles`: list of np.array with 3 int per triangle (0-based indices to triangles) - `distance`: float value of minimum distance - **output**: returns [points2, triangles2] containing the refined mesh; currently the points of the subdivided triangles are duplicated! - **notes**: ONLY works for consistent meshes (no duplicated points!) Relevant Examples (Ex) and TestModels (TM) with weblink to github: [`generalContactFrictionTests.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/TestModels/generalContactFrictionTests.py) (TM) (sec-graphicsdatautilities-computetriangularmesh)= ## Function: ComputeTriangularMesh [`ComputeTriangularMesh(vertices, segments)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/graphicsDataUtilities.py#L306) - **function description**: helper function to compute triangular mesh from list of vertices (=points) and segments; computes triangular meshes for non-convex case. In order to make it efficient, it first computes neighbors and then defines triangles at segments to be inside/outside. Finally neighboring relations are used to define all triangles inside/outside finally only returns triangles that are inside the segments - **input**: - `vertices`: list of pairs of coordinates of vertices in mesh [x,y] - `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, compare example with segment [V1,V2]: inside V1 V2 O----------O outside - **output**: triangulation structure of Delaunay(...), see scipy.spatial.Delaunaystructure, containing all simplices (=triangles) - **notes**: Delauney will not work if points are duplicated; you must first create point lists without duplicated points! *example*: ```python points = np.array([[0, 0], [0, 2], [2, 2], [2, 1], [1, 1], [0, 1], [1, 0]]) segments = [len(points)-1,0] for i in range(len(points)-1): segments += [i,i+1] tri = ComputeTriangularMesh(points, segments) exudyn.Print(tri.simplices) ``` (sec-graphicsdatautilities-segmentsfrompoints)= ## Function: SegmentsFromPoints [`SegmentsFromPoints(points, pointIndexOffset = 0, invert = False, closeCurve = True)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/graphicsDataUtilities.py#L398) - **function description**: convert point list into segments (indices to points); point indices start with pointIndexOffset - **input**: - `invert`: True: circle defines outter boundary; False: circle cuts out geometry inside a geometry - `pointIndexOffset`: point indices start with pointIndexOffset - **output**: return segments, containing list of lists of point indices for segments (sec-graphicsdatautilities-circlepointsandsegments)= ## Function: CirclePointsAndSegments [`CirclePointsAndSegments(center = [0,0], radius = 0.1, invert = False, pointIndexOffset = 0, nTiles = 16)`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/graphicsDataUtilities.py#L425) - **function description**: create points and segments, used in SolidExtrusion(...) for circle with given parameters - **input**: - `center`: 2D center point (list/numpy array) for circle center - `radius`: radius of circle - `invert`: True: circle defines outter boundary; False: circle cuts out geometry inside a geometry - `pointIndexOffset`: point indices start with pointIndexOffset - `nTiles`: number of tiles/segments for circle creation (higher is finer) - **output**: return [points, segments], both containing lists of lists - **notes**: geometries may not intersect! (sec-graphicsdatautilities-graphicsdatarectangle)= ## Function: GraphicsDataRectangle [`GraphicsDataRectangle(xMin, yMin, xMax, yMax, color = [0.,0.,0.,1.])`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/graphicsDataUtilities.py#L461) - **function description**: generate graphics data for 2D rectangle - **input**: minimal and maximal cartesian coordinates in (x/y) plane; color provided as list of 4 RGBA values - **output**: graphicsData dictionary, to be used in visualization of EXUDYN objects - **notes**: DEPRECATED: use graphics.Lines with the five corner points, graphics.Lines([[xMin,yMin,0],[xMax,yMin,0],[xMax,yMax,0],[xMin,yMax,0],[xMin,yMin,0]], color) Relevant Examples (Ex) and TestModels (TM) with weblink to github: [`particleClusters.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/particleClusters.py) (Ex), [`particlesTest.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/particlesTest.py) (Ex), [`particlesTest3D.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/particlesTest3D.py) (Ex), [`particlesTest3D2.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/particlesTest3D2.py) (Ex), [`rigid3Dexample.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/rigid3Dexample.py) (Ex), [`coordinateVectorConstraint.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/TestModels/coordinateVectorConstraint.py) (TM), [`coordinateVectorConstraintGenericODE2.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/TestModels/coordinateVectorConstraintGenericODE2.py) (TM), [`plotSensorTest.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/TestModels/plotSensorTest.py) (TM), ... (sec-graphicsdatautilities-graphicsdataorthocubelines)= ## Function: GraphicsDataOrthoCubeLines [`GraphicsDataOrthoCubeLines(xMin, yMin, zMin, xMax, yMax, zMax, color = [0.,0.,0.,1.])`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/exudyn/graphicsDataUtilities.py#L483) - **function description**: generate graphics data for orthogonal block drawn with lines - **input**: minimal and maximal cartesian coordinates for orthogonal cube; color provided as list of 4 RGBA values - **output**: graphicsData dictionary, to be used in visualization of EXUDYN objects - **notes**: DEPRECATED: use graphics.Brick(centerPoint, size, addFaces=False, addEdges=True, edgeColor=color)