Message Boards Message Boards

0
|
2456 Views
|
10 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Export P1 function on a mesh to Mathematica

Posted 2 years ago

Hi,

I'm writing a library (in Rust) to handle triangular meshes and P1 functions on them and would like to offer an export to Mathematica, in particular to visualize the functions. There used to be TriangularSurfacePlot for that but that functionality is now built in and I could not find

  • what Mathematica datastructures I should use to export the mesh (coordinates of the points, list of triangles or adjacency matrix) and the P1 function (values at each point of the mesh);

  • what function(s) I should call to produce a nice graphic (similar to Matlab trisurf, shown below).

Thanks!

graph

POSTED BY: Christophe T
10 Replies
Posted 2 years ago

Aha! Thanks a lot for your help!

enter image description here

POSTED BY: Christophe T

You can use VertexColors inside GraphicsComplex to give colors to vertices:

pts = RandomReal[{0, 1}, {5, 3}];
Graphics3D[
 GraphicsComplex[pts, Polygon[{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}], 
  VertexColors -> 
   Map[Function[pt, ColorData["Rainbow"][pt[[3]]]], pts]]]

You may have to simulate ColorFunctionScaling.

POSTED BY: Gianluca Gorni
Posted 2 years ago

Yes thanks. The picture is only a small test, the library is still under development. I attached a modification of it. With ListPlot3D[xyz,ColorFunction->"Rainbow",Mesh->All] I indeed produced the picture below. However, since the triangles are not used, Mathematica reconstructs a mesh from the points. I would prefer if possible that it uses mine. Any way to tell it to do so?

enter image description here

Attachments:
POSTED BY: Christophe T

All your points appear to lie in a plane. So - it does not look like the first picture you showed.

Any way to have a color gradient according to the height?

Does this do what you have in mind?

ListPlot3D[xyz,ColorFunction->"Rainbow",Mesh->All]

enter image description here

POSTED BY: Henrik Schachner
Posted 2 years ago

Sure, here it is (as said earlier, it is generated code). The complete file is attached.

xyz = {{1.16*^2,3.72*^2,2.56*^2}, {1.27*^2,2.02*^2,7.5*^1}, {4.29*^2,2.38*^2,-1.91*^2}, {2.54*^2,1.99*^2,-5.5*^1}, ...};
triangles = {{235,116,4}, {4,232,235}, {116,43,4}, {232,236,235}, ...};
Graphics3D[GraphicsComplex[xyz, Polygon[triangles]]]
Attachments:
POSTED BY: Christophe T

You can use Graphics3D and Polygon:

Graphics3D[Table[Polygon[RandomReal[{0, 1}, {3, 3}]], {10}]]

If your triangles share vertices, it may be more computationally efficient to use GraphicsComplex rather than listing each Polygon by itself.

POSTED BY: Gianluca Gorni
Posted 2 years ago

Thanks for your help. I also used GraphicsComplex to store the coordinate triplets and Polygon structure “separately”. I now get the test image below. Any way to have a color gradient according to the height? enter image description here

POSTED BY: Christophe T

Welcome to Wolfram Community!
Please provide your code to make it easier for other members to help. Please read the forum rules for more information on how to include code to your post: http://wolfr.am/READ-1ST

POSTED BY: Moderation Team

You get something similar with the Mesh and MeshStyle options:

ListPlot3D[Table[1/(x^2 + y^2 + 1), {x, -2, 2, 1/2}, {y, -2, 2, 1/2}],
  Mesh -> All, MeshStyle -> Thick]
POSTED BY: Gianluca Gorni
Posted 2 years ago

Thanks but Table defines a rectangular mesh while, in my case, my data is defined on a triangular one. The picture was just an example. Attached is an example of what I really want.

Attachments:
POSTED BY: Christophe T
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract