How to find Intersection point of plane and vector/line in 3d

조회 수: 23 (최근 30일)
Aknur
Aknur 2023년 2월 23일
댓글: Aknur 2023년 5월 2일
Hello! Could you please help me why my fucntion does not calculate intersection point I. It gaves me my initial X0, Y0, Z0 coordinate
I used this example
[I ] = planeLocation6(1.5, 3.3371, 0.1820)
function [ I ] = planeLocation6(XBar, YBar, ZBar)
X0 = 1.5;
Y0 = 1.5;
Z0 = 3.0;
Theta0 = 30;
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==location_plane
plane = planes(:,:,j);
p0 = plane(1,:);
p1 = plane(2,:);
p2 = plane(3,:);
p3 = plane(4,:);
V0 = plane(5,:);
Ri = [X0 Y0 Z0];
Rr = [XBar YBar ZBar];
u = Rr-Ri;
w=Ri-V0;
A = p0-p2;
B = p0-p3;
n=cross(A,B); % normal vector of the Plane
u = Rr-Ri;
w=Ri-V0;
D=dot(n,u);
N=-dot(n,w);
sI = N / D;
I = Ri+ sI.*u;
disp(I);
end
Thank you in advance, BR Aknur
  댓글 수: 3
Rik
Rik 2023년 2월 28일
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
Aknur
Aknur 2023년 5월 2일
Hello, dear @Rik I have removed because in general my code was not correct and it can lead to misunderstanding for other viewers. As I used this function with mistakes https://www.mathworks.com/matlabcentral/fileexchange/103835-plane-and-line-intersection

댓글을 달려면 로그인하십시오.

채택된 답변

Bhavana Ravirala
Bhavana Ravirala 2023년 2월 23일
Hi Ankur,
I understand that you are unable to calculate the intersection point ‘I’.
When I try to run the code at my end, I am getting a value of ‘I’ as Infinity and not the initial values.
You are not getting the intersection point because the dot product of ‘n’ and ‘u’ is zero with the inputs which you have provided to the function. Try giving different inputs to the function such that ‘D’ does not become zero and ‘I’ does not be Infinity.
Hope this helps!!
  댓글 수: 1
Aknur
Aknur 2023년 2월 27일
Dear, @Bhavana Ravirala thank you for your feedback. Yes D become zero, Can I ask if I want extract special data in array which will met the requirements of if statement x > 0 & x < 3 & y > 0 & y < 3 & z > 0 & z < 3 how I can do it? I used isnan and isinf to clean data and take out Nan and Infinite values. Now I'm thining how to take only that I which will meet the requirement mentioned above.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by