Mercurial > hg > octave-lyh
annotate scripts/plot/tetramesh.m @ 17126:eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Emphasize clarity, use common "voice", and increase density of seealso links.
* doc/interpreter/plot.txi: Add @findex entries that were in xlim.m
* scripts/miscellaneous/getappdata.m scripts/miscellaneous/setappdata.m,
scripts/plot/allchild.m, scripts/plot/ancestor.m, scripts/plot/area.m,
scripts/plot/axes.m, scripts/plot/axis.m, scripts/plot/bar.m,
scripts/plot/barh.m, scripts/plot/box.m, scripts/plot/caxis.m,
scripts/plot/cla.m, scripts/plot/clabel.m, scripts/plot/clf.m,
scripts/plot/close.m, scripts/plot/closereq.m, scripts/plot/colorbar.m,
scripts/plot/comet.m, scripts/plot/comet3.m, scripts/plot/compass.m,
scripts/plot/contour.m, scripts/plot/contour3.m, scripts/plot/contourc.m,
scripts/plot/contourf.m, scripts/plot/copyobj.m, scripts/plot/cylinder.m,
scripts/plot/daspect.m, scripts/plot/diffuse.m, scripts/plot/ellipsoid.m,
scripts/plot/errorbar.m, scripts/plot/ezcontour.m, scripts/plot/ezcontourf.m,
scripts/plot/ezmesh.m, scripts/plot/ezmeshc.m, scripts/plot/ezplot.m,
scripts/plot/ezplot3.m, scripts/plot/ezpolar.m, scripts/plot/ezsurf.m,
scripts/plot/ezsurfc.m, scripts/plot/feather.m, scripts/plot/figure.m,
scripts/plot/fill.m, scripts/plot/findall.m, scripts/plot/findobj.m,
scripts/plot/fplot.m, scripts/plot/gca.m, scripts/plot/gcbf.m,
scripts/plot/gcbo.m, scripts/plot/gcf.m, scripts/plot/gco.m,
scripts/plot/ginput.m, scripts/plot/graphics_toolkit.m, scripts/plot/grid.m,
scripts/plot/gtext.m, scripts/plot/guidata.m, scripts/plot/guihandles.m,
scripts/plot/hdl2struct.m, scripts/plot/hggroup.m, scripts/plot/hidden.m,
scripts/plot/hist.m, scripts/plot/hold.m, scripts/plot/ishghandle.m,
scripts/plot/ishold.m, scripts/plot/isocolors.m, scripts/plot/isprop.m,
scripts/plot/legend.m, scripts/plot/line.m, scripts/plot/linkprop.m,
scripts/plot/loglog.m, scripts/plot/loglogerr.m, scripts/plot/mesh.m,
scripts/plot/meshc.m, scripts/plot/meshgrid.m, scripts/plot/meshz.m,
scripts/plot/newplot.m, scripts/plot/orient.m, scripts/plot/pareto.m,
scripts/plot/patch.m, scripts/plot/pcolor.m, scripts/plot/peaks.m,
scripts/plot/pie.m, scripts/plot/pie3.m, scripts/plot/plot.m,
scripts/plot/plot3.m, scripts/plot/plotmatrix.m, scripts/plot/plotyy.m,
scripts/plot/polar.m, scripts/plot/print.m, scripts/plot/quiver.m,
scripts/plot/quiver3.m, scripts/plot/rectangle.m, scripts/plot/refresh.m,
scripts/plot/refreshdata.m, scripts/plot/ribbon.m, scripts/plot/rose.m,
scripts/plot/saveas.m, scripts/plot/scatter.m, scripts/plot/scatter3.m,
scripts/plot/semilogx.m, scripts/plot/semilogxerr.m, scripts/plot/semilogy.m,
scripts/plot/semilogyerr.m, scripts/plot/shading.m, scripts/plot/shg.m,
scripts/plot/shrinkfaces.m, scripts/plot/slice.m, scripts/plot/specular.m,
scripts/plot/sphere.m, scripts/plot/stairs.m, scripts/plot/stem.m,
scripts/plot/stem3.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m,
scripts/plot/surf.m, scripts/plot/surface.m, scripts/plot/surfc.m,
scripts/plot/surfl.m, scripts/plot/tetramesh.m, scripts/plot/text.m,
scripts/plot/title.m, scripts/plot/trimesh.m, scripts/plot/triplot.m,
scripts/plot/trisurf.m, scripts/plot/view.m, scripts/plot/waitbar.m,
scripts/plot/waitforbuttonpress.m, scripts/plot/waterfall.m,
scripts/plot/whitebg.m, scripts/plot/xlabel.m, scripts/plot/xlim.m,
scripts/plot/ylabel.m, scripts/plot/ylim.m, scripts/plot/zlabel.m,
scripts/plot/zlim.m: Rewrite docstrings for most plot functions.
Emphasize clarity, use common "voice", and increase density of seealso links.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 31 Jul 2013 13:53:30 -0700 |
parents | ddac88d32d6a |
children | bc924baa2c4e |
rev | line source |
---|---|
14514 | 1 ## Copyright (C) 2012 Martin Helm |
2 ## | |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
14623
fd3acd55dd42
tetramesh.m: Fix unbalanced parentheses in @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents:
14541
diff
changeset
|
20 ## @deftypefn {Function File} {} tetramesh (@var{T}, @var{X}) |
fd3acd55dd42
tetramesh.m: Fix unbalanced parentheses in @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents:
14541
diff
changeset
|
21 ## @deftypefnx {Function File} {} tetramesh (@var{T}, @var{X}, @var{C}) |
fd3acd55dd42
tetramesh.m: Fix unbalanced parentheses in @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents:
14541
diff
changeset
|
22 ## @deftypefnx {Function File} {} tetramesh (@dots{}, @var{property}, @var{val}, @dots{}) |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
23 ## @deftypefnx {Function File} {@var{h} =} tetramesh (@dots{}) |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
24 ## Display the tetrahedrons defined in the m-by-4 matrix @var{T} as 3-D patches. |
14514 | 25 ## |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
26 ## @var{T} is typically the output of a Delaunay triangulation |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
27 ## of a 3-D set of points. Every row of @var{T} contains four indices into |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
28 ## the n-by-3 matrix @var{X} of the vertices of a tetrahedron. Every row in |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
29 ## @var{X} represents one point in 3-D space. |
14514 | 30 ## |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
31 ## The vector @var{C} specifies the color of each tetrahedron as an index |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
32 ## into the current colormap. The default value is 1:m where m is the number |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
33 ## of tetrahedrons; the indices are scaled to map to the full range of the |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
34 ## colormap. If there are more tetrahedrons than colors in the colormap then |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
35 ## the values in @var{C} are cyclically repeated. |
14514 | 36 ## |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
37 ## Calling @code{tetramesh (@dots{}, "property", "value", @dots{})} passes all |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
38 ## property/value pairs directly to the patch function as additional arguments. |
14514 | 39 ## |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
40 ## The optional return value @var{h} is a vector of patch handles where each |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
41 ## handle represents one tetrahedron in the order given by @var{T}. |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
42 ## A typical use case for @var{h} is to turn the respective patch "visible" |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
43 ## property "on" or "off". |
14514 | 44 ## |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
45 ## Type @code{demo tetramesh} to see examples on using @code{tetramesh}. |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
46 ## @seealso{trimesh, delaunay3, delaunayn, patch} |
14514 | 47 ## @end deftypefn |
48 | |
49 ## Author: Martin Helm <martin@mhelm.de> | |
50 | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
51 function h = tetramesh (varargin) |
14514 | 52 |
53 [reg, prop] = parseparams (varargin); | |
54 | |
55 if (length (reg) < 2 || length (reg) > 3) | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
56 print_usage (); |
14514 | 57 endif |
58 | |
59 T = reg{1}; | |
60 X = reg{2}; | |
61 | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
62 if (! ismatrix (T) || columns (T) != 4) |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
63 error ("tetramesh: T must be a n-by-4 matrix"); |
14514 | 64 endif |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
65 if (! ismatrix (X) || columns (X) != 3) |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
66 error ("tetramesh: X must be a n-by-3 matrix"); |
14514 | 67 endif |
68 | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
69 size_T = rows (T); |
14514 | 70 colmap = colormap (); |
71 | |
72 if (length (reg) < 3) | |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14623
diff
changeset
|
73 size_colmap = rows (colmap); |
14514 | 74 C = mod ((1:size_T)' - 1, size_colmap) + 1; |
75 if (size_T < size_colmap && size_T > 1) | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
76 ## expand to the available range of colors |
14514 | 77 C = floor ((C - 1) * (size_colmap - 1) / (size_T - 1)) + 1; |
78 endif | |
79 else | |
80 C = reg{3}; | |
81 if (! isvector (C) || size_T != length (C)) | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
82 error ("tetramesh: C must be a vector of the same length as T"); |
14514 | 83 endif |
84 endif | |
85 | |
86 h = zeros (1, size_T); | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
87 if (strcmp (graphics_toolkit (), "gnuplot")) |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
88 ## tiny reduction of the tetrahedron size to help gnuplot by |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
89 ## avoiding identical faces with different colors |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
90 for i = 1:size_T |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
91 [th, p] = __shrink__ ([1 2 3 4], X(T(i, :), :), 1 - 1e-7); |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
92 hvec(i) = patch ("Faces", th, "Vertices", p, |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
93 "FaceColor", colmap(C(i), :), prop{:}); |
14514 | 94 endfor |
95 else | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
96 for i = 1:size_T |
14514 | 97 th = [1 2 3; 2 3 4; 3 4 1; 4 1 2]; |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
98 hvec(i) = patch ("Faces", th, "Vertices", X(T(i, :), :), |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
99 "FaceColor", colmap(C(i), :), prop{:}); |
14514 | 100 endfor |
101 endif | |
102 | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
103 if (nargout > 0) |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
104 h = hvec; |
14514 | 105 endif |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
106 |
14514 | 107 endfunction |
108 | |
109 ## shrink the tetrahedron relative to its center of gravity | |
110 function [tri, p] = __shrink__ (T, X, sf) | |
111 midpoint = repmat (sum (X(T, :), 1) / 4, 12, 1); | |
112 p = [X([1 2 3], :); X([2 3 4], :); X([3 4 1], :); X([4 1 2], :)]; | |
113 p = sf * (p - midpoint) + midpoint; | |
114 tri = reshape (1:12, 3, 4)'; | |
115 endfunction | |
116 | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
117 |
14514 | 118 %!demo |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
119 %! clf; |
14514 | 120 %! d = [-1 1]; |
121 %! [x,y,z] = meshgrid (d, d, d); | |
122 %! x = [x(:); 0]; | |
123 %! y = [y(:); 0]; | |
124 %! z = [z(:); 0]; | |
125 %! tetra = delaunay3 (x, y, z); | |
126 %! X = [x(:) y(:) z(:)]; | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
127 %! colormap (jet (64)); |
14514 | 128 %! h = tetramesh (tetra, X); |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
129 %! set (h(1:2:end), 'Visible', 'off'); |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
130 %! axis equal; |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
131 %! view (30, 20); |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
132 %! title ('Using jet (64), every other tetrahedron invisible'); |
14514 | 133 |
134 %!demo | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
135 %! clf; |
14514 | 136 %! d = [-1 1]; |
137 %! [x,y,z] = meshgrid (d, d, d); | |
138 %! x = [x(:); 0]; | |
139 %! y = [y(:); 0]; | |
140 %! z = [z(:); 0]; | |
141 %! tetra = delaunay3 (x, y, z); | |
142 %! X = [x(:) y(:) z(:)]; | |
143 %! colormap (gray (256)); | |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
144 %! tetramesh (tetra, X, 21:20:241, 'EdgeColor', 'w'); |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
145 %! axis equal; |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
146 %! view (30, 20); |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
147 %! title ('Using gray (256) and white edges'); |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
148 |