transform a patch using a transform object
조회 수: 7 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (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
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!