Hello! How to define on which plane lies a given point with coordinates? I have coordinates of plane and normal
Ältere Kommentare anzeigen
Hello everyone. I undertsand it might be very simple question, but I could not solve it. I have point for example A(1.5, 1.5, 3.0) and i have 6 planes of cube and I need to determine on which plane lies this point. I found normal for each plane and need to find for which of these planes ( number of plane) rely A.
Thank you so much in advance for your time and consideration . More appreciate help and any advice.
X0 = 1.5;
Y0 = 1.5;
Z0 = 3.0;
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
% Pi is initial start point on the ray
Pi = [X0 Y0 Z0]; %initial start point
%Ri = [XBar YBar ZBar]; %direction vector with unit length
A = p0-p2; %calculate A and B then
B = p0-p3; %then to calculate Normal of each plane
n=cross(A,B); % Normal for each Plane
n
Akzeptierte Antwort
Weitere Antworten (1)
Davide Masiello
am 6 Apr. 2023
Bearbeitet: Davide Masiello
am 6 Apr. 2023
Four points can be verified to belong on the same plane if the determinant of the matrix

is equal to zero.
I'd translate that into code in the following way.
x0 = 1.5;
y0 = 1.5;
z0 = 3;
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];
for j = 1:6
x(j,:) = planes(1:3,1,j);
y(j,:) = planes(1:3,2,j);
z(j,:) = planes(1:3,3,j);
end
for j = 1:6
M = [x(j,:),x0;y(j,:),y0;z(j,:),z0;ones(1,4)];
if det(M) == 0
fprintf('The point belongs to face %d.\n',j)
break
end
end
Examples with other points
x0 = 1.5;
y0 = 3;
z0 = 1;
for j = 1:6
M = [x(j,:),x0;y(j,:),y0;z(j,:),z0;ones(1,4)];
if det(M) == 0
fprintf('The point belongs to face %d.\n',j)
break
end
end
x0 = 1.5;
y0 = 0;
z0 = 2;
for j = 1:6
M = [x(j,:),x0;y(j,:),y0;z(j,:),z0;ones(1,4)];
if det(M) == 0
fprintf('The point belongs to face %d.\n',j)
break
end
end
Only thing, for edges 2 answers would be correct, but this code will output only the first of the 2 faces the point belongs to.
5 Kommentare
John D'Errico
am 6 Apr. 2023
Bearbeitet: John D'Errico
am 6 Apr. 2023
UGH! Please don't teach people to use a determinant to test for this! Using a determinant is essentially NEVER a good thing to do.
And testing for ANY number to be zero in floating point arithmetic is an insane thing to do!!!!!!!!! I'm sorry, but this is just the wrong advice to offer. Determinants are thigns we see in classes, usually where beginnign linear algebra is taught. They are neat things to teach a student, or so I assume. It is a nice easy ttest to show a student to see if a matrix is singular. How could that be a bad idea? The problem is, when a student computes the determinant of an entirely integer matrix, they get an integer result. But computers use floating point arithmetic, not integer arithmetic. And they don't use the same method you used as a student to compute that determinant. The result is, when you compute the determant of even entirely integer matrix, the result will not even be an integer. For exmple:
format long g
A = magic(4) %Purely integer
rank(A) % and a singular matrix, so det should be zero, right?
det(A)
det(A) == 0
So here, A is an entirely integer matrix, that is known to be singular (as a even order magic mattrix.) It must have a zero determinant, right? NOPE. Not exactly zero.
Worse, determinants don't cale well at all. AN identityy matrix is NEVER singular, right? ANd any multiple of an identity matrix is just as well condeitioned, right?
E = eye(10);
det(E)
det(E*1000)
det(E/1000)
Is E/1000 singular? That sure seems like a small number. In fact, if E was much larger, the determinant would underflow, and det would tell you the determinant is EXACTLY zero.
Teachers taught you to use determaninats, because their teachers taught them that. They do it because their books show the use of determinants. And because your teachers know only what they have been taught. But that does not make the use of determinants to be a good thing. And your teachers were wrong.
Yes, it is arguably ok to teach about determinants, as everybody will see them eventually, but what they needed to do was to teach another lesson, why you should NOT be using them!!!!!!
SO PLEASE DON"T KEEP THE CHAIN UNBROKEN. LEARN NOT TO TEACH STUDENTS TO DO SOMETHING THAT IS JUST A BAD IDEA. If you go on teaching the same things, then yet another student will learn the wrong lessons, and so they will learn to teach their students one day to use determinants. And that would be a pity.
Perhaps the worst thing is, you never needed to use a determinant at all for this!!!!!!
Davide Masiello
am 6 Apr. 2023
Hi @John D'Errico, thanks for the good advice. I guess I didn't think about the more profound numerical implications of using a determinat. I'll keep that in mind for the future :)
Aknur
am 10 Apr. 2023
Davide Masiello
am 11 Apr. 2023
@Aknur please do consider @John D'Errico's comments about the limitations of using determinants and equality to zero.
Aknur
am 12 Apr. 2023
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!