0

I need to project a SlimDX.Vector3 (X, Y and Z components) in a generic 2D plane (defined with SlimDX.Plane, with 3 Vector3). Please note that the plane is generic, and it is not the screen plane (otherwise, Vector3.Project could be used). I need to determine the Tranformation Matrix (or the Quaternion) from the 3D space to the 2D plane, but I don't know how. The origin of the plane can be whatever, e.g. the first point used to define the plane.

Anyone can help?

2 Answers2

1

I think what you want is the separation of the point to the plane (along the normal) which is given with

float h = Plane.DotNormal(plane, point);

Then subtract this amount along the plane normal from the point

Vector3 proj = point - h*plane.Normal;

The resulting point should lie on the plane.

John Alexiou
  • 28,472
  • 11
  • 77
  • 133
  • I already know that the point lies on that plane. Anyway, performing the operations you suggested, I get the same coordinates as before (I tried with a plane, defined by 3 nodes in the 3D space). – johnnyontheweb Aug 31 '15 at 13:13
  • So then you haven't explained very well what you are trying to do. I thought you wanted to project a 3D point onto a plane (which is what I replied to). – John Alexiou Aug 31 '15 at 14:05
0

Your question is still very unclear. However, I'm trying a shot in the dark.

Let's start by calculating a model transform for the plane (which transforms the plane lying in the x/y plane to its actual position). The transform you are looking for is the inverse of this matrix.

We can construct the matrix by finding the images of the principals. The origin is quite simple. As you specified, the origin should be mapped to the first point (v1). The z-axis is also easy. That's the plane's normal. Hence, the matrix is:

    /  .           .           .          . \
M = |  .           .           .          . |
    | p.Normal.X  p.Normal.Y  p.Normal.Z  0 |
    \ v1.X        v1.Y        v1.Z        1 /

Now comes the part where your description lacks information. We need a local x-axis on the plane. I assume that this axis is defined by the second vector:

Vector3 x = Vector3.Normalize(v2 - v1);

Then, the resulting local y-axis is:

Vector3 y = Vector3.Normalize(Vector3.Cross(p.Normal, x));

And:

    / x.X         x.Y         x.Z         0 \
M = | y.X         y.Y         y.Z         0 |
    | p.Normal.X  p.Normal.Y  p.Normal.Z  0 |
    \ v1.X        v1.Y        v1.Z        1 /

As mentioned, you need this matrix' inverse. Hence:

       /  x.X     y.X     p.Normal.X  0 \
M^-1 = |  x.Y     y.Y     p.Normal.Y  0 |
       |  x.Z     y.Z     p.Normal.Z  0 |
       \ -v1.X   -v1.Y      -v1.Z     1 /

More compactly, since you don't need the third and fourth dimensions (although this might not be the most convenient representation for SDX):

       /  x.X     y.X  \
   T = |  x.Y     y.Y  |
       |  x.Z     y.Z  |
       \ -v1.X   -v1.Y /
Nico Schertler
  • 32,049
  • 4
  • 39
  • 70