1 ## Copyright (C) 2002-2012 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_arrow (sz, col) - Arrow pointing in "y" direction
20 ## Arguments are optional. NaN's are replaced by default values.
22 ## sz = [len, alen, dc, dr] has size 1, 2, 3 or 4, where
24 ## len : total length <1>
25 ## alen : If positive: length of cone/total length <1/4>
26 ## If negative: -(length of cone)
27 ## dc : If positive: diameter of cone base/total len <1/16>
28 ## If negative: -(diameter of cone)
29 ## dr : If positive: diameter of rod/total length <min(dc, len/32)>
30 ## If negative: -(diameter of rod)
32 ## col : 3 or 3x2 : Color of body and cone <[0.3 0.4 0.9]>
36 ## s : string : vrml representation of an arrow (a rod and a cone)
38 function v = vrml_arrow (sz, col, emit)
40 if nargin < 3, emit = 1; end
42 if nargin<2 || isempty (col), col = [0.3 0.4 0.9;0.3 0.4 0.9];
43 elseif prod (size (col)) == 3, col = [1;1]*col(:)';
44 elseif all (size (col) == [3,2]), col = col';
45 elseif any (size (col) != [2,3]),
46 error("vrml_arrow : col has size %dx%d (should be 3 or 3x2)\n",size(col));
51 s0 = [1, 1/4, 1/16, 1/32];
53 if nargin<1 || isempty (sz) || isnan (sz), sz = s0 ;
54 elseif length (sz) == 4, sz = [sz(1),sz(2),sz(3),sz(4)];
55 elseif length (sz) == 3, sz = [sz(1),sz(2),sz(3),s0(4)];
56 elseif length (sz) == 2, sz = [sz(1),sz(2),s0(3),s0(4)];
57 elseif length (sz) == 1, sz = [sz(1),s0(2),s0(3),s0(4)];
59 error ("vrml_arrow : sz has size %dx%d. (should be in 1-4)\n", size(sz));
65 if !isempty (tmp = find(isnan(sz))), sz(tmp) = s0(tmp) ; end
76 smat1 = vrml_material (col(:,1), emit);
77 smat2 = vrml_material (col(:,2), emit);
79 v = sprintf (["Group {\n",\
82 " translation %8.3g %8.3g %8.3g\n",\
85 " appearance Appearance {\n",\
88 " geometry Cylinder {\n",\
96 " translation %8.3g %8.3g %8.3g\n",\
99 " appearance Appearance {\n",\
102 " geometry Cone { \n",\
103 " bottomRadius %8.3g \n",\
111 [0,(sz(1)-sz(2))/2,0],\
114 [0,sz(2)/2+sz(1)-sz(2),0],\