@@ -8,23 +8,36 @@ function plot_coord(origin,varargin)
8
8
% ------------------------------------------------------------------------
9
9
% KEY VALUE DESCRIPTION
10
10
% ------------------------------------------------------------------------
11
+ % 'rotate' [AX AY AZ] 3x3 rotation matrix where AX,AY,AZ are the
12
+ % vectors of each axis
13
+ % OR
11
14
% 'rotate' [u v w] Rotate coordinates 'u' degrees around the 1st axis
12
15
% 'v' degrees around the 2nd axis
13
- % 'w' degrees around the 3rd axis
16
+ % & 'w' degrees around the 3rd axis
14
17
% 'order' [r1 r2 r3] Order of rotation, default [3 2 1] for [Z Y X]
15
- % 'axes' ['x' and/or 'y' and/or 'z']
16
- % Only plot axes listed
17
- % 'labels' [true/false]
18
- % Whether to print coordinate system labels
19
- % 'index' str String index on labels (default str='1')
20
18
% ------------------------------------------------------------------------
21
- % 'length' L Length of axes lines
22
- % 'headlength' R Length of arrow head
23
- % 'arrowangle' a Angle of arrowhead "quills"
19
+ % 'length' L Length of axes lines (default 0.05)
20
+ % 'headlength' R Length of arrow head (default (0.02)
21
+ % 'arrowangle' a Angle of arrowhead "quills" in degrees (default 25)
22
+ % 'linewidth' w Linewidth of axes lines and arrow outline (default 0.4)
23
+ % ------------------------------------------------------------------------
24
24
% 'linecolour' [R G B] Red-Green-Blue colour of axis lines
25
25
% 'headcolour' [R G B] Red-Green-Blue colour of arrowhead faces
26
26
% 'headopacity' C Opacity of arrowhead faces
27
27
% ------------------------------------------------------------------------
28
+ % 'axes' ['x' and/or 'y' and/or 'z']
29
+ % Only plot axes listed (default 'xyz')
30
+ % 'labels' [true/false]
31
+ % Whether to print coordinate system labels (default false)
32
+ % 'labelframe' [true/false]
33
+ % Whether to print a "frame" label (default false)
34
+ % 'labelaxes' [true/false]
35
+ % Whether to print coordinate system labels (default false)
36
+ % 'labelshift' l Shift label away from end of axis/frame (default 0.01)
37
+ % 'index' str String index on labels; omit if empty (default '')
38
+ % ------------------------------------------------------------------------
39
+ % 'fontsize' Font size for labels (default same as Matlab)
40
+ % ------------------------------------------------------------------------
28
41
29
42
%% Parse inputs:
30
43
@@ -35,12 +48,17 @@ function plot_coord(origin,varargin)
35
48
p .addOptional(' length' ,0.05 );
36
49
p .addOptional(' headlength' ,0.02 );
37
50
p .addOptional(' arrowangle' ,25 );
38
- p .addOptional(' index' ,' 1' );
39
- p .addOptional(' labels' ,true );
51
+ p .addOptional(' index' ,' ' );
52
+ p .addOptional(' labels' ,false );
53
+ p .addOptional(' labelframe' ,false );
54
+ p .addOptional(' labelaxes' ,false );
40
55
p .addOptional(' axes' ,' xyz' );
41
56
p .addParameter(' linecolour' ,[0 0 0 ]);
57
+ p .addParameter(' linewidth' ,0.4 );
42
58
p .addParameter(' headcolour' ,0.5 *[1 1 1 ]);
43
59
p .addParameter(' headopacity' ,0.9 );
60
+ p .addParameter(' labelshift' ,0.01 );
61
+ p .addParameter(' fontsize' ,get(0 ,' defaulttextfontsize' ));
44
62
p .parse(origin ,varargin{: })
45
63
46
64
O = p .Results .origin ;
@@ -49,16 +67,29 @@ function plot_coord(origin,varargin)
49
67
ang = p .Results .arrowangle ;
50
68
51
69
r = p .Results .rotate ;
52
- ro = p .Results .order ;
53
- ni = p .Results .index ;
70
+ ro = p .Results .order ;
71
+ plot_axes = p .Results .axes ;
72
+
54
73
ecol = p .Results .linecolour ;
74
+ lw = p .Results .linewidth ;
75
+
55
76
col = p .Results .headcolour ;
56
77
opac = p .Results .headopacity ;
78
+
57
79
labels_bool = p .Results .labels ;
58
- plot_axes = p .Results .axes ;
80
+ labelframe_bool = p .Results .labelframe ;
81
+ labelaxes_bool = p .Results .labelaxes ;
82
+ labelshift = p .Results .labelshift ;
83
+
84
+ fontsize = p .Results .fontsize ;
59
85
60
- % Constant that should actually be optional input
61
- nameshift = 0.01 ;
86
+ %%
87
+
88
+ if isempty(p .Results .index )
89
+ index_label = ' ' ;
90
+ else
91
+ index_label = [' _{' ,p .Results .index ,' }' ];
92
+ end
62
93
63
94
%% Definition of a single axis (X)
64
95
%
@@ -74,7 +105,6 @@ function plot_coord(origin,varargin)
74
105
if numel(r ) == 3
75
106
c = cosd(r );
76
107
s = sind(r );
77
-
78
108
RxRyRz(: ,: ,1 ) = [1 0 0 ; 0 c(1 ) - s(1 ); 0 s(1 ) c(1 )];
79
109
RxRyRz(: ,: ,2 ) = [c(2 ) 0 s(2 ); 0 1 0 ; - s(2 ) 0 c(2 )];
80
110
RxRyRz(: ,: ,3 ) = [c(3 ) - s(3 ) 0 ; s(3 ) c(3 ) 0 ; 0 0 1 ];
@@ -91,61 +121,37 @@ function plot_coord(origin,varargin)
91
121
hold on
92
122
93
123
if strcmp(plot_axes ,' xyz' )
94
- if labels_bool
95
- text(-nameshift + O(1 ),-nameshift + O(2 ),O(3 ),[' O_{ ' , ni , ' } ' ] );
124
+ if labels_bool || labelframe_bool
125
+ text(-labelshift + O(1 ),-labelshift + O(2 ),- labelshift + O(3 ),[' O ' , index_label ], ' fontsize ' , fontsize );
96
126
end
97
127
end
98
128
129
+ RX = R ;
130
+ RY = R *[0 - 1 0 ;1 0 0 ;0 0 1 ]; % Rz(+90);
131
+ RZ = R *[0 0 - 1 ;0 1 0 ;1 0 0 ]; % Ry(-90);
132
+
99
133
for s = plot_axes
100
134
switch s
101
135
case ' x'
102
- plot_one_coord(O ,R * ax , R * head1 , R * head2 , [ ' x_{ ' , ni , ' } ' ],[2 * nameshift ; 0 ; 0 ])
136
+ plot_one_coord(O ,RX * ax ,RX * head1 ,RX * head2 ,[ ' x ' , index_label ],[labelshift ; 0 ; 0 ])
103
137
case ' y'
104
- plot_one_coord(O ,R * Rz(+ 90 )* ax ,R * Rz(+ 90 )* head1 ,R * Rz(+ 90 )* head2 ,[' y_{ ' , ni , ' } ' ],[0 ; nameshift ; 0 ])
138
+ plot_one_coord(O ,RY * ax ,RY * head1 ,RY * head2 ,[' y ' , index_label ],[0 ; labelshift ; 0 ])
105
139
case ' z'
106
- plot_one_coord(O ,R * Ry(- 90 )* ax ,R * Ry(- 90 )* head1 ,R * Ry(- 90 )* head2 ,[' z_{ ' , ni , ' } ' ],[0 ; 0 ; nameshift ])
140
+ plot_one_coord(O ,RZ * ax ,RZ * head1 ,RZ * head2 ,[' z ' , index_label ],[0 ; 0 ; labelshift ])
107
141
end
108
142
end
109
143
110
144
%% Nested functions
111
145
112
146
function plot_one_coord(O ,a ,head1 ,head2 ,name ,ns )
113
- if labels_bool
114
- text(ns(1 )+O(1 )+a(1 ),ns(2 )+O(2 )+a(2 ),ns(3 )+O(3 )+a(3 ),name );
147
+ if labels_bool || labelaxes_bool
148
+ text(ns(1 )+O(1 )+a(1 ),ns(2 )+O(2 )+a(2 ),ns(3 )+O(3 )+a(3 ),name , ' fontsize ' , fontsize );
115
149
end
116
150
117
- plot3(O(1 )+[0 a(1 )],O(2 )+[0 a(2 )],O(3 )+[0 a(3 )],' color' ,ecol );
118
- patch(O(1 )+head1(1 ,: ),O(2 )+head1(2 ,: ),O(3 )+head1(3 ,: ),ecol ,' facealpha' ,opac ,' facecolor' ,col );
119
- patch(O(1 )+head2(1 ,: ),O(2 )+head2(2 ,: ),O(3 )+head2(3 ,: ),ecol ,' facealpha' ,opac ,' facecolor' ,col );
151
+ plot3(O(1 )+[0 a(1 )],O(2 )+[0 a(2 )],O(3 )+[0 a(3 )],' color' ,ecol , ' linewidth ' , lw );
152
+ patch(O(1 )+head1(1 ,: ),O(2 )+head1(2 ,: ),O(3 )+head1(3 ,: ),ecol ,' facealpha' ,opac ,' facecolor' ,col , ' linewidth ' , lw );
153
+ patch(O(1 )+head2(1 ,: ),O(2 )+head2(2 ,: ),O(3 )+head2(3 ,: ),ecol ,' facealpha' ,opac ,' facecolor' ,col , ' linewidth ' , lw );
120
154
end
121
155
122
156
end
123
157
124
- %% Rotation matrices
125
- %
126
- % These could all be anonymous functions if we wanted.
127
-
128
- function R = Rz(t )
129
- R = [cosd(t ) - sind(t ) 0 ;
130
- sind(t ) cosd(t ) 0 ;
131
- 0 0 1 ];
132
- end
133
-
134
- function R = Ry(t )
135
- R = [ cosd(t ) 0 sind(t );
136
- 0 1 0 ;
137
- - sind(t ) 0 cosd(t )];
138
- end
139
-
140
- function R = Rx(t )
141
- R = [1 0 0 ;
142
- 0 cosd(t ) - sind(t );
143
- 0 sind(t ) cosd(t )];
144
- end
145
-
146
- % assert( all( Rx(90)*[0;1;0]==[ 0; 0; 1]) )
147
- % assert( all( Rz(90)*[0;1;0]==[-1; 0; 0]) )
148
- % assert( all( Ry(90)*[1;0;0]==[ 0; 0;-1]) )
149
- % assert( all( Rz(90)*[1;0;0]==[ 0; 1; 0]) )
150
- % assert( all( Rx(90)*[0;0;1]==[ 0;-1; 0]) )
151
- % assert( all( Ry(90)*[0;0;1]==[ 1; 0; 0]) )
0 commit comments