Intersection between a line and an interpolated surface

2 views (last 30 days)
Hello all,
How can I solve for points of intersection between a line and an interpolated curve (an interpolant)? I tried fsolve to solve F = 0 where F is defined by
F = [r(3) - surfacefun(r(1),r(2));
r(1) - r0(1) - r(4)*k(1);
r(2) - r0(2) - r(4)*k(2);
r(3) - r0(3) - r(4)*k(3)];
surfacefun is the interpolant obtained from TriScatteredInterp applied to the scattered data. r(1), r(2) and r(3) are the x, y and z coordinates, while r(4) is actually lambda in the vector equation of a line (r = a + lambda*k), and k(1), k(2) and k(3) are the components of the direction vector of the line.
One of the errors returned was that "Undefined function 'surfacefun' for input arguments of type 'double'."
So, how should I approach the problem of finding intersections between a line and a numerically interpolated surface?
Thank you very much in advance for your help :)

Accepted Answer

Matt J
Matt J on 27 Jan 2013
Edited: Matt J on 27 Jan 2013
Your approach seems okay. Make sure surfacefun exists though :-)
I assume the code you've shown is but one line in a file that implements F(lambda). Is surfacefun available in that workspace? How did you pass the surfacefun handle to F(lambda)?
  3 Comments
Cong Bang Huynh
Cong Bang Huynh on 27 Jan 2013
I see. I'll try FMINSEARCH. Regarding the previous error I realised I forgot to declare surfacefun as global. But now I'm facing another problem: basically I have a function [x,y,z] = intersection(r0,k) to calculate the intersection coordinates (x,y,z) of a line passing through a point r0 with direction k with the interpolated surface. Then within this function I use FSOLVE which calls intersectionfun which is where I store my system of equations to be solved, as shown above. However I am not sure if FSOLVE when calling intersectionfun is able to see r0 and k which are variables defined for [x,y,z] = intersection(r0,k).
I suspect that FMINSEARCH would incur the same problem too...
Thank you Matt for your help :)
Matt J
Matt J on 27 Jan 2013
Edited: Matt J on 29 Jan 2013
Since FSOLVE is called inside intersection() and since r0,k were passed as arguments to intersection(), then they all reside in the workspace of intersection() and should be able to see each other there.
As for intersectionfun(), the variables r0,k will only reach its workspace if you pass them to intersectionfun() as argument as well. See here for better ways of passing fixed parameters around than as global variables

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation 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!