Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: generating a facetted surface
Replies: 2   Last Post: Sep 29, 2011 5:02 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Peter Schreiber

Posts: 110
Registered: 2/1/08
generating a facetted surface
Posted: Sep 29, 2011 5:02 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi Bruno,
Thanks for the note. As you mentioned the definition of u and v was missing.
I would be very curious if anyone has an elegant way of eliminating the interior surfaces that only the outer facetet surface remains.

Thanks a lot,
Peter

Here is the complete code:




clear all
clc
close all
a=8;
b=8;
c=50;
d=200;
nf_uv_grid = 101;
%alpha=0/180*pi;
%beta=0/180*pi;
gamma=0/180*pi;

[u,v]=meshgrid(linspace(0,2*pi,nf_uv_grid),linspace(0,pi,nf_uv_grid));

[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')
hold on

else

end
end
end




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.