- /
-
teardrop
on 9 Nov 2023
- 6
- 32
- 0
- 2
- 1132
drawframe(27);
Write your drawframe function below
Animated version of 3D Ultrasound (2021)
function drawframe(f)
persistent L
if f==1 || isempty(L)
% Create base sphere,define eye locations
[x,y,z]=sphere(600);
eyepos=[-.4,-1,.2; .4 -1 .2]; %[x,y,z] coordinates of [L;R] eye
% Rewrite pdist2() since it's currently not accpted in the contest
pdist2=@(x0,y0,z0,xyz)sqrt((xyz(1)-x0(:)).^2 + (xyz(2)-y0(:)).^2 + (xyz(3)-z0(:)).^2);
cDist=[pdist2(x,y,z,eyepos(1,:)),pdist2(x,y,z,eyepos(2,:))];
% cDist=pdist2([x(:),y(:),z(:)],eyepos); % Distance of sphere points to eyes
lgFcn=@(x,A)1./((1+.4.*exp(-A*x+4)).^2); % logistics fcn to define eye profiles; in exp(-A*B+C) A affects diam (inversely)
% Create orbits (concave) and eye lids (convex)
r=.65; % orbit radii
v=.3; % eyelid radii
g=4; % orbit depth
k=-3; % eyelid depth (neg. for convex)
profiles=[lgFcn(cDist./r,9).*r/g+1-r/g,lgFcn(cDist./v,7).*v/k+1-v/k]; %[orbit,eyelid]
% Create nose profile
% The vertical profile (z-axis) is produced by combining a gaussian with a flat-top gaussian.
noseBounds=[-.2,.35]; % z val for [noseTip,topOfBridge]
hGausFcn=@(x,amp,center,sigma,k)amp.*exp(-((x(:)-center).^2/(2*sigma.^2)).^k); % Higher order gaussian (flat top when k is large)
gSig =.175; % higher order gaus sigma; determines steepness of cutoff
kP=4; % shape param for higher order gaus.; larger values make nose end more abruptly
zg=hGausFcn(z,1,mean(noseBounds),gSig,kP);
noseAmp=0.1; % how far the nose sticks out
noseSig=0.2; % determines nose curvature
zs=hGausFcn(z,noseAmp,noseBounds(1),noseSig,1);
zNoseProf=zs .* zg;
% Azimuthal nose profile follows a gaussian within the azimuthal angles that define nose width.
[Az,Phi,Rd]=cart2sph(x,y,z);
azNoseBounds= hGausFcn(Az(:),1,-pi/2,.07,1); %[theta,amplitude,center,sigma,k] k=1 for guassian
% Combine vertical and azimuthal profiles
noseProf=zNoseProf .* azNoseBounds;
Rd(:)=prod(profiles,2)+noseProf; % final shape
[a,b,c]=sph2cart(Az,Phi,Rd);
ax=gca;
surf(a*1.3,b,c,'EdgeC','none')
axis equal
set(ax,'Clipping','off','Color','k','Colormap',copper)
campos([-6.29 -15.44 5.71])
camtarget([0.22 -0.15 -0.23])
camup([-0.087 0.34 0.92])
camva(3)
material dull
L=light('Position',[0 0 1]);
M=[.1 .7 .5;0 .2 .8;-.4 .5 .5;0 0 .8;.4 -.5 .4;0 .6 .5];
L.UserData=interp1(1:6,M,linspace(1,6,48));
camorbit(-10,0)
end
L.Position=L.UserData(f,:); % Update lighting
camorbit(0.5,0) % update scene viewing angle
end