Intersect between functions. I am trying to get the intersection between three functions in 3D space.

2 views (last 30 days)
Hi, I have three functions (lines) in 3Dspace, for who I am trying to ge the intersect coordinates to. In other words: I am trying to get the intersection between:
z1 = x -2.*y + 5;
z2 = 2.*x -4.*y + 6;
z3 = -x -4.*y + 1
I hace checked everywhere but I do not seem to find a suitable answer.

Answers (1)

DGM
DGM on 22 Apr 2021
Edited: DGM on 22 Apr 2021
something like this:
syms x y z
e1 = (x -2.*y + 5)==z;
e2 = (2.*x -4.*y + 6)==z;
e3 = (-x -4.*y + 1)==z;
sol = vpasolve([e1 e2 e3])
Then just look at sol.x and sol.y. To demonstrate that they match, substitute the solution into the equations:
subs(e1,{x,y},[sol.x sol.y])
subs(e2,{x,y},[sol.x sol.y])
subs(e3,{x,y},[sol.x sol.y])
All three of which yield the same result:
4.0 == z
Which is the same as sol.z
In cases where the math is a lot more complicated and untuitive, I find that it helps to plot the surfaces first so that I can judge if the results from the solver even make sense. In this case, it's pretty simple. For example:
xx = linspace(-5,5,10);
yy = linspace(-5,5,10)';
s1 = xx -2.*yy + 5;
s2 = 2.*xx -4.*yy + 6;
s3 = -xx -4.*yy + 1;
a=1; % you can adjust transparency if it helps
h1 = surf(xx,yy,s1,'facealpha',a); hold on;
h2 = surf(xx,yy,s2,'facealpha',a);
h3 = surf(xx,yy,s3,'facealpha',a);
plot3(sol.x,sol.y,sol.z,'k*','markersize',20) % mark the solution location
shading flat
camlight
Like I said, these are all just planes, so the function behavior is simple and intuitive.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!