Check if two hgtransform objects are colliding or overlapping (or find the minimum distance between them)
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Prabhan Purwar
on 20 Oct 2020
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 Comments
See Also
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!