Creating a rectangle with 4 points

조회 수: 21 (최근 30일)
Umut Ege Ulucay
Umut Ege Ulucay 2020년 5월 1일
편집: Adam Danz 2020년 5월 4일
Hello, I have 4 points with (x,y,z) and I want to have a closed shape which connects them.
I actually want to draw 4 lines between the 4 points and make them a rectangle.
Thank you for help.

채택된 답변

Adam Danz
Adam Danz 2020년 5월 1일
편집: Adam Danz 2020년 5월 4일
plot3([2 4 4 2 2],[1 1 5 5 1], [3 3 3 3 3], '-k') % for (x,y,z)
% plot([2 4 4 2 2],[1 1 5 5 1], '-k') % for (x,y)
grid on
axis equal
  댓글 수: 2
Umut Ege Ulucay
Umut Ege Ulucay 2020년 5월 2일
편집: Umut Ege Ulucay 2020년 5월 2일
This one works pretty well, thank you.
I want to ask one more question. What if I have couple of rectangles and I want to fill the inside of them according to some values and a colorbar to show the values. Thanks for your help so far.
edit: As I see, I can use fill3 function, am i right?
Adam Danz
Adam Danz 2020년 5월 2일
편집: Adam Danz 2020년 5월 4일
You can check out fill3(). There are examples toward the bottom of that page.
This page also shows you how to do it with patch().
To link the colors of the rectangles to a colobar, you can define a color map which will be a nx3 matrix of RGB values. Assign the colormap to your axes, and then use the rows of the colormap to assign color to each patch. If you get stuck, let me know where I can help.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 5월 1일
Did you try rectangle()?
rectangle('Position', [x1, y1, x2-x1, y2-y1], 'FaceColor', 'r', 'EdgeColor', 'k');
or using line():
line([x1,x2], [y1, y1], 'Color', 'r', 'LineWidth', 2);
hold on;
line([x1,x2], [y2, y2], 'Color', 'r', 'LineWidth', 2);
line([x1,x1], [y1, y2], 'Color', 'r', 'LineWidth', 2);
line([x2,x2], [y1, y2], 'Color', 'r', 'LineWidth', 2);
hold off;
  댓글 수: 1
Umut Ege Ulucay
Umut Ege Ulucay 2020년 5월 2일
Yes that works but I asked 3d with point z. Thank you anyways

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by