Find Corners of Rectangle, Given Plane equation, height and width

江枫思渺然 提交于 2019-12-07 15:11:41

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/22769430/find-corners-of-rectangle-given-plane-equation-height-and-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!