1 ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
16 ## s = vrml_cyl(x,...)
18 ## Makes a cylinder that links x(:,1) to x(:,2)
22 ## "tran", transparency : Transparency default = 0
23 ## "col" , col : Color default = [ 0.3 0.4 0.9 ]
24 ## "rad" , radius : Radius of segments default = 0.05
25 ## "balls" : Add balls to extremities
26 ## "brad" : Radius of balls default = rad
27 ## "emit", bool : Use or not emissiveColor
28 ## "noemit" : Same as emit,0
29 ## "arrow" : Last segment is an arrow
30 ## "hcol", hcol : Set color of the head of the arrow.
33 function s = vrml_cyl (x,varargin) # pos 2.1.39
48 op1 = " rad tran col hcol brad emit " ;
49 op0 = " verbose balls noemit arrow " ;
51 df = tars (rad, tran, col, hcol, verbose, balls, noemit, arrow, brad, \
55 s = read_options (varargin, "op1",op1,"op0",op0, "default",df); # pos 2.1.39
69 if isnan (brad), brad = rad; end
70 if !isnan (noemit), emit = ! noemit; end
71 if !isnan (hcol), arrow = 1; end
78 if prod (size (col)) == 3, col = col(:); col = col(:, ones(1,N)); end
79 if emit, emitcol = col; else emitcol = nan(1,N); end
80 if prod (size (tran)) == 1, tran = tran(ones(1,N)); end
81 tran(find (tran==0)) = nan ;
89 ax = cross([0,1,0],d') ;
91 if abs(an)>eps, ax = ax/an ; else ax = [1,0,0] ; end
94 t = mean (x(:,[i,i-1])')' ;
98 smat = vrml_material (col(:,i-1), emitcol(:,i-1), tran(i-1));
100 s = [s,sprintf(["Transform {\n",\
101 " translation %8.3f %8.3f %8.3f\n",\
104 " rotation %8.3f %8.3f %8.3f %8.3f\n",\
107 " appearance Appearance {\n",\
110 " geometry Cylinder {\n",\
126 if isnan (hcol), hcol = col(:,i); end
127 arrowcol = [col(:,i) hcol(1:3)(:)];
129 vrml_transfo(vrml_arrow ([n,nan,2*rad/n,rad/n],arrowcol,emit),\
137 s = [s, vrml_points(x,"balls","col",col, "rad",brad,"emit",emit)];
139 # Make a rounded junction
140 s = [s, vrml_points(x(:,2:columns(x)-1),"balls","col",col,"rad",rad, \