
Patch function gives crosses when multiple squares attempted
10 次查看(过去 30 天)
显示 更早的评论
Trying to place four squares with patch gradients, code works when only doing one but when trying with multiple it produces X with left and right triangles. Coord order same as when works for single
shapesx=[0 5 5 0;0 5 5 0;5 10.5 10.5 5;5 10.5 10.5 5];
shapesy=[0 0 5 5;5 5 10.5 10.5;0 0 5 5;5 5 10.5 10.5];
shapesc=[0 2.5 5 2.5;2.5 5 7.5 5;2.5 5 7.5 5; 5 7.5 10 7.5];
patch(shapesx,shapesy,shapesc)
0 个评论
回答(1 个)
Mike Garrity
2015-11-30
Yeah, this can be a bit confusing.
one polygon ("face") per column is added
So in this case:
shapesx=[0 5 5 0];
shapesy=[0 0 5 5];
shapesc=[0 2.5 5 2.5];
patch(shapesx,shapesy,shapesc)
We have 4 columns which each have 1 row. So in theory, we should get 4 1-sided polygons. But this is a special case. These 1x4 arrays are called "row vectors". If you give patch (and many other graphics commands) a row vector when it expects a "column vector", then it will transpose for you. So it's just as if you had done this:
patch(shapesx',shapesy',shapesc')
But in your 4x4 case, this special case doesn't apply. So in that case you do need to worry about the fact that each column is going to become a polygon, rather than each row.
So I think what you really want is this:
shapesx=[0 5 5 0;0 5 5 0;5 10.5 10.5 5;5 10.5 10.5 5];
shapesy=[0 0 5 5;5 5 10.5 10.5;0 0 5 5;5 5 10.5 10.5];
shapesc=[0 2.5 5 2.5;2.5 5 7.5 5;2.5 5 7.5 5; 5 7.5 10 7.5];
patch(shapesx',shapesy',shapesc')
or this:
shapesx=[0 0 5 5 ; ...
5 5 10.5 10.5; ...
5 5 10.5 10.5; ...
0 0 5 5 ];
shapesy=[0 5 0 5 ; ...
0 5 0 5 ; ...
5 10.5 5 10.5; ...
5 10.5 5 10.5];
shapesc=[0 2.5 2.5 5 ; ...
2.5 5 5 7.5; ...
5 7.5 7.5 10 ; ...
2.5 5 5 7.5];
patch(shapesx,shapesy,shapesc)

0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!