From: Per Sundqvist on
"striker " <friend_019(a)hotmail.com> wrote in message <hjmr44$jhg$1(a)fred.mathworks.com>...
> Yes the banana shape is important

If you modify the PlotTube function a little (see below)
http://www.mathworks.com/matlabcentral/fileexchange/5562-tubeplot

I can get a pretty nice banana with the code (change 20 to 7 and see what happen):

t=linspace(0,pi,50);
tubeplot([cos(t);sin(t);0*t],0.1*t.*(pi-t),20);axis equal
shading interp;lighting phong;light;axis off

/Per

My slightly fix of the original code below. Hope he doesn't mind... Copy and save as tubeplot.m
-------------------------------------------------------

function [x,y,z]=tubeplot(curve,r,n,ct)
% Usage: [x,y,z]=tubeplot(curve,r,n,ct)
%
% Tubeplot constructs a tube, or warped cylinder, along
% any 3D curve, much like the build in cylinder function.
% If no output are requested, the tube is plotted.
% Otherwise, you can plot by using surf(x,y,z);
%
% Example of use:
% t=linspace(0,2*pi,50);
% tubeplot([cos(t);sin(t);0.2*(t-pi).^2],0.1);
% daspect([1,1,1]); camlight;
%
% Arguments:
% curve: [3,N] vector of curve data
% r the radius of the tube
% n number of points to use on circumference. Defaults to 8
% ct threshold for collapsing points. Defaults to r/2
%
% The algorithms fails if you have bends beyond 90 degrees.
% Janus H. Wesenberg, july 2004

if nargin<3 || isempty(n), n=8;
if nargin<2, error('Give at least curve and radius');
end;
end;
if size(curve,1)~=3
error('Malformed curve: should be [3,N]');
end;
if nargin<4 || isempty(ct)
ct=-1+0*0.5*r;
end


%Collapse points within 0.5 r of each other
npoints=1;
for k=2:(size(curve,2)-1)
if norm(curve(:,k)-curve(:,npoints))>ct;
npoints=npoints+1;
curve(:,npoints)=curve(:,k);
end
end
%Always include endpoint
if norm(curve(:,end)-curve(:,npoints))>0
npoints=npoints+1;
curve(:,npoints)=curve(:,end);
end

%deltavecs: average for internal points.
% first strecth for endpoitns.
dv=curve(:,[2:end,end])-curve(:,[1,1:end-1]);

%make nvec not parallel to dv(:,1)
nvec=zeros(3,1);
[buf,idx]=min(abs(dv(:,1))); nvec(idx)=1;

xyz=repmat([0],[3,n+1,npoints+2]);

%precalculate cos and sing factors:
cfact=repmat(cos(linspace(0,2*pi,n+1)),[3,1]);
sfact=repmat(sin(linspace(0,2*pi,n+1)),[3,1]);

%Main loop: propagate the normal (nvec) along the tube
for k=1:npoints
convec=cross(nvec,dv(:,k));
convec=convec./norm(convec);
nvec=cross(dv(:,k),convec);
nvec=nvec./norm(nvec);
%update xyz:
xyz(:,:,k+1)=repmat(curve(:,k),[1,n+1])+...
cfact.*repmat(r(k)*nvec,[1,n+1])...
+sfact.*repmat(r(k)*convec,[1,n+1]);
end;

%finally, cap the ends:
xyz(:,:,1)=repmat(curve(:,1),[1,n+1]);
xyz(:,:,end)=repmat(curve(:,end),[1,n+1]);

%,extract results:
x=squeeze(xyz(1,:,:));
y=squeeze(xyz(2,:,:));
z=squeeze(xyz(3,:,:));

%... and plot:
if nargout<3, surf(x,y,z); end;
From: striker on
@ Per Sundqvist

Thank you very much sir..
From: Walter Roberson on
striker wrote:
> Yes the banana shape is important

If the banana shape is important, then you still need to be able to answer
questions about the number of sides, relative proportions of the sides,
curvature of each of the sides, how the curvature varies along the length.

If you don't know that information, then you will not be able to "create a
model that looks like a banana": at best, you will be able to create something
that is a rough approximation of the shape of a banana -- and if all you
create is a rough approximation, then the banana shape is NOT important to you.

Any model will be an approximation, of course, but you have to decide which
features of the original must be represented and to what precision.

Have you at least taken a real banana and done some measurements with a ruler
and a French Curve?