MATLAB: Creating a plane normal to an ellipsoid

graphics

I need to plot a plane normal to a specified point on an ellipsoid and am having issues doing so. I am currently able to plot a line normal, but have not been able to figure out how to create the plane. The ellipsoid is defined as below and the matrices Rc_matrix and N_matrix define points on the ellipsoid touching the plane and the planar normal vector, respectively.
n1=6;
xr=0.05;
yr=0.05;
zr=0.05;
N<=35
[X,Y,Z] = ellipsoid(obst_pos(1,1),obst_pos(2,1),obst_pos(3,1),xr,yr,zr);
surf(X,Y,Z)
hold on
for i1=1:N
plot3(Rc_matrix(n1*i1-5),Rc_matrix(n1*i1-4),Rc_matrix(n1*i1-3),'ro'); % plots point on plane normal to ellipsoid
q = [-N_matrix(i1, n1*i1-5);N_matrix(i1, n1*i1-4);N_matrix(n1*i1-3)]/5;
plot3([Rc_matrix(n1*i1-5)-q(2),Rc_matrix(n1*i1-5)+q(2)],[Rc_matrix(n1*i1-4)-q(1),Rc_matrix(n1*i1-4)+ q(1)],[Rc_matrix(n1*i1-3)-q(3),Rc_matrix(n1*i1-3)+q(3)],'r-')
end

Best Answer

Matlab’s ‘ellipsoid’ function,
[x,y,z] = ellipsoid(xc,yc,zc,xr,yr,zr)
creates an ellipsoid whose equation is:
f(x,y,z) = (x-xc)^2/xr^2 + (y-yc)^2/yr^2 + (z-zc)^2/zr^2 = 1
If (x0,y0,z0) is an arbitrary point on the ellipsoid, the normal to the ellipsoid surface at that point will have directional values proportional to the three partial derivatives of f(x,y,z) at that point:
2*(x0-xc)/xr^2, 2*(y0-yc)/yr^2, and 2*(z0-zc)/zr^2
Hence the equation of your plane can be expressed as:
(x0-xc)/xr^2*(x-x0) + (y0-yc)/yr^2*(y-y0) + (z0-zc)/zr^2*(z-z0) = 0
for an arbitrary point (x,y,z) on the plane at the designated point.
Note: I have assumed here that where you said a "plane normal" you actually meant a plane "tangent" to the surface of the ellipsoid at the designated point.