map of outline robot
1 回表示 (過去 30 日間)
古いコメントを表示
採用された回答
Fifteen12
2022 年 12 月 8 日
For animation techniques to make the robot move, you might want to check this out: https://www.mathworks.com/help/matlab/creating_plots/animation-techniques-1.html
For mapping your robot onto some space, what you have is the centroid of the object and it's orientation. Imagine the robot is a box, you have the (x,y) point of it's centroid, as well as which direction the robot is facing. As for the obstacle, I assume you know the orientation of the IR sensor?
The rotation matrix you pasted in the question is good for getting the coordinates of the box around the centroid. To graph an arbitary patch you can do the following:
figure(1)
axis([-10, 10, -10, 10])
h = drawBox(0, 0, 0);
pause(1)
delete(h)
h = drawBox(3, 3, pi/4);
function [handle] = drawBox(x, y, theta)
width = 5;
height = 8;
% Get coordinates of box corners if it was at the origin
x0_coord = [-width / 2, width / 2, width / 2, -width / 2];
y0_coord = [-height / 2, -height / 2, height / 2, height / 2];
% Rotate by theta
rotation = [cos(theta), -sin(theta); sin(theta), cos(theta)];
% Translate to new x,y location
for i = 1:4
to_shift(:,i) = rotation * [x0_coord(i); y0_coord(i)];
end
shifted_coord = [x; y] + to_shift;
% Plot
handle = patch(...
'Vertices', [shifted_coord(1,:); shifted_coord(2,:)]', 'Faces', [1 2 3 4],...
'FaceColor','k','EdgeColor','k','LineWidth',2);
end
2 件のコメント
Fifteen12
2022 年 12 月 9 日
Hi Muhammad, the code I provided is just a starting place, it will definitely need to be modified. Hopefully you can see where a set of x and y coordinates are mapped to a new, transformed set of coordinates. Following this process you could take that initial set and include any new point that you would like.
As for the obstacle mapping, I don't know exactly what information you're dealing with. Do you have a vector of coordiantes for the obstacle? If that's the case, then you can just do this:
xcoord = 10 * rand(100, 1) - 5;
ycoord = 10 * rand(100, 1) - 5;
plot(xcoord, ycoord, '.r', 'MarkerSize', 10)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Lighting, Transparency, and Shading についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!