MATLAB: How to create a triangular geometry in matlab using loop

loop use

How can I create a triangular shape geometry in matlab using 'for loop'? Can I create grid point in this?

Best Answer

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
.