查找矩形的角,给定平面方程,高度和宽度 [英] Find Corners of Rectangle, Given Plane equation, height and width

查看:35
本文介绍了查找矩形的角,给定平面方程,高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本质上,我想让矩形平面始终面向对象.

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

1) 我找到了我的平面方程 (ax + by + cz + d = 0)

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

2) 我有矩形的中心点 (P0 = (x0,y0,z0)),它位于平面上.

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

3) 我有矩形的宽度和高度.(W, H)

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

4) 我知道矩形的顶部两个角将具有相同的 Y 值,这也适用于底部的两个角.(Y是我的上下轴,矩形的上下线总是平行于x,z平面)

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)

有谁知道如何求四个角 C1、C2、C3、C4 的 x、y、z 值?

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

推荐答案

计算从您的平面中心到您要面对的对象的向量.调用该向量 V.然后 normalize(V) = (a, b, c) 和 d = - a*x0 - b*y0 - c*z0.你有你的飞机的方程.

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.

现在您可以随意旋转飞机.如果你想让飞机有 0 滚转(即只修改偏航和俯仰),你可以取世界向上"向量 (0,0,1) 和 normalize(V) 的归一化叉积得到矩形的水平向量 U.取normalize(V)和U的归一化叉积得到矩形的垂直向量W.

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.

矩形的角现在是:

C1 = P0 + (宽/2) * U + (高/2) * W
C2 = P0 + (宽/2) * U - (高/2) * W
C3 = P0 - (宽/2) * U + (高/2) * W
C4 = P0 - (宽/2) * U - (高/2) * W

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.

这篇关于查找矩形的角,给定平面方程,高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆