0

For context, the problem I am trying to solve here is within game development - The player can move in 3D space (in any direction), but when near a wall, the player should not be able to move toward that wall. Instead they should move along a vector parallel to the wall, in the same general direction as the initial input. This is trivial - I take the dot product of the input vector and the normal of the plane we hit. If the result is positive the input is valid, and if not, the input vector plus the normal multiplied by the dot product result gives a satisfactory result.

A problem arises when we have more than one wall (plane) nearby. If we simply repeat the previous algorithm successively for each wall, It's possible to get a vector which does point toward one or more planes. What I would like to do instead, is to find the range of vectors (if there are any) which satisfy all planes involved.

I'm able to visualize it as each successive plane cutting a hemisphere off the unit sphere, with whatever shape remains being the range of valid output vectors. However, I'm not sure how to go about it mathematically. Of course, even if I could solve the problem this way, I would also need to find a way to remap the input to the desired range.

Does anyone have an idea of how this can be done?

  • There is a mathematical question here, for sure, and it can be answered mathematically; that said, I think the abstract question might go better on the Game Dev Stack Exchange. – Steven Stadnicki Sep 24 '20 at 18:14
  • If I understand correctly, you want the set of vectors that have non-negative dot product with a given list of vectors (normals to the planes). It is straightforward to check if a given vector satisfies that. What do you want to do exactly if it does not? Produce the vector in the set closest to it? If so, you do not need to parametrize that set (and it is unclear how it would help even if you did). What you have is a standard quadratic optimization problem with linear inequality constraints. – Conifold Sep 24 '20 at 22:43
  • @Conifold You've got it exactly. I was also worried that having the set may not be the answer, but I was hoping it would get me closer to it. I appreciate you pointing me in the right direction, but I'm worried it may be a little over my head. Is there any particular part of that article that you think can help me or other resources I could look into? I'm not sure how to even express my problem (or what I'm solving for) in mathematical terms, so it's difficult to understand what in that article I could use to help the problem.

    Thanks again for the response!

    – Peter D Sep 25 '20 at 17:08
  • You have normal vectors $n_i$ and the target vector $v$. What you want is to minimize $|x-v|^2$ subject to the constraints $x\cdot n_i\geq0$. Linear Least Squares with Linear Inequality Constraints discusses the theory, in your case $A$ and $G$ are identity matrices, and $h=0$. Implementation in MATLAB is by lsqlin command, see also ALGLIB. – Conifold Sep 25 '20 at 19:56

0 Answers0