Among all intersection points between a ray defined by a point $M$ and a vector and a surface, find which one is closest to $M$?

52 Views Asked by At

Suppose I have a ray in 3d space with an origin at $(x_0, y_0, z_0)$ and direction $(a, b, c)$. This can be represented with the following equation

$\frac{x-x_0}{a} = \frac{y-y_0}{b} = \frac{z-z_0}{c}$

And suppose I have another function in 3d space,

$y=sin(x)+cos(z)$

Assuming the intersection points between the straight line and the surface, how do I find the point (or a close approximation) closest to $(x_0, y_0, z_0)$ that these two entities intersect?

My understanding is I can rework the ray into the following:

$x = \frac{a}{b}(y-y_0)+x_0$

$z = \frac{c}{b}(y-y_0)+z_0$

Then plug those equations for x and z into the sinusoidal function,

$y = sin(\frac{a}{b}(y-y_0)+x_0) + cos(\frac{c}{b}(y-y_0)+z_0)$

Rearrange it and set it equal to 0:

$f(y) = sin(\frac{a}{b}(y-y_0)+x_0) + cos(\frac{c}{b}(y-y_0)+z_0) - y $

And this new function $f(y)$ represents the distance of a point on the ray from the original sinusoidal function. So I'd want to find $y$ where $f(y) = 0$. Finally I could plug the discovered $y$ value back into the ray equations to get $x$ and $z$.

Am I on the right track, and how would I find $f(y)=0$?

1

There are 1 best solutions below

3
On BEST ANSWER

In general (see remark below), the straight line intersects the surface in a finite number of points.

enter image description here

Fig. 1 : A case with 3 intersection points. Point $(x_0;y_0;z_0)$ is figured as a little circle.

You are right when you look for solutions to your equation

$$y = \sin\left(\frac{a}{b}(y-y_0)+x_0\right) + \cos\left(\frac{c}{b}(y-y_0)+z_0\right)$$

But solutions $y_k $ of (1) w haven't to be plugged into parametric equations $x=... ; z=...$

It suffices

1) To consider them as abscissas on the straight line (variable $y$ can be thought as a sort of time variable). Then select, among all $y_k$s, the smallest one say $y_{min}$ in absolute value (avoiding in this way any real distance computation with formulas such as $\sqrt{(...)^2+(...)^2+(...)^2}$).

2) Then to plug this unique value of $y_{min}$ into the parametric equations in order to get $x_{min}$ and $z_{min}$.

Remark : In the exceptional case where the straight line is parallel to the $x-z$ plane :

  • either there is an infinite number of solutions (but the previous method can still be applied)

  • or there is no solution.