]> Creatis software - CreaPhase.git/blob - octave_packages/vrml-1.0.13/vrml_flatten.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / vrml-1.0.13 / vrml_flatten.m
1 ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
2 ##
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
6 ## version.
7 ##
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
11 ## details.
12 ##
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/>.
15
16 ## s = vrml_flatten (x [, d, w, col]) - A planar surface containing x
17 ##
18 ## If the points  x  are not coplanar (or not in the affine plane {y|d'*y==w}),
19 ## the surface will not contain the points, but rather their projections on
20 ## the plane {y|d'*y==w}.
21 ## 
22 ## x   : 3 x P  : 3D points
23 ## d   : 3      : normal to plane    | Default : given by best_dir()
24 ## w   : 1      : intercept of plane |
25 ## col : 3      : RGB color            Default : [0.3,0.4,0.9]
26 ##
27 ## s   : string : vrml code representing the planar surface
28
29 function s = vrml_flatten (x, d, w, col)
30
31
32 if     nargin <= 3 || isnan (col),  col = [0.3,0.4,0.9];  end
33 if     nargin <= 1 || isnan (d),    [d,w] = best_dir (x); 
34 elseif nargin <= 2 || isnan (w),    w = mean (d'*x); end
35 if   ! nargin,       error ("vrml_flatten : no arguments given"); end 
36
37 y = bound_convex (d,w,x);
38 Q = columns (y);
39 faces = [ones(1,Q-2); 2:Q-1; 3:Q];
40
41
42 s = vrml_faces (y, faces, "col",col);
43 endfunction
44