How can I put in a triangle into a matrix?

7 ビュー (過去 30 日間)
Pratik Samant
Pratik Samant 2018 年 11 月 8 日
回答済み: Matt J 2018 年 11 月 8 日
I have the matrix
A=zeros(100,100) I want to create an equilateral triangle with top vertex at point 50 (right in the middle of the matrix) extending down a total height of 10 array entries in height.
I there a function that can do this?
Thanks

回答 (2 件)

Image Analyst
Image Analyst 2018 年 11 月 8 日
This will do it:
% Define vertices coordinates.
x = [50, 40, 60]
y = [50, 60, 60]
% Make triangle.
A = poly2mask(x, y, 100, 100) % Last two arguments are # of rows and columns.

Matt J
Matt J 2018 年 11 月 8 日
If you don't have the Image Processing Toolbox, you can do it with inpolygon
[I,J]=ndgrid(1:100);
Iv=[50,60,60];
Jv=[50,40,60];
Image=inpolygon(I,J,Iv,Jv);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by