Question

Essentially I want to make a rectangular plane face an object at all times.

1) I have found my plane equation (ax + by + cz + d = 0)

2) I have the center point of the rectangle (P0 = (x0,y0,z0)), which lays on the plane.

3) I have the width and Height of the rectangle. (W, H)

4) I know that the top two corners of the rectangle will have equal Y values, this goes for bottom 2 corners also. (Y is my up and down axis, the rectangle top and bottom lines will always be parallel to the x,z plane)

Does anyone know how to find the x,y,z values of the four corners C1,C2,C3,C4?

Was it helpful?

Solution

Compute the vector from your plane center to the object you want to face. Call that vector V. Then normalize(V) = (a, b, c) and d = - a*x0 - b*y0 - c*z0. You have the equation for your plane.

Now you can rotate the plane however you want. If you to have the plane to have 0 roll (that is, only ever modify yaw and pitch), you can take the normalized cross product of the world "up" vector (0,0,1) and normalize(V) to get the horizontal vector U for the rectangle. Take the normalized cross product of normalize(V) and U to get the vertical vector W for the rectangle.

The corners of your rectangle are now:

C1 = P0 + (width / 2) * U + (height / 2) * W
C2 = P0 + (width / 2) * U - (height / 2) * W
C3 = P0 - (width / 2) * U + (height / 2) * W
C4 = P0 - (width / 2) * U - (height / 2) * W

Note that this approach has a singularity when the rectangle is directly above or below the object it is supposed to face. You should check for that if appropriate and handle it however makes sense in your scenario.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top