-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot2DElementsAndNodes.asv
More file actions
181 lines (162 loc) · 6.39 KB
/
Plot2DElementsAndNodes.asv
File metadata and controls
181 lines (162 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
%------------------------------------------------------------------
% Plot2DElementsAndNodes plots all elements and nodes, including the
% supports and the forces.
% It receives the following parameters:
% nodecoordinates: all node coordinates
% elemNodes: the nodes of each element
% xAxis: value of x max and min to be ploted all the figure. Ex: xAxis = [-5,5]
% yAxis: value of y max and min to be ploted all the figure. Ex: yAxis = [-5,5]
% typeProblem: string with the type of the problem to be solved. Ex:
% "problem1", "problem2", "problem3"
function Plot2DElementsAndNodes(nodecoordinates, elemNodes, elemat)%, xAxis, yAxis, typeProblem)
nel = length(elemNodes) ; % number of elements
nnode = length(nodecoordinates) ; % total number of nodes in system
%counting the number of bars, tri and quad
nbars = 0;
ntris = 0;
nquads = 0;
for i=1:nel
if strcmp( elemat{1,i}(1), 'bar')
nbars = nbars+1;
elseif strcmp( elemat{1,i}(1), 'tri')
ntris = ntris+1;
elseif strcmp( elemat{1,i}(1), 'quad')
nquads = nquads+1;
end
end
%plotting triangles
if ntris>0
X(3, ntris) = 0;
Y(3, ntris) = 0;
for iel = 1:nel
if strcmp( elemat{1,iel}(1), 'tri')
nnel = 3;
for i = 1:nnel
node(i) = elemNodes{1,iel}(i);
X(i, iel) = nodecoordinates{1,node(i)}(1);
Y(i, iel) = nodecoordinates{1,node(i)}(2);
end
end
end
plot(X,Y, 'k');
fill(X,Y,[0.6 0.6 0.6 ]);
clear X Y node
end
%plotting quads
if nquads>0
X(4, nquads) = 0;
Y(4, nquads) = 0;
for iel = 1:nel
if strcmp( elemat{1,iel}(1), 'quad')
nnel = 4;
for i = 1:nnel
node(i) = elemNodes{1,iel}(i);
X(i, iel) = nodecoordinates{1,node(i)}(1);
Y(i, iel) = nodecoordinates{1,node(i)}(2);
end
end
end
plot(X,Y, 'k');
fill(X,Y,[0.6 0.6 0.6 ]);
end
%plotting bars
if nbars>0
X(2, nbars) = 0;
Y(2, nbars) = 0;
for iel = 1:nel
if strcmp( elemat{1,iel}(1), 'bar')
nnel = 2;
for i = 1:nnel
node = elemNodes{1,iel}(i);
X(i, iel) = nodecoordinates{1,node}(1);
Y(i, iel) = nodecoordinates{1,node}(2);
end
end
end
plot(X,Y,'k', 'LineWidth',2)
clear X Y;
end
for i = 1:nnode
%circle( X(i, iel), Y(i, iel), 0.05, 'k');
%text( X(:, ntris)-0.2, Y(:, ntris), int2str(node(:)),'fontsize',12,'color','k');
%title('Finite Element Mesh') ;
%axis off ;
%k = nodes(:,1:end);
%nd = k' ;
%for i = 1:nel
% text(X(:,i),Y(:,i),int2str(nd(:,i)),'fontsize',8,'color','k');
% text(sum(X(:,i))/4,sum(Y(:,i))/4,int2str(i),'fontsize',10,'color','r') ;
%end
%}
end
%% Class (static) auxiliary functions
%------------------------------------------------------------------
% Plots a square with defined center coordinates, side length and
% color.
% This method is used to draw nodal points and rotation constraints
% on 2D models.
% Input arguments:
% x: center coordinate on the X axis
% y: center coordinate on the Y axis
% l: side length
% c: color (RGB vector)
function square(x,y,l,c)
X = [x - l/2, x + l/2, x + l/2, x - l/2];
Y = [y - l/2, y - l/2, y + l/2, y + l/2];
fill(X, Y, c);
end
%------------------------------------------------------------------
% Plots a triangle with defined top coordinates, height, base,
% orientation, and color.
% This method is used to draw translation constraints on 2D models.
% Input arguments:
% x: top coordinate on the X axis
% y: top coordinate on the Y axis
% h: triangle height
% b: triangle base
% ang: angle (in radian) between the axis of symmetry and the
% horizontal direction (counterclockwise) - 0 rad when
% triangle is pointing left
% c: color (RGB vector)
function triangle(x,y,h,b,ang,c)
cx = cos(ang);
cy = sin(ang);
X = [x, x + h * cx + b/2 * cy, x + h * cx - b/2 * cy];
Y = [y, y + h * cy - b/2 * cx, y + h * cy + b/2 * cx];
fill(X, Y, c);
end
%------------------------------------------------------------------
% Plots a circle with defined center coordinates, radius and color.
% This method is used to draw hinges on 2D models.
% Input arguments:
% x: center coordinate on the X axis
% y: center coordinate on the Y axis
% r: circle radius
% c: color (RGB vector)
function circle(x,y,r,c)
circ = 0 : pi/50 : 2*pi;
xcirc = x + r * cos(circ);
ycirc = y + r * sin(circ);
plot(xcirc, ycirc, 'color', c);
end
%------------------------------------------------------------------
% Plots an arrow with defined beggining coordinates, length,
% arrowhead height, arrowhead base, orientation, and color.
% This method is used to draw load symbols on 2D models.
% Input arguments:
% x: beggining coordinate on the X axis
% y: beggining coordinate on the Y axis
% l: arrow length
% h: arrowhead height
% b: arrowhead base
% ang: pointing direction (angle in radian with the horizontal
% direction - counterclockwise) - 0 rad when pointing left
% c: color (RGB vector)
function arrow2D(x,y,l,h,b,ang,c)
cx = cos(ang);
cy = sin(ang);
X = [x, x + l * cx];
Y = [y, y + l * cy];
line(X, Y, 'Color', c);
CrossDraw.triangle(x, y, h, b, ang, c);
end