1

I have a plane defined by a normal vector and another normalalised direction vector that is moving along that plane, both in 3D space.

I'm trying to figure out how to project that normal direction 3D vector onto the plane such that it ends up being a 2D vector with x/y coordinates.

meds
  • 21,699
  • 37
  • 163
  • 314
  • [This wikipedia page](https://en.wikipedia.org/wiki/3D_projection) has all the math to do it, it is going to boil down to some matrix math where the values filled in represent the "camera" that is "looking" at the 3D object. – Scott Chamberlain Jun 29 '16 at 13:42
  • http://stackoverflow.com/questions/23472048/projecting-3d-points-to-2d-plane Might help. Good luck! – Olian04 Jun 29 '16 at 14:48
  • A 2D vector with x/y coordinates? Relative to what axes? – Beta Jun 29 '16 at 21:31

2 Answers2

2

It sounds like you need to find the angle between the direction vector and the plane. The size of the projection is going to scale with the cosine of that angle. Since the normal vector of the plane is perpendicular, I think you can find the sine between the normal vector and your direction vector.

The angle between the two vectors is given by the dot product of the vectors over the magnitudes multiplied together. That gives us our theta. Take the sin of theta, and we have the scaling factor (I'll call it s)

Next, you need to define unit size vectors on the plane to project onto. It's probably easiest to do this by setting one of the unit vectors in the direction of the projection to move forward...

If you set the unit vector in the direction of the projection, then you know the length of the projection in that unit space by using the scaling factor and multiplying by the length of the vector.

After that, with the unit vector, multiply in the length and find your vector relative to your normally defined xyz axis.

I hope this helps.

Michael Smith
  • 474
  • 4
  • 11
  • If that's not clear, please let me know. I'm not huge on c# but I could probably give you an example if you can show me what you've done so far. – Michael Smith Jul 01 '16 at 03:20
1

Try something like this. I wrote a paper on this exact method a while ago and can provide you with a copy if you would like.

 PointF Transform32(Point3 P)
    {
        float pX = (float)(((V.J * sxy) - V.I * cxy) * zoom);
        float pY = (float)(((V.K * cz) - (V.I * sxy * sz) - (V.J * sz * cxy)));
        return new PointF(Origin.X + pX, Origin.Y - pY);
    }

cxy is the cosine of the x-y camera angle, measured in radians from the positive x-axis on the xy plane. sxy is the sine of the x-y camera angle. cz is the cosine of the z camera angle, measured in radians from the x-y plane (so the angle is zero if the camera rests on that plane). sz is the sine of the z camera angle.

Alternatively:

        Vector3 V = new Vector3(P.X, P.Y, P.Z);
        Vector3 R = Operator.Project(V, View);
        Vector3 Q = V - R;
        Vector3 A = Operator.Cross(View, zA);
        Vector3 B = Operator.Cross(A, View);
        int pY = (int)(Operator.Dot(Q, B) / B.GetMagnitude());
        int pX = (int)(Operator.Dot(Q, A) / A.GetMagnitude());

pY and pX should be your coordinates. Here, vector V is the position vector of the point in question, R is the projection of that vector onto your viewing vector, Q is the component of V orthogonal to the viewing Vector, A is an artificial X-axis formed by the cross-product of the viewing vector with the vector (0,0,1), and B is an artificial Y-axis formed by the cross product of A and (0,0,1).

It sounds like what you're looking for is something like a simple rendering engine, similar to this, which used the above formulae:Mathematical surface

Hope this helps.

wvn
  • 624
  • 5
  • 12