Check if two hgtransform objects are colliding or overlapping (or find the minimum distance between them)
1 次查看(过去 30 天)
显示 更早的评论
Hello!
I am plotting 2 moving objects to visualize a car accident. I am using patch to visualize the shape of the cars and makehgtform in a loop to move them according to their x- and y-coordinates.
Now I need to find a way to check if they are colliding. Is there any way to do that for hgtransform objects? Or maybe there is an easy way to convert them into polyshapes so I can use the function overlaps? But I didn't manage to create a polygon out of the hgtransform object yet...
Thank you for your help! If you need parts of my code or more information to understand what the problem is, just tell me :)
0 个评论
回答(1 个)
Prabhan Purwar
2020-10-20
Hello
hgtransform is primarily used for Graphic Object transformations and doesn't support overlaps functionality.
If your objects are represented in 2D consider making use of polyshape as shown in the following code
pts = [4 4 -1 -1 2 2 1 1 0 0 3 3; ...
1 3 3 -1 -1 1 1 0 0 2 2 1; ...
0 0 0 0 0 0 0 0 0 0 0 0; ...
1 1 1 1 1 1 1 1 1 1 1 1];
h1 = patch('FaceColor',[0.3010 0.7450 0.9330]);
h1.XData = pts(1,:) ./ pts(4,:);
h1.YData = pts(2,:) ./ pts(4,:);
h1.ZData = pts(3,:) ./ pts(4,:);
mrot = makehgtform('zrotate',pi/5);
h2 = patch('FaceColor',[0.9290 0.6940 0.1250]);
h2.XData = p2(1,:) ./ p2(4,:);
h2.YData = p2(2,:) ./ p2(4,:);
h2.ZData = p2(3,:) ./ p2(4,:);
p2 = mrot*pts;
poly1 = polyshape(pts(1,:),pts(2,:));
poly2 = polyshape(p2(1,:),p2(2,:));
figure
polyvec = [poly1 poly2];
plot(polyvec)
TF = overlaps(polyvec)
I would suggest making use of Driving Scenario Designer in Automated Driving Toolbox, designed for designing, simulating, and testing ADAS and autonomous driving systems.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Object Containers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!