2
$\begingroup$

My background:
I have taken an introductory class or two in linear algebra at university, but it was a few years ago and I have not practiced it since. My terminology might be off, but I believe my text should be clear enoungh for everyone to understand.

Problem:
I am trying to build a 3-dimensional controller for a game and have run into an issue that I cannot solve. I need to find a 3-dimensional direction vector to use for moving an object along a plane, parallel to the plane. The directional vector should be based on a 2-dimensional input vector along the x- and z-axis, in combination with the rotation (any / all of the three axes) of the plane.

I think the easiest way for me to explain the problem that needs to be solved is to try to illustrate it using two examples.

Assumptions:
Left-handed coordinate system. We have a sphere with a radius of 0.5 with its center located at (0, 0.5, 0). I guess we can consider the center of the sphere the only thing of importance, but maybe a sphere can help build a visual image. The input vector used to translate the sphere with in both examples below is (1, 0, 1)

Examples:

  1. There is a xz-plane located at y = 0, so the sphere is in contact with the surface of the plane. After moving the sphere along the input vector, the sphere will be located at (0, 0.5, 0) + (1, 0, 1) = (1, 0.5, 1)
  2. The plane from example 1 has been rotated 89 degress around the z-axis and moved ~0.5 on the x-axis (not using 90 degrees rotation and exact movement since it would make it a bit harder to illustrate why the sphere should be moved the way I want it to move). The sphere is still in contact with the surface of the plane, but from the side. If the sphere were to be moved using the input vector it would move through the plane, but I want the sphere to move parallel to the plane. I want to … rotate? the input vector somehow. The final position of the sphere should be roughly (0.05, 0.95, 1). The location of the sphere after the movement should be the same as if we were to rotate the final location of the sphere from example 1 around the world z-axis the same number of degrees as the plane is rotated around the z-axis in this example.

Available data:
The data available is the location of the sphere, the input direction vector and the normal of the plane. Is this information enough to be able to solve the problem, and if so, how? If not, what other data is required?

  • 0
    Unless you are forced to that LH coordinate system, I'd advise switching to a RH one. You may find yourself regularly running into things that don't work as expected, because the formulas you used were intended for RH systems and require sign changes to adapt them to LH.2017-02-25
  • 0
    I don't get this: You say that the only information about the plane you have is it's normal, but in your description, you say it also moves $\sim 0.5$ along the $x$-axis. How can you move the plane when the only thing you know about it is the normal vector? The normal vector alone can only define planes through the origin. To have planes off the origin, you also need at least one more value (usually the distance $d$ from the origin to the plane, as then the plane equation is $\vec n \cdot \vec r = d$, where $\vec r$ are the points on the plane.).2017-02-26
  • 0
    @PaulSinclair Both examples are supposed to be... "starting scenarios", not something we do, but that we're given. Think a ball on a flat field. You kick it so that it moves straight ahead 1 meter and to the right 1 meter. Now compare the flat field scenario to one where you're facing a slope (same flat field rotated so that it is facing you). You're still trying to kick the ball straight ahead 1 meter and to the right 1 meter, to shoot the ball "through" the slope. In this scenario we want the ball to move up the slope 1 meter and to the right 1 meter. If that makes sense.2017-02-26
  • 0
    So you are not transforming the sphere and plane, but really are transforming the direction *and* distance from which they are viewed, a.k.a the camera location and orientation?2017-02-26
  • 0
    @PaulSinclair The sphere is transformed, the plane is not. The plane is static geometry in a game world, the ground immediately below the sphere. The sphere is an object the player is supposed to move along the ground.2017-02-26
  • 0
    The transformation you are asking about is not moving the ball along the ground. That is trivial. It is about transforming the *camera* - the view that the user is provided. The same transformation in what the user sees applies to both ground and sphere. Instead of trying to change the direction of the ground and the direction the sphere rolls on it, leave them alone and transform the whole thing with the same transformation when determining what the camera sees. How the view of the sphere changes is the same as how the view of the ground changes.2017-02-26
  • 0
    @PaulSinclair I am either not clear enough in explaining the problem or I am lacking too much 3D math skills to understand your responses.2017-02-26

1 Answers 1

0

Okay - I get now that you talking about changing the ground. But still this princicple applies: the same transformation that you applied to the ground is the transformation that applies to the ball.

You rotated the plane. I don't know how you have accomplished that rotation in your program, but mathematically it is expressed as a matrix $M$ that satisfies $M^TM = I$, the identity matrix (where $M^T$ is the transpose of $M$). If $\bf n$ is the normal vector to the original plane, then $M\bf n$ is the normal vector to the rotated plane.

You also said you moved the plane (in the example, along the $x$-axis). This means that the new plane no longer passes through the origin (at least in your example, the original point did). This is a translation, but we need to be careful which translation we use. Suppose the new plane must pass through some point $\bf p$. In your example you indicated that it passes through $(\sim 0.5, 0, 0)$. You can use that to be the point $\bf p$. Since the normal vector is $M\bf n$ and it passed through $\bf p$, a point $\bf r$ is on the new plane if $$(M{\bf n})^T{\bf r} = {\bf n}^TM^T{\bf r} = d$$ where $d = {\bf n}^TM^T\bf p$. The translation vector we need is ${\bf b} = dM\bf n$, which is the closest point on the new plane to the origin.

So the tranformation to the original plane ${\bf n}^T{\bf r} = 0$ to get the new plane ${\bf n}^TM^T{\bf r} = d$ is to rotate by $M$, then add the translation vector $b$:

$$ {\bf r} \mapsto M{\bf r} + \bf b$$

(In case you don't know, $\mapsto$ means "maps to". I.e., the original value on the left is transformed into the value on the right.) This is the same transformation you need to apply to your sphere to get it's new location after the transformation. If $\bf c$ is the original center of the sphere, the transformed center will be $${\bf c} \mapsto M{\bf c} + \bf b$$

Let $\bf v$ be the "input direction vector" of the horizontal ball movement. Since $\bf v$ is a direction, not a point, it does not translate. So the new direction vector that the ball will travel up the sloped ground will be given by $${\bf v} \mapsto M\bf v$$

So the inputs you need to solve your problem are the rotation vector $M$, and a point $\bf p$ that the new plane passes through. If you have these, then you can use them to transform the ground plane, the sphere's position, and the direction of movement, all three.

  • 0
    Exhaustive response, I appreciate it. I do not have access to M though (as far as I know). The only thing we know about the plane is the normal and one point that lies in the plane (forgot to mention this in the original post). The plane can be one of the surfaces of a 3D computer object, and I don't think we have access to any individual data about each particular surface (plane). Based on the last sentence in your post I'm still unsure if you believe the plane should be moved or not, of it you simply mentioned that we *can* move it with the input you mentioned in the last paragraph.2017-02-26
  • 0
    We have access to the point **p**. Can we create the rotation vector _M_ from the normal of the surface?2017-02-26
  • 0
    You cannot completely determine $M$ from the normal vector, because $M$ can also rotate things around that vector. So you need at least one other referent to completely determine $M$. But the remaining information needed to determine $M$ is probably implicit in your system, so you are not recognizing it. For example, if there is a definite direction of "right" both for the flat and inclined ground. That conjunction along with the normal vector completely defines $M$2017-02-26