-MATLAB开发)
MATLAB自建函数quiver3_Renderingquiver3_Rendering更新内容新的quiver_Refine函数quiver3_Rendering函数使用方法结果展示quiver3_Rendering之前利用MATLAB绘制更好看的箭头自建函数quiver_Refine可以输入箭头的位置a,b,c与朝向alpha,beta,gamma在坐标区中返回三维箭头现进一步加强其可调节功能以及进一步打包至最终函数quiver3_Rendering。更新内容对quiver_Refine函数进行了一些功能拓展除了标准的控制箭头位置与朝向功能增加了如下几点新功能可选择箭头的旋转中心控制箭头在旋转时以整个箭头的中点为旋转点或者以箭头的圆柱的中点为旋转点。以HSL方式渲染箭头时色环可顺逆时针旋转且旋转的角度可输入。增加了箭头渲染模式可选功能可以选择不同的箭头渲染模式甚至可自定义箭头渲染模式。全新的箭头参数输入功能箭头中圆锥的半径/高圆柱的半径/高可作为参数输入。增加了箭头透明度作为参数输入。将quiver_Refine函数打包至quiver3_Rendering函数中将位置矩阵方向矩阵以及色环角度/颜色渲染模式作为输入与MATLAB内部函数quiver3类似。新的quiver_Refine函数function[s1,s2,s3,s4]quiver_Refine(s,x,V,theta,color,r1,h1,r2,h2,al)%quiver_Refine(rotation_center,position,direction,color,Cone_r,Cone_h,...%Cylinder_r,Cylinder_h,alpha)%s1rotate along the arrow center%s0rotate along the cylinder center%color control the colormap%1~HSL%2~RWB%3~Customized%read data ax(1,1);bx(1,2);cx(1,3);alphaV(1,1);betaV(1,2);gammaV(1,3);r10:0.01:r1;%Cone%The cone top position a1a;b1b;%Generate cone data[u,v,w]cylinder(r1,50);uua1;vvb1;w-w*h1c(h1h2)/2h1/2-h1/2*s;%Cone botton t1(0:0.04:2)*pi;rmax(r1(:));xca1;ycb1;zc-h1c(h1h2)/2h1/2-h1/2*s;%Generate cone botton data x1xccos(t1)*r;y1ycsin(t1)*r;[m,n]size(x1);z1repmat(zc,m,n);%Cylinder%The cylinder top position a2a;b2b;c2c-h1;%Generate cylinder data[x,y,z]cylinder(r2,50);xxa2;yyb2;z-z*h2c2(h1h2)/2h1/2-h1/2*s;%Cylinder botton t2(0:0.04:2)*pi;rr2;xca2;ycb2;zcc2-h2(h1h2)/2h1/2-h1/2*s;%Generate cylinder botton data x2xccos(t2)*r;y2ycsin(t2)*r;[m,n]size(x2);z2repmat(zc,m,n);%Rotate arrow hold on origin[a b c];theta2acos(gamma./sqrt(alpha.^2beta.^2gamma.^2));ifbeta^2alpha^20direct[010];elsedirect[-beta,alpha,0];endswitchcolorcase1%control vector color using HSL%Hue:in-plane magnetization%Lightness:out-of-plane magnetization Hatan2(-beta,alpha);%-beta due to the y direction reverse%Get the atan2 space in0~2*piifH0H2*piH;end%rotate clockwisely HHtheta/180*pi;ifH0HH2*pi;elseif H2*pi HH-2*pi;end Ssqrt(alpha.^2beta.^2);I(gamma1)/2;%contrast1;%Smin(1,contrast*(1-gamma));%Imin(1,contrast*(1gamma));%change HSL to RGB idxfind((0H)(H2*pi/3));B(idx)I(idx).*(1-S(idx));R(idx)I(idx).*(1S(idx).*cos(H(idx))./cos(pi/3-H(idx)));G(idx)3*I(idx)-(B(idx)R(idx));idxfind((2*pi/3H)(H4*pi/3));R(idx)I(idx).*(1-S(idx));G(idx)I(idx).*(1S(idx).*cos(H(idx)-2*pi/3)./cos(pi-H(idx)));B(idx)3*I(idx)-(G(idx)R(idx));idxfind((4*pi/3H)(H2*pi));G(idx)I(idx).*(1-S(idx));B(idx)I(idx).*(1S(idx).*cos(H(idx)-4*pi/3)./cos(5*pi/3-H(idx)));R(idx)3*I(idx)-(G(idx)B(idx));case2%control vector color using RWB%White:in-plane magnetization%Red or blue:out-of-plane magnetizationifgamma0R1;elseR1-gamma;endifgamma0B1;elseB1gamma;end G1-abs(gamma);case3%control vector color using shades of green color R0;B0;G1;otherwise R0;B0;G0;end c[R G B];c(isnan(c))0;%Get c in the right sectionfori1:3c(i)max(min(c(i),1),0);end%plot s1surf(u,v,w,Facecolor,c,Edgecolor,none,FaceAlpha,al);s2surf(x,y,z,Facecolor,c,Edgecolor,none,FaceAlpha,al);s3fill3(x1,y1,z1,c,Edgecolor,none,FaceAlpha,al);s4fill3(x2,y2,z2,c,Edgecolor,none,FaceAlpha,al);iftheta2~0rotate(s1,direct,rad2deg(theta2),origin);rotate(s2,direct,rad2deg(theta2),origin);rotate(s3,direct,rad2deg(theta2),origin);rotate(s4,direct,rad2deg(theta2),origin);end%must be enabled to get right axis axis equal endquiver3_Rendering函数function[]quiver3_Rendering(X,Y,Z,U,V,W,theta,color)[N1,N2]size(X);fori1:N1forj1:N2 a0X(i,j);b0Y(i,j);c0Z(i,j);p[a0,b0,c0];alpha0U(i,j);beta0V(i,j);gamma0W(i,j);d[alpha0,beta0,gamma0];%0.2,0.65,0.08,0.35quiver_Refine(1,p,d,theta,color,0.2,0.65,0.08,0.35,1);hold on end end end使用方法quiver3_Rendering(X,Y,Z,U,V,W,theta,color)与MATLAB内部函数quiver3类似X,Y,Z为输入的位置矩阵U,V,W为相应的方向矩阵theta为色环的旋转角度color为箭头渲染的模式1为经典的HSL渲染2为经典的RWB三色渲染3提供了可自定义的渲染方式。quiver_Refine(s,x,V,theta,color,r1,h1,r2,h2,al)s选择旋转中心r1,h1,r2,h2控制箭头的具体形状al控制箭头透明度结果展示