How can I create a plot of a 3D mesh given node coordinates and element connectivity from an input file?

29 views (last 30 days)
Hi, I have an input file from another software that gives 1) nodal coordinates, 2) element connectivity, and 3) dx, dy, and dz for each node (after a loading analysis is run with another software). I've read this information into my MATLAB file and wish to create a 3D plot that has lines connecting the new node locations of each element. I've gotten it to display the points, but can't get lines that show each element. Note, I haven't read in the element connectivity yet. Wasn't sure how to go about this. Any suggestions?
Matlab file:
%Load the input file data
clear;
mode=textread('mode.txt');
%Load the original x,y,z coordinates
nnodes=mode(1,1);
nelements=mode(1,2);
for i=1:nnodes;
x(i)=mode(i+1,2);
y(i)=mode(i+1,3);
z(i)=mode(i+1,4);
end
%Load the movements
for i=1:nnodes;
dx(i)=mode(i+1+nnodes+nelements,2);
dy(i)=mode(i+1+nnodes+nelements,3);
dz(i)=mode(i+1+nnodes+nelements,4);
end
%need to plot here
Example input file (downsized):
27 8
1 0.0 0.0 0.0
2 1.0 0.0 0.0
3 2.0 0.0 0.0
4 0.0 -1.0 0.0
5 1.0 -1.0 0.0
6 2.0 -1.0 0.0
7 0.0 -2.0 0.0
8 1.0 -2.0 0.0
9 2.0 -2.0 0.0
10 0.0 0.0 1.0
11 1.0 0.0 1.0
12 2.0 0.0 1.0
13 0.0 -1.0 1.0
14 1.0 -1.0 1.0
15 2.0 -1.0 1.0
16 0.0 -2.0 1.0
17 1.0 -2.0 1.0
18 2.0 -2.0 1.0
19 0.0 0.0 2.0
20 1.0 0.0 2.0
21 2.0 0.0 2.0
22 0.0 -1.0 2.0
23 1.0 -1.0 2.0
24 2.0 -1.0 2.0
25 0.0 -2.0 2.0
26 1.0 -2.0 2.0
27 2.0 -2.0 2.0
1 1 2 5 4 10 11 14 13
2 2 3 6 5 11 12 15 14
3 4 5 8 7 13 14 17 16
4 5 6 9 8 14 15 18 17
5 10 11 14 13 19 20 23 22
6 11 12 15 14 20 21 24 23
7 13 14 17 16 22 23 26 25
8 14 15 18 17 23 24 27 26
1 0.830152E+00 0.628702E+00 -0.201450E+00
2 0.830152E+00 -0.524228E-15 -0.137507E-14
3 0.830152E+00 -0.628702E+00 0.201450E+00
4 0.190131E-14 0.628702E+00 -0.431462E-14
5 0.258145E-14 -0.135851E-14 -0.238954E-14
6 0.155987E-14 -0.628702E+00 0.128234E-15
7 -0.830152E+00 0.628702E+00 0.201450E+00
8 -0.830152E+00 0.161677E-14 -0.392258E-15
9 -0.830152E+00 -0.628702E+00 -0.201450E+00
10 -0.144434E-14 -0.348655E-14 -0.201450E+00
11 0.597316E-15 -0.149615E-14 -0.576758E-15
12 0.644873E-15 -0.120253E-14 0.201450E+00
13 -0.531611E-15 0.242440E-15 -0.842095E-15
14 0.149549E-15 0.568441E-16 -0.574665E-15
15 0.442493E-15 -0.305375E-15 0.121846E-14
16 -0.297409E-14 0.388064E-14 0.201450E+00
17 -0.907046E-15 0.154782E-14 -0.328073E-14
18 -0.176488E-14 -0.571024E-15 -0.201450E+00
19 -0.830152E+00 -0.628702E+00 -0.201450E+00
20 -0.830152E+00 0.829819E-16 0.184305E-14
21 -0.830152E+00 0.628702E+00 0.201450E+00
22 0.151713E-14 -0.628702E+00 0.380174E-14
23 -0.124307E-14 -0.259287E-15 0.993696E-15
24 -0.558489E-14 0.628702E+00 0.263517E-14
25 0.830152E+00 -0.628702E+00 0.201450E+00
26 0.830152E+00 -0.274566E-14 -0.206110E-14
27 0.830152E+00 0.628702E+00 -0.201450E+00

Answers (1)

Matt Kindig
Matt Kindig on 19 Apr 2013
Hi Kirsten,
First of all, can you clarify exactly what you are trying to plot? For the element connectivity you can define it using patches. A few questions that arise:
-how is a single element defined? I am assuming that the element connectivity is defined in the 8x9 matrix portion of the input whose first row is:
" 1 1 2 5 4 10 11 14 13"
Does that mean that the element consists of 9 nodes? Or is the first column the element ID? Also, how is this element defined--is it a polygon of 8 nodes, or a hexahedral element (8 nodes)? If so, what is the node numbering order?
What do you need to do with the dx/dy/dz for each node? Do you need to somehow plot this?
Also, it appears that your approach of reading in the input file is rather inefficient, since you are looping over each element, when Matlab can more efficiently read the file in chunks, using textscan() or similar. Also, I assume that the actual input file is "sectioned", with specific text indicators separating the various constituents (node coordinates, element definition, deviations). Can you post the actual input file for us?
Thanks, Matt

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!