a b/plot_rectangle_with_rotation.m
1
function [Xrot, Yrot] = plot_rectangle_with_rotation(rect_position, rect_rotation, axes_to_plot, color, BOX_ID)
2
    
3
    % rect_posittion is the Position cordinates of the "rectangular" object
4
    % of Matlab
5
    % rect_rotation (in degree) is the necessary rotation of the object
6
    % axes_to_plot - figure axes
7
    % color may be expressed as a string like '-r', '-m'
8
    X_cordinates    = [ nan nan nan nan nan];
9
    Y_cordinates    = [ nan nan nan nan nan];
10
    
11
    X_cordinates(1) = rect_position(1);
12
    Y_cordinates(1) = rect_position(2);
13
    
14
    X_cordinates(2) = rect_position(1);
15
    Y_cordinates(2) = rect_position(2) + rect_position(4);
16
    
17
    X_cordinates(3) = rect_position(1) + rect_position(3);
18
    Y_cordinates(3) = rect_position(2) + rect_position(4);
19
    
20
    X_cordinates(4) = rect_position(1) + rect_position(3);
21
    Y_cordinates(4) = rect_position(2);
22
    
23
    X_cordinates(5) = X_cordinates(1);
24
    Y_cordinates(5) = Y_cordinates(1);
25
    
26
    X_centre        = mean([X_cordinates(1) X_cordinates(3)]);
27
    Y_centre        = mean([Y_cordinates(1) Y_cordinates(2)]); 
28
       
29
    % Perform rotation
30
    theta   = rect_rotation * pi/180; % The rotation angle
31
    cth     = cos(theta) ; 
32
    sth     = sin(theta);
33
    Xrot    =  (X_cordinates - X_centre)*cth + (Y_cordinates - Y_centre)*sth + X_centre;
34
    Yrot    = -(X_cordinates - X_centre)*sth + (Y_cordinates - Y_centre)*cth + Y_centre;
35
    
36
    plot(   Xrot, Yrot, color, 'LineWidth', 3, 'Parent', axes_to_plot);
37
       
38
end