[e6773f]: inst / vrml_arrow.m Maximize Restore History

Download this file

vrml_arrow.m    107 lines (97 with data), 3.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
## Copyright (C) 2002 Etienne Grossmann <etienne@cs.uky.edu>
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.
## s = vrml_arrow (sz, col) - Arrow pointing in "y" direction
##
## INPUT :
## -------
## Arguments are optional. NaN's are replaced by default values.
## <default>
## sz = [len, alen, dc, dr] has size 1, 2, 3 or 4, where
##
## len : total length <1>
## alen : length of arrow/total length <len/4>
## dc : Diameter of cone base/total length <len/16>
## dr : Diameter of rod/total length <min(dc, len/32)>
##
## col : 3 or 3x2 : Color of body and cone <[0.3 0.4 0.9]>
##
## OUTPUT :
## --------
## s : string : vrml representation of an arrow (a rod and a cone)
function v = vrml_arrow (sz, col, emit)
if nargin < 3, emit = 1; end
if nargin<2 || isempty (col), col = [0.3 0.4 0.9;0.3 0.4 0.9];
elseif prod (size (col)) == 3, col = [1;1]*col(:)';
elseif all (size (col) == [3,2]), col = col';
elseif any (size (col) != [2,3]),
error("vrml_arrow : col has size %dx%d (should be 3 or 3x2)\n",size(col));
## keyboard
end
col = col' ;
s0 = [1, 1/4, 1/16, 1/32];
# Get absolute size
if nargin<1 || isempty (sz) || isnan (sz), sz = s0 ;
elseif length (sz) == 4, sz = [sz(1),sz(2),sz(3),sz(4)];
elseif length (sz) == 3, sz = [sz(1),sz(2),sz(3),s0(4)];
elseif length (sz) == 2, sz = [sz(1),sz(2),s0(3),s0(4)];
elseif length (sz) == 1, sz = [sz(1),s0(2),s0(3),s0(4)];
else
error ("vrml_arrow : sz has size %dx%d. (should be in 1-4)\n", size(sz));
## keyboard
end
if any (tmp = isnan(sz)), sz(find (tmp)) = s0(find (tmp)) ; end
sz .*= [1, sz([1 1 1])];
# Do material nodes
smat1 = vrml_material (col(:,1), emit);
smat2 = vrml_material (col(:,2), emit);
v = sprintf (["Group {\n",\
" children [\n",\
" Transform {\n",\
" translation %8.3g %8.3g %8.3g\n",\
" children [\n",\
" Shape {\n",\
" appearance Appearance {\n",\
smat1,\
" }\n"\
" geometry Cylinder {\n",\
" radius %8.3g\n",\
" height %8.3g\n",\
" }\n",\
" }\n",\
" ]\n",\
" }\n",\
" Transform {\n",\
" translation %8.3g %8.3g %8.3g\n",\
" children [\n",\
" Shape {\n",\
" appearance Appearance {\n",\
smat2,\
" }\n",\
" geometry Cone { \n",\
" bottomRadius %8.3g \n",\
" height %8.3g\n",\
" }\n",\
" }\n",\
" ]\n",\
" }\n",\
" ]\n",\
"}\n"],\
[0,(sz(1)-sz(2))/2,0],\
sz(4),\
sz(1)-sz(2),\
[0,sz(2)/2+sz(1)-sz(2),0],\
sz(3),\
sz(2));
endfunction