|
|
generating a facetted surface
Posted:
Sep 28, 2011 7:49 PM
|
|
Dear all, I have written some code to shift and tilt ellipsoids which are intersecting each other, with the goal to generate a facetted surface. One item that I'm still trying to figure out is how to remove the interior pieces of the surfaces after they intersect. Any help would be highly appreciated. All that I want to have left is one surface that has as many facets as ellipsoids are used.
Best Regards, Peter
a=8; b=8; c=50; d=200; nf_uv_grid = 31; %alpha=0/180*pi; %beta=0/180*pi; gamma=0/180*pi;
[s_grid_x,s_grid_y]=meshgrid(linspace(-2,2,3),linspace(-2,2,3)); s_grid_z=0.*s_grid_x;
[r_grid_x,r_grid_y]=meshgrid(linspace(-40,40,3),linspace(-40,40,3)); r_grid_z=0.*r_grid_x+0.5*d;
f=sqrt((r_grid_x-s_grid_x).^2+(r_grid_y-s_grid_y).^2+(r_grid_z-s_grid_z).^2);
c=sqrt(f.^2+a^2);
alpha=atan((r_grid_x-s_grid_x)./(r_grid_z-s_grid_z)); beta=atan((r_grid_y-s_grid_y)./(r_grid_z-s_grid_z));
s_grid_x=s_grid_x'; s_grid_y=s_grid_y';
for i=1:size(c,1) for j=1:size(c,2)
if (i==((size(c,1)-1)/2+1) && j==((size(c,2)-1)/2)+1) || i==1 || i==size(c,1) || j==1 || j==size(c,2) x=a.*cos(u).*cos(v); y=b.*cos(u).*sin(v); z=c(i,j).*sin(u)+f(i,j);
xv=reshape(x,1,numel(x)); yv=reshape(y,1,numel(y)); zv=reshape(z,1,numel(z));
shift_M=[1 0 0 s_grid_x(i,j);0 1 0 -s_grid_y(i,j); 0 0 1 0; 0 0 0 1]; Rx=[1 0 0 0; 0 cos(alpha(i,j)) -sin(alpha(i,j)) 0;0 sin(alpha(i,j)) cos(alpha(i,j)) 0; 0 0 0 1]; Ry=[cos(beta(i,j)) 0 sin(beta(i,j)) 0; 0 1 0 0; -sin(beta(i,j)) 0 cos(beta(i,j)) 0; 0 0 0 1]; Rz=[cos(gamma) -sin(gamma) 0 0; sin(gamma) cos(gamma) 0 0; 0 0 1 0; 0 0 0 1];
temp=shift_M*Ry*Rx*[xv;yv;zv;ones(size(xv))];
xs=temp(1,:); ys=temp(2,:); zs=temp(3,:);
xs2=reshape(xs,nf_uv_grid,nf_uv_grid); ys2=reshape(ys,nf_uv_grid,nf_uv_grid); zs2=reshape(zs,nf_uv_grid,nf_uv_grid);
xs2(zs2>20)=NaN; ys2(zs2>20)=NaN; zs2(zs2>20)=NaN;
figure(1) surf(xs2,ys2,zs2) xlabel('x') ylabel('y') zlabel('z') axis([-30 30 -30 30 -10 50]) hold on
else
end end end
|
|