How do I animate polyshape objects with translate?

6 views (last 30 days)
I am trying to animate a scene with multiple shapes using "translate." However, whenever the new position of the polyshape overlaps the previous position only the boundary moves as shown. The "fill" part of the pshape stays at the original postion as shown:
The shape still translates ok after that, but the "fill" remains at the original position, though it does change color every time the shape translates, like so:
My code is also checking for collision, which works just fine even though the "fill" has never moved. Here is an example of that from a different run:
I thought it might be confusing the pshape object because the initial translates overlap (like adding more vertices), but that doesn't make sense since the pshape is just translating. I think attaching the pshapes to hgtransforms would work, but I don't want to add the extra code if I can avoid it. Any suggestions?
Here is my code:
ax = axes('XLim',[0 65],'XTick',[],'YLim',[0 65],'YTick',[]);
hp1temp = polyshape([12 12 20 20],[12 22 22 12]);
hp2temp = polyshape([35 35 50 50],[35 45 45 35]);
nFrames = 50;
d1 = 2*[rand() rand()];
d2 = -1*[rand() rand()];
% Move shapes around randomly, [while staying in bounds] (TBA)
for i = 1:0.1:nFrames
hp1 = hp1temp;
hp2 = hp2temp;
check = separating_axis_theorem(hp1.Vertices,hp2.Vertices);
pt1 = plot(hp1);
pt2 = plot(hp2);
text(5,40,'Collision Detected','FontSize',20,'FontWeight','bold','Color','red');
hp1temp = translate(hp1,d1);
hp2temp = translate(hp2,d2);

Answers (0)


Find more on Elementary Polygons 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!