フィルターのクリア

Draw diagonals of rectangle

7 ビュー (過去 30 日間)
Thales
Thales 2019 年 11 月 14 日
編集済み: Adam Danz 2019 年 11 月 14 日
The code below
figure; hold on;
rectangle('Position',[1 2 5 6])
axis([0 10 0 10])
plot([1 6],[8 2],'k')
plot([1 6],[2 8],'k')
Draws a rectangle and I manually plotted 2 lines to conect the vertices of the rectangle, to draw the two diagonals of the rectangle.
Is there an easier or faster way to draw the diagonals of a rectangle, after you created it with the rectangle function?
fig1.png

採用された回答

Adam Danz
Adam Danz 2019 年 11 月 14 日
編集済み: Adam Danz 2019 年 11 月 14 日
If you're looking for a function, check out interconnections()
rectPos = [1 2 5 6]; %[left, bottom, width, height];
interconnections(repmat(cumsum(rectPos([1,3])),2,1), repmat(cumsum(rectPos([2,4])),2,1)', true);
% This will also draw the rectangle
Alternatively,
rectPos = [1 2 5 6]; %[left, bottom, width, height];
rectangle('Position',rectPos);
hold on
plot(cumsum(rectPos([1,3])), [cumsum(rectPos([2,4]));fliplr(cumsum(rectPos([2,4])))], '-k')

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by