-
Notifications
You must be signed in to change notification settings - Fork 0
/
drone_Animation_Sphere.m
38 lines (28 loc) · 1.48 KB
/
drone_Animation_Sphere.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
%% Display animation function. Drone represented by Sphere
function drone_Animation_Sphere(x, y, z, roll, pitch, yaw, combinedobject)
% This Animation code represents the drone as a small black sphere.
%% Define constants
D2R = pi/180; % Degrees to radians
%% Create the black sphere representing the drone
[sx, sy, sz] = sphere(20); % Create a unit sphere with 20 grid points
% Scale the sphere to make it small
sphere_radius = 0.5; % Set a small radius for the drone sphere
% Create the sphere and set its color to black
droneSphere = surf(sphere_radius * sx, sphere_radius * sy, sphere_radius * sz, ...
'FaceColor', 'black', 'EdgeColor', 'none', 'Parent', combinedobject); % Black sphere representing the drone
hold on;
%% Animation - update transformations for the sphere
for i = 1:length(x)
% Translation to update position
translation = makehgtform('translate', [x(i), y(i), z(i)]);
% Apply orientation changes with yaw, pitch, and roll
rotation1 = makehgtform('xrotate', roll(i) * D2R);
rotation2 = makehgtform('yrotate', pitch(i) * D2R);
rotation3 = makehgtform('zrotate', yaw(i) * D2R);
% Apply transformations (position + orientation)
set(combinedobject, 'matrix', translation * rotation3 * rotation2 * rotation1);
% Render the scene
drawnow;
pause(0.02); % Pause to simulate real-time updates
end
end