How to project a point on a plane in 3D?

I have a three-dimensional point (point_x, point_y, point_z), and I want to project it onto a 2D plane in three-dimensional space, which (the plane) is determined by the coordinates of the point (orig_x, orig_y, orig_z) and the unary perpendicular vector (normal_dx, normal_dy, normal_dz )

How should I do it? enter image description here

+45
c ++ c
Mar 07 2018-12-12T00:
source share
7 answers

1) Make a vector from your orig point to point of interest:

v = point-orig (in each dimension);

2) Take the point product of this vector with the unit normal vector n :

dist = vx*nx + vy*ny + vz*nz; dist = scalar distance from point to plane along the normal

3) Multiply the unit normal vector by the distance and subtract this vector from its point.

projected_point = point - dist*normal;

Edit with image: I slightly modified your image. Red is 'v'; 'v' dot 'normal' = length of blue and green ( dist above). Blue - normal*dist . Green = blue * -1 : find planar_xyz, start with point and add a green vector.

enter image description here

+60
Mar 07 2018-12-12T00:
source share

It is very simple, all you have to do is find the perpendicular (abbr here |_ ) the distance from point P to the plane, and then move P back to the perpendicular distance in the plane of the plane. As a result, the translated P is in the plane.

Taking a simple example (which we can verify by checking):

Set n = (0,1,0) and P = (10, 20, -5).

enter image description here

The projected point should be (10,10, -5). You can see by checking that Pproj is 10 units perpendicular to the plane, and if it were in the plane, it would have y = 10.

So how do we find it analytically?

The plane equation is Ax + By + Cz + d = 0. What this equation means is that for a point (x, y, z) to be in a plane, it must satisfy Ax + By + Cz + d = 0 .

What is the equation Ax + By + Cz + d = 0 for the plane drawn above?

The plane has a normal n = (0,1,0). D can be found simply by using a test point already in the plane:

 (0)x + (1)y + (0)z + d = 0 

Point (0.10.0) is in the plane. Connecting above, we find d = -10. The flat equation is then 0x + 1y + 0z - 10 = 0 (if you simplify, you get y = 10).

A good interpretation of d is that we are talking about the perpendicular distance that you would need to translate the plane along its normal so that the plane passes through the origin .

In any case, as soon as we have d , we can find the distance from any point to the plane with the following equation:

enter image description here

There are 3 possible classes of results for | _ distance to the plane:

  • 0: ON PLANE EXACTLY (almost never happens with floating point inaccuracy issues)
  • +1:> 0: In the FRONT plane (on the normal side)
  • -1: <0: BEHIND plane (ON OPPOSITE SIDE OF NORMAL)

Anyway,

enter image description here

Which you can check as correctly by looking at the diagram above

+28
Jul 15 '13 at 18:37
source share

This is not enough to provide only the origin and a normal vector. This defines a three-dimensional plane, however it does not define a coordinate system on the plane.

Think that you can rotate your plane around a normal vector relative to its origin (that is, put a normal vector at the origin and "rotate").

However, you can find the distance from the projected point to the origin (which, obviously, is invariant to rotation).

Subtract the origin from the three-dimensional point. Then do the cross product in the normal direction. If the normal vector is normalized, the resulting length of the vector is equal to the required value.

EDIT

For a complete answer, an additional parameter is required. Say you also supply a vector denoting the x axis on your plane. Thus, we have vectors n and x . Suppose they are normalized.

The origin is denoted by O , your three-dimensional point p .

Then your point is projected as follows:

x = ( p - O ) point x

y = ( p - O ) point ( n cross x )

+6
Mar 07 2018-12-12T00:
source share

This answer is in addition to the two existing answers. I want to show how the explanations of @tmpearce and @bobobobo come down to the same thing, while at the same time providing quick answers to those who are simply interested in copying the equation that is most suitable for their situation.

Method for planes defined by normal n and point o

This method was explained in @tmpearce's answer.

Given the point-normal definition of a plane with normal n and a point o on the plane, the point p ', which is a point on the plane closest to a given point p , can be found:

1) p '= p - ( n โ‹… ( p - o )) * n

Method for planes defined by normal n and scalar d

This method was explained in @bobobobo's answer.

For a plane defined by normal n and a scalar d, the point p ', which is a point on the plane closest to a given point p , can be found from:

2) p '= p - ( n > p + d) * n

If instead you have a point-normal definition of the plane (the plane is determined by the normal n and the point o on the plane) @bobobobo suggests finding d:

3) d = - n โ‹… o

and paste this into equation 2. This gives:

4) p '= p - ( n โ‹… p - n โ‹… o ) * n

Difference Note

Take a closer look at Equations 1 and 4. Comparing them, you will see that Equation 1 uses n โ‹… ( p - o ), where Equation 2 uses n โ‹… p - n โ‹… o . These are actually two ways to write the same thing:

5) n โ‹… ( p - o ) = n โ‹… p - n โ‹… o = n โ‹… p + d

Thus, we can choose the interpretation of the scalar d, as if it were a โ€œpreliminary calculationโ€. I will explain: if n and o are known, but o is only used to calculate n โ‹… ( p - o ), we can also determine the plane n and d and calculate n โ‹… p + d, because we just saw that the same subject .

Additionally, programming with d has two advantages:

  • Finding p 'is now a simpler calculation, especially for computers. For comparison:
    • using n and o : 3 subtractions + 3 multiplications + 2 additions
    • using n and d: 0 subtraction + 3 multiplications + 3 additions.
  • Using d limits the definition of the plane to only 4 real numbers (3 for n + 1 for d) instead of 6 (3 for n + 3 for o ). This saves memory.
+5
Jan 27 '17 at 15:23
source share

Let V = (orig_x, orig_y, orig_z) - (point_x, point_y, point_z)

N = (normal_dx, normal_dy, normal_dz)

Let d = V.dotproduct (N);

Projected point P = V + dN

+1
Mar 07 2018-12-12T00:
source share

I think you should slightly change the way you describe an airplane. In fact, the best way to describe a plane is through the vector n and the scalar c

( x , n ) = c

(absolute value) of the constant c is the distance of the plane from the origin and is equal to ( P , n ), where P is any point on the plane.

So, let P be your starting point, and A the projection of the new point A onto the plane. You need to find such that A '= A - a * n satisfies the plane equation, i.e.

( A - a * n , n ) = ( P , n strong>)

The solution for a, you will find that

a = ( A , n ) - ( P , n ) = ( A , n ) - c

which gives

A '= A - [( A , n ) - c] n

Using your names, it reads

 c = orig_x*normal_dx + orig_y*normal_dy+orig_z*normal_dz; a = point_x*normal_dx + point_y*normal_dy + point_z*normal_dz - c; planar_x = point_x - a*normal_dx; planar_y = point_y - a*normal_dy; planar_z = point_z - a*normal_dz; 

Note: your code will save one scalar product if instead of the point orig P you store c = ( P , n ), which basically means 25% fewer flops for each projection (if this procedure is used many times in your code).

+1
Mar 07 2018-12-12T00:
source share

Let r be the point of the project, and p the result of the projection. Let c be any point on the plane and n be normal to the plane (not necessarily normalized). Write p = r + m d for some scalar m, which will be considered indefinite if their solution is not. Since ( p - c ). n = 0, because all points on the plane satisfy this restriction: ( r n ) n + m ( d . n ) = 0 and therefore m = [( c - r ). n ] / [ d . n ] where the dot used is the product (.). But if d . n = 0, then there is no solution. For example, if d and n are perpendicular to each other, a solution is not available.

0
Sep 10 '14 at 11:43
source share



All Articles