📄 frame_vector_plot.m
字号:
function frame_vector_plot( v, attach_pts, W, H, R, arrow_end, color_spec)
if nargin<7
color_spec = 'k'; % plot arrow in black by default
end
if nargin<6
arrow_end = 1;
end
face = attach_pts(:,1);
s = attach_pts(:,2);
% Assemble 2D coordinates for building exterior:
frame_x = [0 0 W/2 W W];
frame_z = [0 H H+R H 0];
% Assemble 2D coordinates for vector origins:
x_0 = zeros(size(s)); % initialize vector origins as zero
z_0 = zeros(size(s));
v_x = zeros(size(s));
v_z = zeros(size(s));
ind_1 = find(face==1); % indices of left wall
ind_2 = find(face==2); % indices of left roof slope
ind_3 = find(face==3); % indices of right roof slope
ind_4 = find(face==4); % indices of right wall
% Terms for transformation from s-coordinates to x- and z-coordinates:
hyp = sqrt((W/2)^2+R^2); % hypotenuse of triangle formed by W/2 and R
s2x_0 = [0 0 W W]; % constant term for s -> x
s2x_1 = [0 W/(2*hyp) -W/(2*hyp) 0]; % linear term for s -> x
s2z_0 = [0 H H 0]; % constant term for s -> z
s2z_1 = [1 R/hyp R/hyp 1]; % linear term for s -> z
% Terms for transformation of 'vector' to x- and z-coordinates:
hyp = sqrt((W/2)^2+R^2); % hypotenuse of triangle formed by W/2 and R
v2x = [1 R/hyp -R/hyp -1]; % scale factor for v -> v_x
v2z = [0 -W/(2*hyp) -W/(2*hyp) 0]; % scale factor for v -> v_z
for j = 1:4
% find indices on current face:
ind_j = find(face==j);
% transform attachment points to x- and z-coordinates:
x_0(ind_j) = s2x_0(j) + s(ind_j)*s2x_1(j);
z_0(ind_j) = s2z_0(j) + s(ind_j)*s2z_1(j);
% compute vector components in x- and z-coordinates:
v_x(ind_j) = v(ind_j)*v2x(j);
v_z(ind_j) = v(ind_j)*v2z(j);
end
sf = 0.6*H/max(abs(v));
% Plot frame:
plot(frame_x, frame_z, 'k-');
hold on;
% Plot solid circles at attachment points:
plot(x_0, z_0, 'k.');
% Plot vectors:
for j=1:length(v)
if arrow_end == 1
h = plot_arrow(x_0(j), z_0(j), x_0(j)+sf*v_x(j), z_0(j)+sf*v_z(j));
set(h(1),'Color',color_spec);
set(h(2),'EdgeColor',color_spec,'FaceColor',color_spec);
else
h = plot_arrow(x_0(j)-sf*v_x(j), z_0(j)-sf*v_z(j), x_0(j), z_0(j) );
set(h(1),'Color',color_spec);
set(h(2),'EdgeColor',color_spec,'FaceColor',color_spec);
end
end
set(gca,'XLim',[-H W+H],'YLim',[-H 2*H+R],'DataAspectRatio',[1 1 1]);
%axis equal;
hold off;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -