how to create a triangular geometry in matlab using loop?

5 ビュー (過去 30 日間)
Sabyasachi  Sahu
Sabyasachi Sahu 2016 年 4 月 28 日
コメント済み: Sabyasachi Sahu 2016 年 4 月 28 日
How can I create a triangular shape geometry in matlab using 'for loop'? Can I create grid point in this?
  1 件のコメント
Sabyasachi  Sahu
Sabyasachi Sahu 2016 年 4 月 28 日
I have created a code for square mesh using for loop clc;clear all; L=1;H=3; m=40;n=40; dx=L/m;dy=H/n; for i=1:m+1 for j=1:n+1 x(i,j)=(i-1)*dx; y(i,j)=(j-1)*dy; end end R=x-x; mesh(x,y,R) view(0,90)
and I want to create a triangular geometry inside which I want square mesh but not using coordinate points.

サインインしてコメントする。

採用された回答

KSSV
KSSV 2016 年 4 月 28 日
clc; clear all ;
% Vertices of triangle
A = [2 1] ;
B = [-6 4] ;
C = [-3 -2] ;
% Discretization along sides
N = 20 ;
% sides
s1 = [linspace(A(1),B(1),N)',linspace(A(2),B(2),N)'];
s2 = [linspace(B(1),C(1),N)',linspace(B(2),C(2),N)'];
s3 = [linspace(C(1),A(1),N)',linspace(C(2),A(2),N)'];
% coors
X = [s1(:,1) ; s2(:,1) ; s3(:,1)] ;
Y = [s1(:,2) ; s2(:,2) ; s3(:,2)] ;
[p,t] = mesh2d([X Y]) ;
The grid will look as the figure attached
.
  2 件のコメント
Sabyasachi  Sahu
Sabyasachi Sahu 2016 年 4 月 28 日
can u do this using for loop?
Sabyasachi  Sahu
Sabyasachi Sahu 2016 年 4 月 28 日
clc;clear all; L=1;H=3; m=40;n=40; dx=L/m;dy=H/n; for i=1:m+1 for j=1:n+1 x(i,j)=(i-1)*dx; y(i,j)=(j-1)*dy; end end R=x-x; mesh(x,y,R) view(0,90)
This is my code for square mesh but I want a triangular domain inside which it should have square mesh using this for loop any idea

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 28 日
編集済み: Azzi Abdelmalek 2016 年 4 月 28 日
You don't need a loop to create a triangle, just set the coordinate of your triangle. For example
t=[0 10 5 0]
y=[0 0 5 0]
plot(t,y)
or
fill(t,y,'g')

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by