To divide a triangle into n^2 smaller triangles, we can uniformly divide the base and height of the triangle into n equal parts, and then draw lines connecting the corresponding points on the base and height to create the smaller triangles.
Here's the code in Matlab:
main.m1076 chars43 lines
This code defines the vertices of the original triangle and the number of divisions. It then calculates the coordinates of the lines connecting the divisions, and uses a nested loop to create two smaller triangles for each square. The vertices of these triangles are added to the triangles
matrix. Finally, the original triangle and the smaller triangles are plotted using patch
functions. The axis equal
command ensures that the plot is scaled equally in both directions.
gistlibby LogSnag