-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot2DMesh2.m
More file actions
138 lines (127 loc) · 5.3 KB
/
Plot2DMesh2.m
File metadata and controls
138 lines (127 loc) · 5.3 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
%------------------------------------------------------------------
% Plot2DMesh2 plots all elements and nodes for the Problem2, including the
% supports and the forces.
% It receives the following parameters:
% nodecoordinates: all node coordinates
% elemNodes: the nodes of each element
% P is the total force
% scale of the axis
function Plot2DMesh2(nodecoordinates, elemNodes, elemat, nodetag, forcevalues,P, Lx, Ly)
nel = length(elemNodes) ; % number of elements
nnode = length(nodecoordinates) ; % total number of nodes in system
scale = min(Lx, Ly);
if abs(scale) < 0.5
axis([ -0.15 Lx+0.15 -0.15 Ly+0.15 ]);
sizeTriangle = 0.01;
fontSize = 6;
arrowSize = 0.02;
arrowSizeBase1 = 0.005;
arrowSizeBase2 = 0.015;
textOffset = 0.01;
textOffset2 = 0.05;
else
sizeTriangle = 0.1;
fontSize = 6;
arrowSize = 0.1;
arrowSizeBase1 = 0.03;
arrowSizeBase2 = 0.07;
textOffset = 0.05;
textOffset2 = 0.2;
end
%plotting texts, circles, supports and forces
for i = 1:nnode
x = nodecoordinates{1,i}(1);
y = nodecoordinates{1,i}(2);
%circle( x,y, 0.1, 'k');
text( x+textOffset,y, int2str(i),'fontsize',fontSize,'color','k');
if nodetag(i,1) == 1
triangle(x,y,sizeTriangle,sizeTriangle,pi,[ 0 0 1]);
end
if nodetag(i,2) == 1
triangle(x,y,sizeTriangle,sizeTriangle,-pi/2,[ 0 0 1]);
end
if forcevalues(i,1) ~= 0
arrow2D(x,y,arrowSize,arrowSizeBase1,arrowSizeBase1,pi,[1 0 0]);
%text( x-1.8,y, num2str(forcevalues(i,1)),'fontsize',12,'color','r');
end
if forcevalues(i,2) ~= 0
arrow2D(x,y,arrowSize,arrowSizeBase2,arrowSizeBase2,pi/2,[1 0 0]);
Lx = x;
%text( x,y+0.7, num2str(forcevalues(i,2)),'fontsize',12,'color','r');
end
end
Ly = y;
text( Lx+textOffset2,Ly/2, num2str(P),'fontsize',fontSize+2,'color','r');
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);
fill(xcirc, ycirc, [0.9 0.9 0.9]);
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,'LineWidth',2 );
triangle(x, y, h, b, ang, c);
end