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 ## v = vrml_ellipsoid (moment, col) - Ellipsoid
18 ## moment : 3x3 : Define elipsoid by x'*moment*x = 1
19 ## or 3 : use diag(moment)
20 ## or 1 : use diag(moment([1,1,1])) default : eye(3)
22 ## col : 3 : Color default : [0.3 0.4 0.9]
25 function v = vrml_ellipsoid(moment, col)
28 if nargin<2 || isempty (col) || isnan (col), col = [0.3 0.4 0.9];
30 error ("vrml_ellipsoid : col has size %d x %d. This won't do\n",size(col));
36 if nargin<1 || isempty (moment), moment = eye(3),
37 elseif all (size (moment) == 3), # Do nothing
38 elseif prod( size (moment)) == 3, moment = diag (moment);
39 elseif length (moment) == 1, moment = moment*eye(3);
41 error ("vrml_ellipsoid : moment has size %d x %d. This won't do\n",size(moment));
45 [u,d,v] = svd (moment);
47 d(find(d)) = 1 ./ nze (d) ;
49 [r,a] = rotparams (u');
51 v = sprintf (["Transform {\n",\
52 " translation 0 0 0\n",\
53 " rotation %8.3g %8.3g %8.3g %8.3g\n",\
54 " scale %8.3g %8.3g %8.3g\n",\
57 " appearance Appearance {\n",\
58 " material Material {\n",\
59 " diffuseColor %8.3g %8.3g %8.3g\n",\
60 " emissiveColor %8.3g %8.3g %8.3g\n",\
63 " geometry Sphere {}\n",\
75 ## d0 = sort (1+2*rand(1,3));
81 ## vrml_browse ([vrml_frame ([0,0,0],uu',"col",eye(3),"scale",2*d0), vrml_ellipsoid(mm)]);