1

I've got a weird problem I've been trying to solve for a few days and I'm wondering if someone can help me out.

I have the following pieces of information:

  1. A standard PSR (position, scale, and rotation) matrix
  2. An origin point in 3D space defining the starting point of a ray
  3. A normal vector in 3D space relative to #2 that defines the ray direction
  4. A target point in 3D space

The ray origin and normal can be located anywhere in 3D space, but they must be parented to the matrix described in #1 (which itself can have any initial rotation and/or position within 3D space).

What I need to do is to calculate the rotation of the parent matrix to ensure that the ray origin and ray direction are aligned in such a way that the ray is guaranteed to intersect with the target point, preferably using an up vector for alignment if there is more than one possible solution.

Is there any straightforward way to calculate this?

EDIT:

Here's some pictures that show exactly what I'm trying to do. Apologies for the confusion!

In this picture, the orange cube represents the parent matrix (with no rotation), the yellow sphere represents the ray origin, and the blue arrow represents the ray direction. There's also an up vector and target point.

example_1

I need to rotate the matrix the ray origin and direction are parented to so that the ray points directly at the target object, with the ray origin falling on a 2D plane defined by the parent matrix position, target point, and up vector.

example_2

Here's a third example showing how the ray direction now points directly at the target point.

example_3

And finally here's another picture that roughly shows how the entire thing needs to be aligned with the up vector.

example_4

The primary problem here is that nothing is constant- the parent matrix offset (read: position) could change, or the ray origin and direction could change. The target point will also move around, as can the up vector- meaning that I need to figure out how to realign everything as the objects shift around in 3D space.

CMPXCHG8B
  • 497
  • 3
  • 15
  • How do you define the intersection with a *vector*? Do you mean another ray? Also there are infinitely many solutions because rotation around the ray's direction is an unconstrained degree of freedom – meowgoesthedog Oct 17 '18 at 15:28
  • Sorry, I meant target point. The parent matrix needs to be rotated so that the line formed by the ray intersects with the target point. – CMPXCHG8B Oct 17 '18 at 16:08
  • 1
    What you need is to calculate the rotation matrix from one vector to another; the answer to [this post](https://stackoverflow.com/questions/23166898/efficient-way-to-calculate-a-3x3-rotation-matrix-from-the-rotation-defined-by-tw) has linked a [useful article](http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q38). – meowgoesthedog Oct 17 '18 at 16:21
  • There are infinite rotations about the axis joining the parent origin and the target that satisfy the objectives. Is there any other constraints that are missing here. What is the role of the "up" vector? – John Alexiou Oct 22 '18 at 15:34
  • The up vector is to determine which way the ray origin should be pointing once everything is aligned. That was what I was trying to get across with the 4th example above- it's to avoid the exact situation you're describing by locking the ray origin to a plane defined by the parent origin, up vector, and target point. – CMPXCHG8B Oct 22 '18 at 15:50
  • I think is question might get a better answer over at [Mathematics.SE] – John Alexiou Oct 22 '18 at 18:15

0 Answers0