Creating a rectangle with 4 points
112 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
Adam Danz
2020-5-2
编辑:Adam Danz
2020-5-4
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
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;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!