]> Creatis software - CreaPhase.git/blob - octave_packages/vrml-1.0.13/vrml_parallelogram.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / vrml-1.0.13 / vrml_parallelogram.m
1 ## Copyright (C) 2003 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_parallelogram (x,...)
17 ##
18 ## x : 3 x 3 : Each column is a 3D point. The fourth corner is 
19 ##               x(:,1)-x(:,2)+x(:,3)
20 ##
21 ## OPTIONS :
22 ## ---------
23 ## col,   c : 3x1 : Color of surface
24 ## emit,  e : 1   :
25 ## tran,  t : 1   :
26 ##
27 ## border,b : 1   :
28 ## bocol, c : 3   :
29 ## boemit,e : 1   :
30 ## borad, r : 1   :
31 ##
32 ## balls, b : 1   :
33 ## bcol,  c : 3   :
34 ## bemit, e : 1   :
35 ## brad,  r : 1   :
36
37 function s = vrml_parallelogram (x, varargin)
38
39 col = [0.3,0.4,0.9];
40 emit = 0;
41 tran = 0;
42 balls = 0;
43 border = 0;
44 bcol = btran = bemit = brad = borad = bocol = boemit = nan;
45
46 if nargin > 1
47   op1 = " col emit tran balls border bcol btran bemit brad borad bocol boemit ";
48   df = tars (col,emit,tran,balls,border,bcol,btran,bemit,brad,borad,bocol,boemit);
49   s = read_options (varargin, "op1",op1, "default",df);
50   col=s.col; emit=s.emit; tran=s.tran; balls=s.balls; border=s.border;
51   bcol = s.bcol; btran = s.btran; bemit = s.bemit; brad = s.brad;
52   borad = s.borad; bocol = s.bocol; boemit = s.boemit;
53 end
54
55 if ! isnan (bcol) ||! isnan (brad) || ! isnan (bemit), balls = 1; end
56 if balls
57  if isnan (bcol), bcol = col; end
58  if isnan (btran), btran = tran; end
59  if isnan (brad)
60    brad = (norm (x(:,1)-x(:,2))+ norm(x(:,1)-x(:,2)))/20; 
61  end
62 end
63
64 x = [x(:,1:3), x(:,1)-x(:,2)+x(:,3)];
65
66                                 # The facet
67
68 s = vrml_faces (x, (1:4)', "col",col, "tran", tran,"emit",emit);
69
70                                 # Decoration : balls on vertices
71 if balls
72   if isnan (bemit), bemit = emit; end
73   s = [s,vrml_points(x,"balls","rad",brad,"col",bcol,"tran",btran,"emit",bemit)];
74 end
75
76                                 # Decoration : border
77
78 if ! isnan (bocol) ||! isnan (borad) || ! isnan (boemit), border = 1; end
79 if border
80   if isnan (borad)
81     borad = (norm (x(:,1)-x(:,2))+ norm(x(:,1)-x(:,2)))/80;
82   end
83   if isnan (boemit)
84     if isnan (bemit), boemit = emit; else boemit = bemit; end
85   end
86   if isnan (bocol), bocol = col; end
87     
88   if !balls                     # Make pretty junctions of cylinders
89     s = [s,\
90          vrml_cyl(x(:,[1:columns(x),1]),"rad",borad,"emit",boemit,"col",col),\
91          vrml_points(x(:,1),"balls","rad",borad,"emit",boemit,"col",col)];
92   else                          # but only if balls don't cover them
93     s = [s,vrml_cyl(x(:,[1:columns(x),1]),"rad",borad,"emit",boemit)];
94   end
95
96 end
97
98 endfunction
99