2

I have $p (>2)$ points $x_1, x_2,\ldots,x_p \in \mathbb{R}^N$ and $y_1,y_2 \in \mathbb{R}^N$. How to test whether the line segment connecting $y_1,y_2$ pass through the cluster formed by the $p$ points $x_1,x_2,\ldots,x_p$?

Soo
  • 131
  • Do you mean the points $x_i$ must lie on the line segment? If not, how do you define "pass through"? – Jens Dec 29 '16 at 18:24
  • @Jens $x_i$ need not lie on the line segment. We may define a cluster first. One of the simplest to form a cluster will be to define it as a sphere with centre as the mean of the $p$ points and radius as the distance from the centre to the farthest point among the $p$ points. Now, my question is how to check whether the line segment connecting $y_1,y_2$ pass though this cluster! – Soo Dec 29 '16 at 18:53
  • It's still not clear to me what counts as "pass through". Is it enough if just one point of the line segment (e.g. an end point) is within the sphere? – Jens Dec 29 '16 at 21:18
  • @Jens. Yes; even if only one point of the line segment touches the sphere, it can be considered a "pass through". – Soo Dec 30 '16 at 05:04

1 Answers1

1

Given your clarifications, a procedure for $N=3$ would be:

  1. Find the center $y_0$ and radius $R$ of the cluster sphere in the manner you describe.

  2. Check if one or both endpoints of the line segment is within the sphere. I.e. check if $|y_1-y_0|\le R$ or $|y_2-y_0|\le R$. If this is the case, you have a "pass through". Otherwise both endpoints are outside the sphere and furher checks are needed.

  3. Check if the shortest distance from $y_0$ to the line through $y_1$ and $y_2$ is $\le R$. This distance is given by the formula (see here): $$d=\frac{|(y_0-y_1)\times (y_0-y_2)|}{|y_2-y_1|}$$

    If $d \le R$ then you may have a "pass through", otherwise you don't.

  4. Though the line through $y_1$ and $y_2$ passes through the sphere it may be that no part of the line segment connecting $y_1$ and $y_2$ is within the sphere. It is therefore necessary to check if the point on the line with the shortest distance, calculated above, is on the line segment. This can be done using the formula (see link above): $$t=-\frac{(y_1-y_0) \cdot (y_2-y_1)}{|y_2-y_1|^2}$$

    where $t$ is used in the parameterization of the line through $y_1$ and $y_2$. If $0 \lt t \lt 1$ then you have a pass through, otherwise you don't.

Hope this helps.

Jens
  • 5,686
  • 2
  • 20
  • 38
  • Thanks for your great answer. But you have mentioned that the method is for N=3. Do you see any restriction for extending the same method for N>3? – Soo Jan 01 '17 at 14:15
  • It may be that it can be generalized, but things can get hairy in higher dimensions. The cross product, for example, is only defined for some dimensions: http://math.stackexchange.com/questions/424482/cross-product-in-mathbb-rn . If you nevertheless found my answer useful, please give it a vote up. – Jens Jan 01 '17 at 17:32