function [Xout, Yout, Zout] = polar3d(Zin,theta_min,theta_max,Rho_min,Rho_max,meshscale,varargin)
%
% POLAR3D Plots a 3D polar surface.
%
% POLAR3D(Zin,theta_min,theta_max,Rho_min,Rho_max,meshscale) plots
% the profiles as a mesh plot for Zin between radii Rho_min and
% Rho_max for polar angles equally spaced between theta_min and theta_max.
%
% POLAR3D(Zin,theta_min,theta_max,Rho_min,Rho_max,meshscale,plotspec)
% plots the profiles Zin between radii Rho_min and Rho_max for
% polar angles between theta_min and theta_max with a plot type
% specification. If plotspec = 'surf' a standard Matlab surface
% is plotted,whereas 'mesh', 'surfc' or 'meshc' will plot mesh,
% surface with countour, or mesh with contour, respectively.
% The size of the squares on the mesh or surf plots is determined
% by meshscale. The default plot is a mesh plot.
%
%
% [Xout,Yout,Zout] = POLAR3D(Zin,theta_min,theta_max,Rho_min,
% Rho_max, meshscale)returns Zout values corresponding to the
% Cartesian positions (Xout,Yout).
%
% SYNTAX polar3d(Zin,theta_min,theta_max,Rho_min,Rho_max,meshscale)
% polar3d(Zin,theta_min,theta_max,Rho_min,Rho_max,meshscale,plotspec)
% polar3d(Zin,theta_min,theta_max,Rho_min,Rho_max,meshscale,interpspec)
% polar3d(Zin,theta_min,theta_max,Rho_min,Rho_max,meshscale, plotspec,interpspec)
% [Xout,Yout,Zout] = polar3d(Zin,theta_min,theta_max,Rho_min,Rho_max,...)
%
% INPUT Zin input magnitude profiles where each column in Zin is
% assumed to represent the radial information in the
% plot i.e. each column represents the information
% along a radial line defined by theta, where theta
% varies between theta_min and theta_max.
%
% Zin is a (M x N) matrix, where M and N are not
% necessarily equal. If M is not equal to N then the
% data are interpolated to make them equal. The final
% size is determined by the larger value of (M,N).
%
% The N columns of Zin are assumed to be equally
% spaced measurements of the radial components, where
% Zin(1,1) corresponds to (theta_min,Rho_max) and
% Zin(M,1) corresponds to (theta_min,Rho_min), and so on.
% Zin(1,N) corresponds to (theta_max,Rho_max) and
% Zin(M,N) corresponds to (theta_max,Rho_min). Theta
% increases in the anticlockwise direction.
%
% theta_min the lower value in radians of the angular range
% over which the data is defined. Theta_min is a
% scalar quantity.
%
% theta_max the upper value in radians of the angular range
% over which the data is defined. Theta_max is a
% scalar quantity.
%
% Rho_min the lower value of the radial component for which
% the data is defined. Rho_min is a scalar quantity.
%
% Rho_max the upper value of the radial component for which
% the data is defined. Rho_max is a scalar quantity.
%
% meshscale a scalar that determines the size of the squares
% on the mesh or surf plots. If meshscale is 1, the
% mesh remains unchanged relative to the input grid;
% if meshscale is 2, the size of the squares is doubled,
% if 3.2, say, it is scaled accordingly. Moreover, if
% meshscale is less than 1, e.g. 0.2, the size of the
% squares is reduced into a finer mesh. The dimensions
% of Xout, Yout and Zout are reduced or enlarged by
% meshscale.
%
% plotspec = 'surf' produces a surface plot.
% = 'surfc' produces a surface plot with contour.
% = 'mesh' produces a mesh plot.
% = 'meshc' produces a mesh plot with countour.
% = 'contour' produces a 2D contour plot.
% = 'contourf' produces a 2D filled contour plot.
% = 'off' disengages plot function.
%
% interpspec = 'linear' bilinear interpolation on Zin.
% = 'spline' spline interpolation on Zin.
% = 'nearest' nearest neighbour interpolation on Zin.
% = 'cubic' bicubic interpolation on Zin.
%
% OUTPUT Zout output magnitude profiles defined by Zin at
% positions (Xout,Yout).
%
% Zout is square with dimensions determined by the
% maximum dimension of the input matrix Zin. The
% dimensions of Zout are reduced or enlarged by meshscale.
%
% Xout output X-positions corresponding to polar positions
% (rho,theta). Xout is square with dimensions
% determined by the maximum dimension of the input
% matrix Zin. The dimensions of Xout are reduced or
% enlarged by meshscale.
%
% Yout output Y-positions corresponding to polar positions
% (rho,theta). Yout is square with dimensions
% determined by the maximum dimension of the input
% matrix Zin. The dimensions of Yout are reduced or
% enlarged by meshscale.
%
% Written by JM DeFreitas, QinetiQ Ltd, Winfrith Technology
% Centre, Dorchester DT2 8XJ, UK. jdefreitas@qinetiq.com.
%
% Revision 1.0 4 April 2005.
% Released 5 April 2005. (Beta Release).
%
% Revision 1.1 17 April 2005
% 1. Inroduced new check on Zin to cover case of dimensions (M x 2)
% or (2 x N) matrix. These are not allowed.
% 2. Changed L2 so that when meshscale > 1 and theta ranges over
% 360 degrees the data wraps around without spaces.
% 3. Removed Xout1, Yout1 and Zout1.
% 4. Changed 'theta(j,:) = ones([(L2/n) 1])*angl(j);' to
% 'theta(j,:) = ones([1 (L2/n)])*angl(j)'; so that it is
% compatible with Matlab6 R12.1.
% 5. Reorganised meshgrid so that interpolation now works with
% meshscale < 1.
% 6. Changed error traps from '((p ~= 1)&(q ~= 1))' to
% '((p ~= 1)|(q ~= 1))' where used.
%
% Full Release 26 May 2005. All Rights Reserved.
%
% Terms and Conditions of Use
%
% 1. This function is made available to Matlab� users under the
% terms and conditions set out in the Matlab Exchange by
% The Mathworks, Inc.
% 2. Where the use of POLAR3D is to be cited, the following is recommended:
% J M De Freitas. �POLAR3D: A 3-Dimensional Polar Plot Function
% in Matlab��. QinetiQ Ltd, Winfrith Technology Centre, Winfrith,
% Dorchester DT2 8XJ. UK. 2 June 2005.
% 3. No offer of warranty is made or implied by the author and
% use of this work implies that the user has agreed to take full
% responsibility for its use.
%
if (nargin < 6)
disp('Polar3d Error: Too few input arguments.');
return
elseif (nargin