Calculate normals to an isosurface.
If called with one output argument and the first input argument
val is a three-dimensional array that contains the data for an
isosurface geometry and the second input argument v keeps the
vertices of an isosurface then return the normals n in form of
a matrix with the same size than v at computed points
[x, y, z] = meshgrid (1:l, 1:m, 1:n)
. The output argument
n can be taken to manually set VertexNormals of a patch.
If called with further input arguments x, y and z which are three–dimensional arrays with the same size than val then the volume data is taken at those given points. Instead of the vertices data v a patch handle p can be passed to this function.
If given the string input argument "negate"
as last input argument
then compute the reverse vector normals of an isosurface geometry.
If no output argument is given then directly redraw the patch that is given by the patch handle p.
For example:
function [] = isofinish (p) set (gca, "PlotBoxAspectRatioMode", "manual", ... "PlotBoxAspectRatio", [1 1 1]); set (p, "VertexNormals", -get (p,"VertexNormals")); # Revert normals set (p, "FaceColor", "interp"); ## set (p, "FaceLighting", "phong"); ## light ("Position", [1 1 5]); # Available with JHandles endfunction N = 15; # Increase number of vertices in each direction iso = .4; # Change isovalue to .1 to display a sphere lin = linspace (0, 2, N); [x, y, z] = meshgrid (lin, lin, lin); c = abs ((x-.5).^2 + (y-.5).^2 + (z-.5).^2); figure (); # Open another figure window subplot (2,2,1); view (-38, 20); [f, v, cdat] = isosurface (x, y, z, c, iso, y); p = patch ("Faces", f, "Vertices", v, "FaceVertexCData", cdat, ... "FaceColor", "interp", "EdgeColor", "none"); isofinish (p); # Call user function isofinish subplot (2,2,2); view (-38, 20); p = patch ("Faces", f, "Vertices", v, "FaceVertexCData", cdat, ... "FaceColor", "interp", "EdgeColor", "none"); isonormals (x, y, z, c, p); # Directly modify patch isofinish (p); subplot (2,2,3); view (-38, 20); p = patch ("Faces", f, "Vertices", v, "FaceVertexCData", cdat, ... "FaceColor", "interp", "EdgeColor", "none"); n = isonormals (x, y, z, c, v); # Compute normals of isosurface set (p, "VertexNormals", n); # Manually set vertex normals isofinish (p); subplot (2,2,4); view (-38, 20); p = patch ("Faces", f, "Vertices", v, "FaceVertexCData", cdat, ... "FaceColor", "interp", "EdgeColor", "none"); isonormals (x, y, z, c, v, "negate"); # Use reverse directly isofinish (p);
See also: isosurface, isocolors.
Package: octave