How to find out the cordinates of the intersection point of a line and a surface?

조회 수: 2 (최근 30일)
Hello
I need to find out weather a line that connect to points in a 3D situation have an intersection with a surface or not, and also report the intersection point for further steps.
Imagine I have two points A and B ( which needs to be connected) a surface z.
A : x= 0.5 y=-0.5 z=-1
B : x=-0.7 y=1 z=1.5
and the surface z is:
[x, y] = meshgrid(linspace(-1, 1));
z = y.^2 + 2*x;
"The above data are just as an example"
Thanks alot for any help on my question

채택된 답변

Matt J
Matt J 2019년 7월 30일
편집: Matt J 2019년 7월 30일
Plug the equation for the line into the equation for the surface and use fzero to find the root. This root will give the location of the intersection.
L=@(t) A+(B-A)*t; %line equation
S= @(xyz) xyz(3)-xyz(1).^2 -xyz(2).^2; %surface equation
t_intersection = fzero(@(t) S(L(t)) ,t0 )
  댓글 수: 1
Zarak kh
Zarak kh 2019년 7월 30일
Dear Matt
Thanks for your answer.
I just have some questions about your answer:
1- You use handle function "@", I have searched about it, is it correct to say this function help us not to define the varibale "t" for example for matlab?
2- Would you please explane surface equation? how you write your code like this from the original equation?
3- and I have to define a range for "t0" where the equation chnaged the sign, so what is the best way to do it?
Thanks again for your answer and help. it wsa very useful.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by