我正在制作程序,我需要绘制一些已分成许多三角形的区域。 我计算了每个节点/三角形每个角落的应变。 现在我需要用应变绘制三角形。
现在我有三种绘制三角形的方法。 但在其中一个中,我用每个三角形的平均角度应变填充。 我想要做的是......将应变放在角落,得到一个看起来像轮廓或轮廓的图。 - 我真的不明白他们是如何工作的。
谁能帮我?
clear; clc; TC = [ 1 2 3 ; 2 3 4 ] ; % Triangles node Connection. NC = [ 0,0 ; 0,1 ; 1,0 ; 1,1 ] ; % Node Coordinates. strain = [ 300 , 400 , 500 ; 400 , 500 , 600]; % Strains in each node.; [ne,np] = size(TC); % Just finding how many elements. element = zeros([3 2 ne]); % Creating a matrix for each element. % My first and second plot... for i=1:ne no1 = TC(i,1); no2 = TC(i,2); no3 = TC(i,3); element(:,:,i) = [ NC(no1,1),NC(no1,2); NC(no2,1),NC(no2,2); NC(no3,1),NC(no3,2);]; % Defining each element for each loop. % Node 1 Node 2 Node 3 xe = [element(1,1,i),element(2,1,i),element(3,1,i)]; % Defining coordinates to plot. ye = [element(1,2,i),element(2,2,i),element(3,2,i)]; subplot(3,1,1) plot([xe, xe(1)],[ye, ye(1)]) % ATTEMPT ONE % Only plotting the triangles. Using first value also last to close the triangle. xlim([-1 2]); ylim([-1 2]) hold on subplot(3,1,2) fill(xe,ye,mean(strain(i,:))) % ATTEMPT TWO % Fill triangles with average strain. hold on xlim([-1 2]); ylim([-1 2]) end % ATTEMPT 3 subplot(3,1,3) TR = triangulation(TC,NC); triplot(TR) hold on xlim([-1 2]); ylim([-1 2])提前致谢。
I'm making program where I need to plot some area which has been split up in many triangles. I have calculated strains in each node / each corner of the triangle. Now I need to plot the triangle with the strains.
Now I have three ways of plotting the triangles. But in one of them I fill each triangle with the average of it's corners strains. What I want to do is... Put the strain on the corner and get a plot that looks like contour or contourf. - I don't really understand how they work.
Can anyone help me?
clear; clc; TC = [ 1 2 3 ; 2 3 4 ] ; % Triangles node Connection. NC = [ 0,0 ; 0,1 ; 1,0 ; 1,1 ] ; % Node Coordinates. strain = [ 300 , 400 , 500 ; 400 , 500 , 600]; % Strains in each node.; [ne,np] = size(TC); % Just finding how many elements. element = zeros([3 2 ne]); % Creating a matrix for each element. % My first and second plot... for i=1:ne no1 = TC(i,1); no2 = TC(i,2); no3 = TC(i,3); element(:,:,i) = [ NC(no1,1),NC(no1,2); NC(no2,1),NC(no2,2); NC(no3,1),NC(no3,2);]; % Defining each element for each loop. % Node 1 Node 2 Node 3 xe = [element(1,1,i),element(2,1,i),element(3,1,i)]; % Defining coordinates to plot. ye = [element(1,2,i),element(2,2,i),element(3,2,i)]; subplot(3,1,1) plot([xe, xe(1)],[ye, ye(1)]) % ATTEMPT ONE % Only plotting the triangles. Using first value also last to close the triangle. xlim([-1 2]); ylim([-1 2]) hold on subplot(3,1,2) fill(xe,ye,mean(strain(i,:))) % ATTEMPT TWO % Fill triangles with average strain. hold on xlim([-1 2]); ylim([-1 2]) end % ATTEMPT 3 subplot(3,1,3) TR = triangulation(TC,NC); triplot(TR) hold on xlim([-1 2]); ylim([-1 2])Thanks in advance.
最满意答案
您可以使用fill功能来获得所需的阴影。 通过对您的应用程序进行一些自定义,我相信下面的代码可以正常工作,尽管如果for循环使程序运行速度过慢,可能会有一些向量化。
X = zeros(3,size(TC,1)); Y = zeros(3,size(TC,1)); C = zeros(3,size(TC,1)); for i = 1:size(TC,1) % for all triangle connection definitions for j = 1:3 % for all nodes in a triangle X(j,i) = NC(TC(i,j),1)'; % format X points Y(j,i) = NC(TC(i,j),2)'; % format Y points C(:,i) = strain(i,:)'; % format color based on strain value end end fill(X,Y,C)结果:
您可能需要查看此文档以获取有关如何解释X,Y和C的更多详细信息
You can use the fill function to get the shading that you desire. With a little bit of customization for your application I believe the following code will work, although some vectorization may be in order if the for loop slows your program too much.
X = zeros(3,size(TC,1)); Y = zeros(3,size(TC,1)); C = zeros(3,size(TC,1)); for i = 1:size(TC,1) % for all triangle connection definitions for j = 1:3 % for all nodes in a triangle X(j,i) = NC(TC(i,j),1)'; % format X points Y(j,i) = NC(TC(i,j),2)'; % format Y points C(:,i) = strain(i,:)'; % format color based on strain value end end fill(X,Y,C)The result:
You may want to check this documentation for further details on how X,Y and C are interpreted
更多推荐
发布评论