## Drawing Beautiful Explicite and Implicite Functions using Matlab

This short demo shows how to generate beautiful surface plots of implicite and explicite functions using default matlab routines. By adding some lighting and computing local surface normals we can produce renderings of unexpected quality.

## Contents

## Explicite graph function

Generate a regular 2D mesh and evaluate a graph function z = f(x, y).

[x, y] = meshgrid(linspace(-1.5, 1.5, 50)); z = x.^2 + y.^2;

Draw a red surface with no edge color and 75 % transparency into a new figure.

figure(1); clf; surf(x, y, z, ... 'FaceColor', 'red', 'EdgeColor', 'none', 'FaceAlpha', 0.75);

Now adjust figure, axes and lighting:

- Set figure color to white.
- Remove ticks.
- Set equal aspect ratio for x, y, and z (same as "axis equal").
- Use perspective rather than orthographic projection.
- Add righthand Gouraud lighting.

set(gcf, 'Color', 'w'); set(gca, 'XTick', [], 'YTick', [], 'ZTick', [], 'Box', 'on', ... 'DataAspectRatio', [1, 1, 1], 'Projection', 'perspective'); camlight right; lighting gouraud;

## Implicite surface function

Generate a 3D mesh and evaluate an implicite function f(x, y, z) = k.

[x, y, z] = meshgrid(linspace(-1.5, 1.5, 50)); f = (x.^4 + y.^4 + z.^4).^0.25; k = 0.5;

Draw a blue iso-surface with no edge-color and 75 % transparency into a new figure and set the default three-dimensional view.

figure(2); clf; p = patch(isosurface(f, k), ... 'FaceColor', 'blue', 'EdgeColor', 'none', 'FaceAlpha', 0.75); view(3);

Now adjust figure, axes and lighting like in the previous example.

set(gcf, 'Color', 'w'); set(gca, 'XTick', [], 'YTick', [], 'ZTick', [], 'Box', 'on', ... 'DataAspectRatio', [1, 1, 1], 'Projection', 'perspective'); camlight right; lighting gouraud;

Finally, to improve the rendering, compute normals for each surface patch.

isonormals(f, p);