Main Content

Tangent Plane and Normal Line of Implicit Surface

Since R2021b

This example shows how to find the tangent plane and the normal line of an implicit surface. This example uses symbolic matrix variables (with the symmatrix data type) for compact mathematical notation.

A surface can be defined implicitly, such as the sphere x2+y2+z2=R2. In general, an implicitly defined surface is expressed by the equation f(x,y,z)=k. This example finds the tangent plane and the normal line of a sphere with radius R=14.

Create a symbolic matrix variable r to represent the x,y,z coordinates. Define the spherical function as f(r)=rr.

clear; close all; clc
syms r [1 3] matrix
f = r*r.'
f = rrT

The implicit equation f(r)=14 represents a sphere. Convert the equation to the syms data type using symmatrix2sym. Plot the equation by using the fimplicit3 function.

feqn = symmatrix2sym(f == 14)
feqn = r1,12+r1,22+r1,32=14
fimplicit3(feqn)
axis equal
axis([-6 6 -6 6 -6 6])

Next, find the tangent plane and normal line at the point r0=x0,y0,z0.

Recall that the gradient vector of f is f(r)=fx(r),fy(r),fz(r). The equation for the tangent plane at the point r0 is then given by fx(r0)(x-x0)+fy(r0)(y-y0)+fz(r0)(z-z0)=0. In compact mathematical notation, the tangent plane equation can be written as f(r0)(r-r0)=0.

Find the gradient of f(r) using the gradient function. Note that the result is a 3-by-1 symbolic matrix variable.

fgrad = gradient(f,r)
fgrad = 2rT
size(fgrad)
ans = 1×2

     3     1

Define the equation for the tangent plane. Use the subs function to evaluate the gradient at the point r0=1,-2,3.

r0 = [-2,1,3];
fplane = (r-r0)*subs(fgrad,r,r0)
fplane = 

2-Σ1+rΣ1Twhere  Σ1=(-213)

Plot the point r0 using plot3, and plot the tangent plane using fimplicit3.

hold on
plot3(r0(1),r0(2),r0(3),'ro',MarkerSize = 10,MarkerFaceColor = 'r')
fimplicit3(symmatrix2sym(fplane == 0))

The equation for the normal line at the point r0 is given by n(t)=x0,y0,z0+tfx(r0),fy(r0),fz(r0). In compact mathematical notation, the equation can be written as n(t)=r0+tf(r0).

Define the equation for the normal line.

syms t
n = r0 + t*subs(fgrad,r,r0).'
n = 

Σ1+2tΣ1where  Σ1=(-213)

Convert the normal line equation to the syms data type using symmatrix2sym. Extract the parametric curves x(t), y(t), and z(t) for the normal line by indexing into n. Plot the normal line using fplot3.

n = symmatrix2sym(n)
n = (-4t-22t+16t+3)
fplot3(n(1),n(2),n(3),[0 1],'r->')