Get coordinates of hgtransform after transformation

5 views (last 30 days)
Hello.
I am transforming a list of points on a 2D Plane for drawing in a figure. It would be helpfull for other parts of the simulation, to know the position of each point after the transformation. What is the most practical way to get these new coordinates?
conePos = [5 5; 10 10; 3 4];
cones = hgtransform;
[idx ~] = size(conePos);
for i = 1:idx % Draw a small box around each point
patch('XData',[-1, 1, 1, -1] * 0.2 + conePos(i,1), ...
'YData',[-1, -1, 1, 1] * 0.2 + conePos(i,2), ...
'FaceColor','yellow','Parent',cones)
end
set(cones, 'Matrix', makehgtform('zrotate',[1 2 3], ...
'scale',1, ...
'translate',-0.5...
));
So i need to get the position of each Element in conePos after the transformation.
Thanks for your help.
EDIT: I have found a solution by myself. See the code below:
pts = [1 0; 1 1];
theta = pi/4;
offset = [0 0 0];
transformCoords(pts, theta, offset)
function [ out ] = transformCoords( pts, theta, offset )
out = zeros(size(pts));
for i=1:size(pts, 1)
ptsH = [pts(i,1); pts(i,2); 0; 1;];
R = makehgtform('zrotate',-theta, ...
'scale',1, ...
'translate',-offset ...
);
p2 = R*ptsH;
pOut = [p2(1,:) ./ p2(4,:); ...
p2(2,:) ./ p2(4,:); ...
p2(3,:) ./ p2(4,:); ...
];
out(i,1) = pOut(1);
out(i,2) = pOut(2);
end
end

Answers (0)

Categories

Find more on Object Containers in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!