issues with rotating and translating matrix for 2D simulation
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
kablai tokhi
el 9 de Mayo de 2018
Editada: kablai tokhi
el 10 de Mayo de 2018
Hi,
I'm working on a project at school and thought I'd test some of my code and came to the conclusion that a 2D simulation would be a great way to confirm its functionality. But I'm having some issues with the code for the simulation. The code for calculations are irrelevant here so I opted from posting them.
function testSim()
x = [-9 , 3, 1, 9, 1, 3, -9 ];
y = [-3,-3,-9/2, 0, 9/2, 3, 3];
g = hgtransform;
patch('XData',x,'YData',y,'FaceColor','yellow','Parent',g)
axis equal
xlim([0 400])
ylim([0 400])
pt1 = [124 80 0];
pt2 = [384 314 0];
yObject = 314;
xObject =384;
pos = [xObject yObject 2 2];
rectangle('Position',pos,'Curvature',[1 1])
r1 = 0;
r2 = 2*pi/6;
for t=linspace(0,1,100)
g.Matrix = makehgtform('zrotate',r1 + t*(r2-r1));
drawnow
pause(0.05)
end
for t2=linspace(0,1,100)
g.Matrix = makehgtform('translate',pt1 + t2*(pt2-pt1));
drawnow
pause(0.05)
end
end
This code basically creates and plots a 2D matrix that has its values in x and y. The problem I'm encountering is the one presented in the for-loops. In the code above, "g.Matrix = makehgtform(...)" is what is used for rotating and translating. By using it twice, it seems like Matlab acknowledges it as two different plots. As it first shows a plot where I can see the object rotating. After that, the plot is reset and the object is set into its default place and orientation, and the movement begins.
Any input is greatly appreciated.
3 comentarios
Jan
el 9 de Mayo de 2018
I do not understand "it seems like Matlab acknowledges it as two different plots".
Respuesta aceptada
Jan
el 9 de Mayo de 2018
The translation must be combined with the former rotation. Replace:
g.Matrix = makehgtform('translate',pt1 + t2*(pt2-pt1));
by
g.Matrix = makehgtform('translate', 0.01 * (pt2-pt1)) * g.Matrix;
3 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Performance en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!