DRAWPARABOLA Draw a parabola on the current axis. drawParabola(PARABOLA); Draws a vertical parabola, defined by its vertex and its parameter. Such a parabola admits a vertical axis of symetry. The algebraic equation of parabola is given by: (Y - YV) = A * (X - VX)^2 Where XV and YV are vertex coordinates and A is parabola parameter. A parametric equation of parabola is given by: x(t) = t + VX; y(t) = A * t^2 + VY; PARABOLA can also be defined by [XV YV A THETA], with theta being the angle of rotation of the parabola (in degrees and Counter-Clockwise). drawParabola(PARABOLA, T); Specifies which range of 't' are used for drawing parabola. If T is an array with only two values, the first and the last values are used as interval bounds, and several values are distributed within this interval. drawParabola(..., NAME, VALUE); Can specify one or several graphical options using parameter name-value pairs. drawParabola(AX, ...); Specifies handle of the axis to draw on. H = drawParabola(...); Returns an handle to the created graphical object. Example: figure(1); clf; hold on; axis equal; axis([0 100 0 100]) % draw parabola with default parameterization bounds drawParabola([50 50 .2 30]); % draw parabola with more specific bounds and drawing style drawParabola([50 50 .2 30], [-3 3], 'color', 'r', 'linewidth', 2); See Also: drawCircle, drawEllipse
0001 function varargout = drawParabola(varargin) 0002 %DRAWPARABOLA Draw a parabola on the current axis. 0003 % 0004 % drawParabola(PARABOLA); 0005 % Draws a vertical parabola, defined by its vertex and its parameter. 0006 % Such a parabola admits a vertical axis of symetry. 0007 % 0008 % The algebraic equation of parabola is given by: 0009 % (Y - YV) = A * (X - VX)^2 0010 % Where XV and YV are vertex coordinates and A is parabola parameter. 0011 % 0012 % A parametric equation of parabola is given by: 0013 % x(t) = t + VX; 0014 % y(t) = A * t^2 + VY; 0015 % 0016 % PARABOLA can also be defined by [XV YV A THETA], with theta being the 0017 % angle of rotation of the parabola (in degrees and Counter-Clockwise). 0018 % 0019 % drawParabola(PARABOLA, T); 0020 % Specifies which range of 't' are used for drawing parabola. If T is an 0021 % array with only two values, the first and the last values are used as 0022 % interval bounds, and several values are distributed within this 0023 % interval. 0024 % 0025 % drawParabola(..., NAME, VALUE); 0026 % Can specify one or several graphical options using parameter name-value 0027 % pairs. 0028 % 0029 % drawParabola(AX, ...); 0030 % Specifies handle of the axis to draw on. 0031 % 0032 % H = drawParabola(...); 0033 % Returns an handle to the created graphical object. 0034 % 0035 % 0036 % Example: 0037 % figure(1); clf; hold on; 0038 % axis equal; axis([0 100 0 100]) 0039 % % draw parabola with default parameterization bounds 0040 % drawParabola([50 50 .2 30]); 0041 % % draw parabola with more specific bounds and drawing style 0042 % drawParabola([50 50 .2 30], [-3 3], 'color', 'r', 'linewidth', 2); 0043 % 0044 % 0045 % See Also: 0046 % drawCircle, drawEllipse 0047 % 0048 0049 % --------- 0050 % author : David Legland 0051 % INRA - TPV URPOI - BIA IMASTE 0052 % created the 02/06/2006. 0053 % 0054 0055 % HISTORY 0056 % 2010-11-17 rewrite, change parametrisation, update doc 0057 % 2011-03-30 use degrees for angle 0058 % 2011-10-11 add management of axes handle 0059 0060 % Extract parabola 0061 if nargin < 1 0062 error('geom2d:drawParabola:IllegalArgument', ... 0063 'Please specify parabola representation'); 0064 end 0065 0066 % extract handle of axis to draw on 0067 if isAxisHandle(varargin{1}) 0068 ax = varargin{1}; 0069 varargin(1) = []; 0070 else 0071 ax = gca; 0072 end 0073 0074 % input parabola is given as a packed array 0075 parabola = varargin{1}; 0076 varargin(1) = []; 0077 x0 = parabola(:,1); 0078 y0 = parabola(:,2); 0079 a = parabola(:,3); 0080 0081 % check if parabola orientation is specified 0082 if size(parabola, 2) > 3 0083 theta = parabola(:, 4); 0084 else 0085 theta = zeros(length(a), 1); 0086 end 0087 0088 % extract parametrisation bounds 0089 bounds = [-100 100]; 0090 if ~isempty(varargin) 0091 var = varargin{1}; 0092 if isnumeric(var) 0093 bounds = var; 0094 varargin(1) = []; 0095 end 0096 end 0097 0098 % create parametrisation array 0099 if length(bounds) > 2 0100 t = bounds; 0101 else 0102 t = linspace(bounds(1), bounds(end), 100); 0103 end 0104 0105 % create handle array (in the case of several parabola) 0106 h = zeros(size(x0)); 0107 0108 % draw each parabola 0109 for i = 1:length(x0) 0110 % compute transformation 0111 trans = ... 0112 createTranslation(x0(i), y0(i)) * ... 0113 createRotation(deg2rad(theta(i))) * ... 0114 createScaling(1, a); 0115 0116 % compute points on the parabola 0117 [xt, yt] = transformPoint(t(:), t(:).^2, trans); 0118 0119 % draw it 0120 h(i) = plot(ax, xt, yt, varargin{:}); 0121 end 0122 0123 % process output arguments 0124 if nargout > 0 0125 varargout = {h}; 0126 end 0127