MATLAB在矩阵内部画正三角形 。

3 views (last 30 days)
ngesayrc
ngesayrc on 25 May 2023
Answered: aftmukf on 25 May 2023
参考https://www.ilovematlab.cn/thread-76283-1-1.html这篇回复里大神的例子,通过给矩阵赋值的方法画出三角形。但是请问如何画出正三角形?
n=200;          %% N为网格大小
b=120;          %% b为正三角形边长
A=2*ones(n);
for x=1:n
    for y=1:n
        if (y>=50 && y<= 104/60*(x-(n-b)/2)+50  && y<=-104/60*(x-(200-(n-b)/2))+50)                 
            A(x,y)=1;          %% 三角形内的值为1
        end
    end
end
imshow(A,[])
[ 本帖最后由 小兰花 于 2010-4-29 19:15 编辑 ]

Accepted Answer

aftmukf
aftmukf on 25 May 2023
正三角形就是等边三角形啊。或者你是要逆时针旋转90°吗?
用rot90命令就行啦
n=200;          %% N为网格大小
b=120;          %% b为正三角形边长
A=2*ones(n);
for x=1:n
    for y=1:n
        if (y>=50 && y<= 104/60*(x-(n-b)/2)+50  && y<=-104/60*(x-(200-(n-b)/2))+50)                 
            A(x,y)=1;          %% 三角形内的值为1
        end
    end
end
imshow(rot90(A),[])

More Answers (0)

Categories

Find more on 二维图和三维图 in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!