File Exchange

image thumbnail

plane intersection

version 1.1 (1.94 KB) by

It computes the intersection of two planes in space.

12 Downloads

Updated

View License

% Inputs:
% N1: normal vector to Plane 1
% A1: any point that belongs to Plane 1
% N2: normal vector to Plane 2
% A2: any point that belongs to Plane 2

%Outputs:
% P is a point that lies on the interection straight line.
% N is the direction vector of the straight line
% check is an integer (0:Plane 1 and Plane 2 are parallel'
% 1:Plane 1 and Plane 2 coincide
% 2:Plane 1 and Plane 2 intersect)

% Example:
% Determine the intersection of these two planes:
% 2x - 5y + 3z = 12 and 3x + 4y - 3z = 6
% The first plane is represented by the normal vector N1=[2 -5 3]
% and any arbitrary point that lies on the plane, ex: A1=[0 0 4]
% The second plane is represented by the normal vector N2=[3 4 -3]
% and any arbitrary point that lies on the plane, ex: A2=[0 0 -2]
% [P,N,check]=plane_intersect([2 -5 3],[0 0 4],[3 4 -3],[0 0 -2]);

Comments and Ratings (6)

is there a way that i can reference you? nice job.

Determine the intersection of these two planes:
% 2x - 5y + 3z = 12 and 3x + 4y - 3z = 6
% The first plane is represented by the normal vector N1=[2 -5 3]
% and any arbitrary point that lies on the plane, ex: A1=[0 0 4]
% The second plane is represented by the normal vector N2=[3 4 -3]
% and any arbitrary point that lies on the plane, ex: A2=[0 0 -2]
% [P,N,check]=plane_intersect([2 -5 3],[0 0 4],[3 4 -3],[0 0 -2]);

phil

phil (view profile)

Instead of :

maxc=max(find(N==max(N)));

You should look for the max ABS value of the intersecting direction.

maxc=find(abs(N)==max(abs(N))));

You even mention this correctly in the comments:
"%first determine max abs coordinate of cross product"

Inserting these values will show the difference :
N1=[-0.0388 -0.10904 -0.99328];
A1=5*N1;
N2=[0 -1 0];
A2=[0 0 0]; %Plane at origin

Nasser Farhat

Thomas Pieper

Hello,

a possible general solution of this problem is as follows:

N=cross(N1,N2);
P=[N1;N2;N]\[dot(N1,A1);dot(N2,A2);0];

You don't have to handles 3 different cases. Checking for colinearity of the normal vectors is mandatory of course.

Best regards,

Thomas

Jos x@y.z

This certainly looks like a decent function. It has ample help and internal comments, but the author has to fix some problems with that:

- add a % to empty lines in the help text so that "help plane_intersect" will display all the help, and not only the input requirements.

- create a H1 line (first line of help) which is used by lookfor.

- you could give a warning when parallel planes are entered and no 3rd output is asked for ..

Look at other ML functions how to set up a help section properly. If these problems are fixed I am happy to look at the actual algorithms.

Updates

1.1

I have read some new commments and responded by changing the code.

MATLAB Release
MATLAB 7 (R14)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video