Search code examples
matlabplotmeshvertices

How to plot minimum and maximum values along z axis in matlab on the given 2D plot?


I am trying to plot two values min, and max along z axis in matlab. Basically, I am interested in the height of the head, hence I want minimum and maximum values on the plot. My approach was to first of all project the 3D mesh onto 2D plane, and then find minimum and maximum values along z axis (Vertices(:,3)). I found the minimum and maximum values, but I am not able to plot it. I know that it has something to do with [0,1] or [1,0] in plot functions. Please can somebody help. I have also added the figure showing which points I am interested in plotting.

Thanks in advance. enter image description here

    clc;
    clear all;

    mesh = readSurfaceMesh("Mesh.ply");

    Vertices=mesh.Vertices;
    Faces=mesh.Faces;


    min=min(Vertices(:,3));
    max=max(Vertices(:,3));


   figure;
   p=patch('Faces',Faces,'Vertices',Vertices);
   view(0,0); %Head Depth-Side View


   hold("on");

   plot([min, min], [0,1], 'ro', 'LineWidth', 2); % I am stuck here
   plot([max, max], [1, 0], 'go', 'LineWidth', 2); %I am stuck here

Solution

  • % You don't need the value of the min and max, you need their position
    % in the array
    [~, posmin] = min(Vertices(:,3));  
    [~, posMAX] = max(Vertices(:,3));
    % Also, Don't call a variable "min" or or "max", you won't be able to 
    % call the min() and max() functions anymore!
    
    figure;
    p=patch('Faces',Faces,'Vertices',Vertices);
    view(0,0); %Head Depth-Side View
    
    hold("on");
    
    % Plot the 3D max and min Vertices
    plot3(Vertices(posmin,1), Vertices(posmin,2), Vertices(posmin,3), 'ro');
    plot3(Vertices(posMAX,1), Vertices(posMAX,2), Vertices(posMAX,3), 'go');