Thread Subject: plot point on 3d surface

Subject: plot point on 3d surface

From: Sirisha

Date: 9 Feb, 2010 11:38:02

Message: 1 of 1

Dear All,

I need help plotting a point on a 3d surface. I have the surface displayed in an axes using surf. I am then using a mouse click and obtaining the 'currentpoint' from the axes handle. I am able to obtain the coordinates of the point by finding the intersection of the selection ray with the existing plane. Then I use hold on and plot3 to plot the point on the 3d axes. When I use the rotate3d tool on this axes, the plotted point does not remain in the same position within the surface. Its location with respect to the surface keeps moving. How can I prevent this? I need to select and display points on the surface rather than in the axes. Please find my code below.

% Extract data from current 3d object within axes
        obj = get(handles.Oblique, 'Children');
        for i = 1:length(obj)
            if isequal(get(obj(i),'Type'),'surface')
                xd = get(obj, 'xdata');
                yd = get(obj, 'ydata');
                zd = get(obj, 'zdata');
            end
        end
        
        X(:,1) = xd(:,1);
        X(:,2) = yd(:,1);
        X(:,3) = zd(:,1);
        
        % Obtain the normal vector to the slice
        [c,s] = princomp(X);
        n = c(:,3);
        
        % Obtain the center of the slice
        C = handles.Center;
        
        % Obtain the plane equation of the current slice
        syms x y z; % declare x y z as symbolic variables
        A = [x,y,z];
        planefunc = dot(n, A-C);
        
        % Obtain the last clicked point from the axes handle
        P = get(handles.Oblique, 'currentpoint');
        P1 = P(1,:);
        P2 = P(2,:);
        
        % Obtain the line equation through P1 and P2
        syms t
        linefunc = P1 + t.*(P2-P1);
        
        % Find the intersection of the selection ray with the slice
        newfunc = subs(planefunc, A, linefunc);
        t0 = eval(solve(newfunc));
        I = subs(linefunc, t, t0);
        
        % Plot the point
        c_value = [1 0 0];
        hold on, plot3(I(1),I(2),I(3),'Color',c_value,'MarkerSize',4);

I have checked the type of 'I', and it is double and the values are within the axes limits. Any help in identifying the problem or using a different approach will be highly appreciated. Thank you!

-S

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
3d Sirisha 9 Feb, 2010 06:39:05
surface Sirisha 9 Feb, 2010 06:39:05
rssFeed for this Thread

Contact us at files@mathworks.com