# Find point in 3D plane

I have four points in a 3D space, example:

(0,0,1)
(1,0,1)
(1,0,2)
(0,0,2)

Then I have a 2D position on that square plane:

x = 0.5
y = 0.5

I need to find out the 3D space point of that position in the plane. In this example it's easy: (0.5,0,1.5) Because Y is zero. But imagine that Y was not zero (and not all the same), that the plane is leaning in some direction. How would I calculate the point in that case?

I imagine this should be a pretty easy thing to solve, but I can't figure it out. Please answer in programming terms and not in straight math terms.

Update with image: The gray plane (made out of two triangles) are the real one actually existing. I create a non-existing plane on top of this, the ABCD corners are exactly the same, however it doesn't slope. What I need to do is project a pixel (blue one in example) from the non-existing plane to the existing plane. It will be in the exact same location, except that it has gained a Y value from the sloping plane.

What I've been able to work out so far on my own is which one of the two triangles to use in the gray plane and the normal of triangle. I basically just need to figure out how I can project the pixel.

• Is the plane composed of 4 triangles or 2? What points compose a triangle together? Do we know this at runtime? Jul 3, 2014 at 22:15
• Each plane is composed of two triangles, in this example triangle A would be: (0,0,1) (1,0,2) (0,0,2) And triangle B: (0,0,1) (1,0,1) (1,0,2) We know this at runtime. Is that really needed to get the results? In my example (0.5,0.5) the point would touch both triangles (though I guess any one of them can be used in the calculation). Jul 3, 2014 at 22:31
• Yes this is needed. I can't find a good image but try this. Draw 2 quads composed of 2 triangles each. One that is composed of triangles 0,1,2 and 1,3,2 and one composed of 0,2,3 and 0,1,3. You'll see that there is a line where the height is the average between 1,2 for quad one and 2,3 for quad 2. (top-left is 0, top-right is 1, bottom-left is 2 and bottom-right is 3) Jul 3, 2014 at 22:43
• Sorry but I can't understand your answer. I also can't understand this one: math.stackexchange.com/questions/855840/find-point-in-3d-plane I got a calculation from a mathematician over there but I can't read it! Are you able to translate it into code? If not I totally understand. Sorry about not understanding your comment over here as well mate. Jul 3, 2014 at 23:11
• For the point (0.5, 0.5) in the plane, are you setting the 'origin' of these coordinates as the plane's bottom-left corner? Will you always make this assumption?
– Ryan
Jul 3, 2014 at 23:15

I'll assume that the A, B, C, D points really do lie on the same plane, i.e. that the two triangles form a single flat surface.

The first step is to calculate the plane equation for the plane. If you don't know what that is, don't worry too much about it. It's a set of four numbers that specify the plane's location and orientation in space. It can be found using any three of the four points on the plane:

float4 planeEqn;
planeEqn.xyz = cross(point1 - point0, point2 - point1);
planeEqn.w = -dot(planeEqn.xyz, point0);


Here, point0, point1, and point2 are any three of your original four points - it doesn't matter which ones, or in which order.

Now, you can solve the plane equation for y in terms of x and z. The plane equation in its native form looks like:

planeEqn.x * x + planeEqn.y * y + planeEqn.z * z + planeEqn.w = 0


where (x, y, z) is any point, and the equation is true (equals zero) only for points on the plane. With a bit of rearrangement you can solve for y:

y = (-planeEqn.x * x - planeEqn.z * z - planeEqn.w) / planeEqn.y;


That gives you the function for the y-value of any point on the plane, given its x- and z-values.

Figured it out mostly thanks to http://gamedeveloperjourney.blogspot.com/2009/04/point-plane-collision-detection.html

Made me realize I had to verify the normal a bit closer, turns out my plane's grid was being rendered a little different than the actual coordinates for the verticles. No wonder this was so hard to get right! The pixel was projected correctly but rendered incorrectly.

Thanks for all the help guys, that blogspot entry can't take all the credits. You helped me too.