|
1 | 1 | %PLOTVOL Set the bounds for a 2D or 3D plot
|
2 | 2 | %
|
3 |
| -% PLOTVOL(W) creates a new axis, and sets the bounds for a 2D plot with X and Y spanning |
4 |
| -% the interval -W to W. The axes are labelled, grid is enabled, aspect ratio set to 1:1, |
5 |
| -% and hold is enabled for subsequent plots. |
| 3 | +% 2D plots:: |
| 4 | +% |
| 5 | +% PLOTVOL([WX WY]) creates a new axis, and sets the bounds for a 2D plot, |
| 6 | +% with X spanning [-WX, WX] and Y spanning [-WY,WY]. |
6 | 7 | %
|
7 | 8 | % PLOTVOL([XMIN XMAX YMIN YMAX]) as above but the X and Y axis limits are explicitly provided.
|
8 | 9 | %
|
9 |
| -% PLOTVOL([XMIN XMAX YMIN YMAX ZMIN ZMAX]) as above but the X, Y and Z axis limits are |
| 10 | +% 3D plots:: |
| 11 | +% |
| 12 | +% PLOTVOL(W) creates a new axis, and sets the bounds for a 3D plot with X, Y and Z spanning |
| 13 | +% the interval -W to W. |
| 14 | +% |
| 15 | +% PLOTVOL([WX WY WZ]) as above with X spanning [-WX, WX], Y spanning [-WY, WY] and Z |
| 16 | +% spanning [-WZ, WZ]. |
| 17 | +% |
| 18 | +% Notes:: |
| 19 | +% - The axes are labelled, grid is enabled, aspect ratio set to 1:1. |
| 20 | +% - Hold is enabled for subsequent plots. |
| 21 | +% |
| 22 | +% See also: axis. |
| 23 | + |
| 24 | +% |
| 25 | +% PLOTVOL([XMIN XMAX YMIN YMAX ZMIN ZMAX]) as above but the X, Y and Z axis limits are |
10 | 26 | % explicitly provided.
|
11 | 27 | %
|
12 | 28 | % See also axis, xaxis, yaxis.
|
13 | 29 |
|
14 | 30 | % Copyright (C) 1993-2019 Peter I. Corke
|
15 | 31 | %
|
16 | 32 | % This file is part of The Spatial Math Toolbox for MATLAB (SMTB).
|
17 |
| -% |
| 33 | +% |
18 | 34 | % Permission is hereby granted, free of charge, to any person obtaining a copy
|
19 | 35 | % of this software and associated documentation files (the "Software"), to deal
|
20 | 36 | % in the Software without restriction, including without limitation the rights
|
|
25 | 41 | % The above copyright notice and this permission notice shall be included in all
|
26 | 42 | % copies or substantial portions of the Software.
|
27 | 43 | %
|
28 |
| -% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 44 | +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
29 | 45 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
30 | 46 | % FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
31 | 47 | % COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
35 | 51 | % https://github.com/petercorke/spatial-math
|
36 | 52 |
|
37 | 53 | function plotvol(bounds)
|
38 |
| - |
39 |
| - if ~any(length(bounds) == [1 4 6]) |
40 |
| - error('SMTB:plotvol:badarg', 'expecting vector of length 1, 4 or 6'); |
41 |
| - end |
42 |
| - if length(bounds) == 1 |
43 |
| - bounds = bounds * [-1 1 -1 1]; |
44 |
| - end |
45 | 54 |
|
| 55 | + assert(any(length(bounds) == [1 2 3 4 6]), 'SMTB:plotvol:badarg', 'expecting vector of length 1, 2, 3, 4 or 6'); |
| 56 | + |
| 57 | + |
| 58 | + clf |
46 | 59 | axis equal
|
47 |
| - axis(bounds); |
48 |
| - |
49 |
| - if length(bounds) == 4 |
50 |
| - % 2D case |
51 |
| - |
52 |
| - set(gca, 'XTick', floor(bounds(1)):floor(bounds(2))) |
53 |
| - set(gca, 'YTick', floor(bounds(3)):floor(bounds(4))) |
54 |
| - |
55 |
| - elseif length(bounds) == 6 |
56 |
| - % 3D case |
57 |
| - set(gca, 'XTick', floor(bounds(1)):floor(bounds(2))) |
58 |
| - set(gca, 'YTick', floor(bounds(3)):floor(bounds(4))) |
59 |
| - set(gca, 'ZTick', floor(bounds(5)):floor(bounds(6))) |
60 |
| - |
| 60 | + |
| 61 | + switch length(bounds) |
| 62 | + case 1 |
| 63 | + bounds = bounds * [-1 1 -1 1 -1 1]; |
| 64 | + case 3 |
| 65 | + bounds = bounds(:) * [-1 1]; |
| 66 | + bounds = bounds'; |
| 67 | + bounds = bounds(:)'; |
| 68 | + case 6 |
| 69 | + % % 3D case |
| 70 | + % set(gca, 'XTick', floor(bounds(1)):floor(bounds(2))) |
| 71 | + % set(gca, 'YTick', floor(bounds(3)):floor(bounds(4))) |
| 72 | + % set(gca, 'ZTick', floor(bounds(5)):floor(bounds(6))) |
| 73 | + bounds = bounds(:)'; |
| 74 | + case 2 |
| 75 | + bounds = bounds(:) * [-1 1]; |
| 76 | + bounds = bounds'; |
| 77 | + bounds = bounds(:)'; |
| 78 | + case 4 |
| 79 | + bounds = bounds(:)'; |
61 | 80 | end
|
62 | 81 |
|
| 82 | + axis(bounds) |
| 83 | + |
63 | 84 | % common code
|
64 | 85 | grid on;
|
65 | 86 | hold on
|
66 |
| - |
67 |
| - |
| 87 | + |
| 88 | + |
68 | 89 | xyzlabel
|
| 90 | +end |
0 commit comments