transform a patch using a transform object
显示 更早的评论
Hi,
I created a square face at the origin using the "patch" function. Then I defined the square as a child of a transform object. I started to move the transform object to several locations and changed its orientation. The square object followed well the transform object. The problem is that when I asked to get the current vertices of the square (after it was moved), I got the original vertices around the origin. I need the current vertices in order to calculate the current normal-vector of that square-face.
Thanks
回答(1 个)
Walter Roberson
2016-4-23
Let p be the patch handle. Let hgtrans be the hgtransform object. Then,
M = get(hgtrans, 'Matrix');
xd = get(p, 'XData');
xd = xd(:);
yd = get(p, 'YData');
try
zd = get(p, 'ZData');
if isempty(zd); zd = zeros(size(xd)); end
catch
zd = zeros(size(xd));
end
XYZ1 = [xd, yd(:), zd(:), ones(size(xd))];
XYZ1_trans = XYZ1 * M';
x_trans = XYZ1_trans(:,1);
y_trans = XYZ1_trans(:,2);
z_trans = XYZ1_trans(:,3);
p does not need to be a patch, but it does need to have XData and YData; if it does not have ZData then the code will compensate. For example, image objects do not have ZData but can validly be translated to a non-zero Z coordinate. Some convenient graphics objects such as rectangle() objects do not have XData or YData; the code here does not account for those.
3 个评论
Ehud
2016-4-24
Walter Roberson
2016-4-24
No, there is no direct way. You need to multiply out all of the transform matrices.
For clarity: when you get the XData, YData, ZData of a graphics object, those are always the values that you passed to the graphics routines, not the transformed values.
Ehud
2016-4-28
类别
在 帮助中心 和 File Exchange 中查找有关 Image Arithmetic 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!