1
votes

I'm using the surfnorm matlab function to calculate the surface normal. When I use it as: surfnorm(pcloud(:,:,1),pcloud(:,:,2),pcloud(:,:,3)); the figure of the surface normal appears but the normal values are not saved. So I used :[Nx,Ny,Nz]=surfnorm(pcloud(:,:,1),pcloud(:,:,2),pcloud(:,:,3)); but not its saving the normal values in [Nx,Ny,Nz] but not displaying the normal figure. So how to make both?

1

1 Answers

1
votes

According to the documentation the two actions you want to perform simultaneously appear to be mutually exclusive:

 [Nx,Ny,Nz] = SURFNORM(X,Y,Z) returns the components of the 3-D 
 surface normal for the surface with components (X,Y,Z).  The 
 normal is normalized to length 1.

 [Nx,Ny,Nz] = SURFNORM(Z) returns the surface normal components
 for the surface Z.

 Without lefthand arguments, SURFNORM(X,Y,Z) or SURFNORM(Z) 
 plots the surface with the normals emanating from it.

 SURFNORM(AX,...) plots into AX instead of GCA.

However, once created you can retrieve the normal vector data from the surface normal figure, as follows:

h=figure;
surfnorm(pcloud(:,:,1),pcloud(:,:,2),pcloud(:,:,3));
axesObjs = get(h, 'Children');
dataObjs = get(axesObjs, 'Children'); 
[Nx,Ny,Nz] = deal(get(dataObjs(1), 'XData').', get(dataObjs(1), 'YData').', get(dataObjs(1), 'ZData').');

It seems convoluted but if it's computational expense you are seeking to avoid this is probably the best way to do this.

Edit:

(1) You can substitute h=figure with a call to figure followed by h=gcf.

(2) My interpretation of the Nx, Ny, Nz vectors is that contain coordinates for the position and direction (not necessarily normalized) of the vectors drawn by surfnorm, as well as additional NaN values, so if you print out [Nx,Ny,Nz] you should see something like:

         0         0   -1.0000   <-- position of origin
         0         0   -1.0000   <-- direction of vector
       NaN       NaN       NaN   <-- nonsense
   -0.5878         0   -0.8090
   -0.7036   -0.0344   -0.9684
       NaN       NaN       NaN
   -0.9511         0   -0.3090
   -1.1341   -0.0543   -0.3685
       NaN       NaN       NaN
   -0.9511         0    0.3090
   -1.1341   -0.0543    0.3685
       NaN       NaN       NaN
    ....