How I can check if planes are parallel to each other in 3d?

22 Ansichten (letzte 30 Tage)
Aknur am 5 Apr. 2023
Kommentiert: Aknur am 10 Apr. 2023
Dear all kindly ask how I can check if any of these six planes of cube are parallel to each other, and which planes are adjacent to each other
How I can check if planes are parallel to each other. I have cube 3*3*3 dimensions and there are planes.
My final goal is to check if one of my any point A(X0,Y0,Z0) lies in one of the plane and check if second point B(X1,Y1,Z1) lies in any of these planes. And at the end check if these two planes are parallel or adjusting to each other
planes(:,:,1) = [0 3 3; 0 0 3; 0 3 0; 0 0 0; 0 0 0];
planes(:,:,2) = [0 0 3; 3 0 3; 0 0 0; 3 0 0; 0 0 0];
planes(:,:,3) = [3 0 3; 3 3 3; 3 0 0; 3 3 0; 3 0 0];
planes(:,:,4) = [3 3 3; 0 3 3; 3 3 0; 0 3 0; 0 3 3];
planes(:,:,5) = [0 3 0; 3 3 0; 0 0 0; 3 0 0; 0 0 0];
planes(:,:,6) = [0 3 3; 3 3 3; 0 0 3; 3 0 3; 0 0 3];
location_plane = 6;
for j=1:6 % j is number of plane
j
plane = planes(:,:,j);
p0 = plane(1,:); %p0 is top left point of plane
p1 = plane(2,:); %p1 is top right point of plane
p2 = plane(3,:); %p2 is bottom left point of plane
p3 = plane(4,:); %p3 is bottom right point of plane
V0 = plane(5,:); %point on the plane
0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

John D'Errico am 5 Apr. 2023
Bearbeitet: John D'Errico am 5 Apr. 2023
planes(:,:,1) = [0 3 3; 0 0 3; 0 3 0; 0 0 0; 0 0 0];
planes(:,:,2) = [0 0 3; 3 0 3; 0 0 0; 3 0 0; 0 0 0];
planes(:,:,3) = [3 0 3; 3 3 3; 3 0 0; 3 3 0; 3 0 0];
planes(:,:,4) = [3 3 3; 0 3 3; 3 3 0; 0 3 0; 0 3 3];
planes(:,:,5) = [0 3 0; 3 3 0; 0 0 0; 3 0 0; 0 0 0];
planes(:,:,6) = [0 3 3; 3 3 3; 0 0 3; 3 0 3; 0 0 3];
6 different planes, represented by points in each plane. First, I'll verify that each set of 5 points you designated do indeed lie in a plane in R^3. (Hey you might have made a mistake.)
for i = 1:6
rank(planes(:,:,i) - planes(1,:,i))
end
ans = 2
ans = 2
ans = 2
ans = 2
ans = 2
ans = 2
Two planes are parallel if they have the same normal vector (Though you could multiply by -1.) So just compute the normal vectors to each plane.
Nullvecs = zeros(6,3);
for i = 1:6
nullvecs(:,i) = null(planes(:,:,i) - planes(1,:,i));
end
nullvecs
nullvecs = 3×6
1 0 1 0 0 0 0 -1 0 1 0 0 0 0 0 0 1 1
Now, look at those vectors. See that planes 1 and 3 have the same normal vectors, The signs of the normal vectors are the same. Planes 2 and 4 have a sign flip on the normal vectors. And planes 5 and 6 are also parallel. In the last case again, the normal vectors had the same signs. Could we identify those pairs automatically? Yes, of course. We can compute a corrrelation matrix, then look for elements of the correlation matrix that are exactly either 1 or -1. I'll put a small tolerance on that result.
C = abs(abs(corr(nullvecs) - eye(6)) - 1)<2*eps
C = 6×6 logical array
0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0
Note that I subtracted the identity matrix so we don't identify each vector as the same as itself.
[I,J] = find(C);
unique(sort([I,J],2),'rows')
ans = 3×2
1 3 2 4 5 6
So there were 3 pairs of parallel planes identified.
3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
John D'Errico am 6 Apr. 2023
I'm not at all positive what you mean by "<1 || >0".
There is a very good reason why I suggested using a test against a tiny number like 2*eps. When you work in floating point arithmetic, you should NEVER trust the least significant digits of a number. In the code I wrote...
planes(:,:,1) = [0 3 3; 0 0 3; 0 3 0; 0 0 0; 0 0 0];
planes(:,:,2) = [0 0 3; 3 0 3; 0 0 0; 3 0 0; 0 0 0];
planes(:,:,3) = [3 0 3; 3 3 3; 3 0 0; 3 3 0; 3 0 0];
planes(:,:,4) = [3 3 3; 0 3 3; 3 3 0; 0 3 0; 0 3 3];
planes(:,:,5) = [0 3 0; 3 3 0; 0 0 0; 3 0 0; 0 0 0];
planes(:,:,6) = [0 3 3; 3 3 3; 0 0 3; 3 0 3; 0 0 3];
Nullvecs = zeros(6,3);
for i = 1:6
nullvecs(:,i) = null(planes(:,:,i) - planes(1,:,i));
end
Now, compute the correlation matrix.
C = corr(nullvecs)
C = 6×6
1.0000 0.5000 1.0000 -0.5000 -0.5000 -0.5000 0.5000 1.0000 0.5000 -1.0000 0.5000 0.5000 1.0000 0.5000 1.0000 -0.5000 -0.5000 -0.5000 -0.5000 -1.0000 -0.5000 1.0000 -0.5000 -0.5000 -0.5000 0.5000 -0.5000 -0.5000 1.0000 1.0000 -0.5000 0.5000 -0.5000 -0.5000 1.0000 1.0000
Whenever you compute a matrix like that, don't trust that the numbers are EXACTLY 1, -1, 0.5 or -0.5. You need to use a tolerance. In fact, for example, C(1,2) looks like it is the number 1/2. But is it?
C(1,2) == 0.5
ans = logical
0
C(1,2) - 1/2
ans = 1.1102e-16
So you should never just test to see if a number is exactly 1, or exactly -1 for that matrix. You might be surprised. And that is why I used a tolerance.
As for saving the planes that are parallel, I could have written this instead:
parallelplanes = unique(sort([I,J],2),'rows');
to save the result into a variable.
Aknur am 10 Apr. 2023
May I ask one more question.
If I want to write ' if ((plane00==1 or plane00==3) and (plane01==1 or plane01==3)) then PhiBar = - (Phi0) is my code correct? Beause when I test it answer will only went through first statemenet (isequal(plane00, plane1) || isequal(plane00, plane3))
and if is true then give me answer, and did not check second condition
if (isequal(plane00, plane1) || isequal(plane00, plane3)) && ((isequal(plane01,plane1))||isequal(plane01,plane3))
fprintf('Planes are parallel1:');
ThetaBar = -(Theta0);
PhiBar = -(Phi0);
fprintf('ThetaBar: %f\n',ThetaBar);
fprintf('PhiBar: %f\n',PhiBar);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by