tags:

views:

374

answers:

1

Hi everyone,

I consider myself a beginner in MATLAB so bear with me if the answer to my question is an obvious one.

Phi=0:pi/100:2*pi;
Theta=0:pi/100:2*pi;
[PHI,THETA]=meshgrid(Phi,Theta);

R=(1 + cos(PHI).*cos(PHI)).*(1 + cos(THETA).*cos(THETA));
[X,Y,Z]=sph2cart(THETA,PHI,R);
surf(X,Y,Z); %display

hold on;

x1=-4:.1:4;
[X1,Y1] = meshgrid(x1);
a=1.8; b=0; c=3; d=0;
Z1=(d- a * X1 - b * Y1)/c;
shading flat;
surf(X1,Y1,Z1);

I have written this code which plots a 3d cartesian plot of a plane intersecting a peanut shaped object at an angle.

I need to get the intersection of these on 2D (going to be the outline of a peanut, but a bit skewed since the intersection happens at an angle), but don't know how.

Thanks

+2  A: 

If you just want to get the intersecting curve, you can plug the coordinates of your surface into the equation of the plane, and find the points that lie nearly in the plane.

%# find the distance of `X,Y,Z` to the plane
dist2plane = a*X(:)+b*Y(:)+c*Z(:)-d;

%# find index of the small distances
lowDistIdx = abs(dist2plane)<0.05; %# or some other distance threshold

%# plot the result - note that it's not quite a peanut
figure,plot3(X(lowDistIdx),Y(lowDistIdx),Z(lowDistIdx),'.')

If you want to have these coordinates in 2D, you do need to make a coordinate transformation.

Jonas

related questions