Home > matGeom > geom2d > drawParabola.m

drawParabola

PURPOSE ^

DRAWPARABOLA Draw a parabola on the current axis.

SYNOPSIS ^

function varargout = drawParabola(varargin)

DESCRIPTION ^

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 % E-mail: david.legland@inrae.fr
0052 % Created: 2006-06-02
0053 % Copyright 2006-2024 INRA - TPV URPOI - BIA IMASTE
0054 
0055 % Extract parabola
0056 if nargin < 1
0057     error('MatGeom:geom2d:drawParabola:IllegalArgument', ...
0058         'Please specify parabola representation');
0059 end
0060 
0061 % extract handle of axis to draw on
0062 if isAxisHandle(varargin{1})
0063     ax = varargin{1};
0064     varargin(1) = [];
0065 else
0066     ax = gca;
0067 end
0068 
0069 % input parabola is given as a packed array
0070 parabola = varargin{1};
0071 varargin(1) = [];
0072 x0 = parabola(:,1);
0073 y0 = parabola(:,2);
0074 a  = parabola(:,3);
0075 
0076 % check if parabola orientation is specified
0077 if size(parabola, 2) > 3
0078     theta = parabola(:, 4);
0079 else
0080     theta = zeros(length(a), 1);
0081 end
0082 
0083 % extract parametrisation bounds
0084 bounds = [-100 100];
0085 if ~isempty(varargin)
0086     var = varargin{1};
0087     if isnumeric(var)
0088         bounds = var;
0089         varargin(1) = [];
0090     end
0091 end
0092 
0093 % create parametrisation array
0094 if length(bounds) > 2
0095     t = bounds;
0096 else
0097     t = linspace(bounds(1), bounds(end), 100);
0098 end
0099 
0100 % create handle array (in the case of several parabola)
0101 h = zeros(size(x0));
0102 
0103 % draw each parabola
0104 for i = 1:length(x0)
0105     % compute transformation
0106     trans = ...
0107         createTranslation(x0(i), y0(i)) * ...
0108         createRotation(deg2rad(theta(i))) * ...
0109         createScaling(1, a);
0110     
0111     % compute points on the parabola
0112     [xt, yt] = transformPoint(t(:), t(:).^2, trans);
0113 
0114     % draw it
0115     h(i) = plot(ax, xt, yt, varargin{:});
0116 end
0117 
0118 % process output arguments
0119 if nargout > 0
0120     varargout = {h};
0121 end
0122

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022