如何用matlab画zernike曲面

来源:学生作业学帮网 编辑:学帮网 时间:2024/04/29 07:01:02

如何用matlab画zernike曲面

function z = zernfun(n,m,r,theta,nflag)
%ZERNFUN Zernike functions of order N and frequency M on the unit circle.
% Z = ZERNFUN(N,M,R,THETA) returns the Zernike functions of order N
% and angular frequency M, evaluated at positions (R,THETA) on the
% unit circle. N is a vector of positive integers (including 0), and
% M is a vector with the same number of elements as N. Each element
% k of M must be a positive integer, with possible values M(k) = -N(k)
% to +N(k) in steps of 2. R is a vector of numbers between 0 and 1,
% and THETA is a vector of angles. R and THETA must have the same
% length. The output Z is a matrix with one column for every (N,M)
% pair, and one row for every (R,THETA) pair.
%
% Z = ZERNFUN(N,M,R,THETA,'norm') returns the normalized Zernike
% functions. The normalization factor sqrt((2-delta(m,0))*(n+1)/pi),
% with delta(m,0) the Kronecker delta, is chosen so that the integral
% of (r * [Znm(r,theta)]^2) over the unit circle (from r=0 to r=1,
% and theta=0 to theta=2*pi) is unity. For the non-normalized
% polynomials, max(Znm(r=1,theta))=1 for all [n,m].
%
% The Zernike functions are an orthogonal basis on the unit circle.
% They are used in disciplines such as astronomy, optics, and
% optometry to describe functions on a circular domain.
%
% The following table lists the first 15 Zernike functions.
%
% n m Zernike function Normalization
% --------------------------------------------------
% 0 0 1 1
% 1 1 r * cos(theta) 2
% 1 -1 r * sin(theta) 2
% 2 -2 r^2 * cos(2*theta) sqrt(6)
% 2 0 (2*r^2 - 1) sqrt(3)
% 2 2 r^2 * sin(2*theta) sqrt(6)
% 3 -3 r^3 * cos(3*theta) sqrt(8)
% 3 -1 (3*r^3 - 2*r) * cos(theta) sqrt(8)
% 3 1 (3*r^3 - 2*r) * sin(theta) sqrt(8)
% 3 3 r^3 * sin(3*theta) sqrt(8)
% 4 -4 r^4 * cos(4*theta) sqrt(10)
% 4 -2 (4*r^4 - 3*r^2) * cos(2*theta) sqrt(10)
% 4 0 6*r^4 - 6*r^2 + 1 sqrt(5)
% 4 2 (4*r^4 - 3*r^2) * cos(2*theta) sqrt(10)
% 4 4 r^4 * sin(4*theta) sqrt(10)
% --------------------------------------------------
%
% Example 1:
%
% % Display the Zernike function Z(n=5,m=1)
% x = -1:0.01:1;
% [X,Y] = meshgrid(x,x);
% [theta,r] = cart2pol(X,Y);
% idx = r1 | r0;
idx_neg = m