如何确定 3D 平面显示的是哪一侧?

发布于 2024-09-03 06:34:13 字数 520 浏览 1 评论 0原文

这是一个 3d n00b 问题。

我正在开发一个 WPF 控件,它实现了 Silverlight 的 PerspectiveTransform 功能的基础知识,允许 2D 平面在三个轴中的任何一个上旋转。它运作得很好。然而,我对确定飞机背面是否显示所需的数学有点困惑。我现在解决这个问题的天真的代码是:

bool isBackShowing = Math.Abs(RotationX) > 90 && Math.Abs(RotationY) < 90;
if (!isBackShowing)
{
    isBackShowing = Math.Abs(RotationX) < 90 && Math.Abs(RotationY) > 90;
}

但是,当任一轴上的旋转介于 +-270 和 +-360 之间时,此操作会失败。

底层的变换是使用四元数对象来进行实际的旋转,并且它具有很好的 Axis 和 Angle 属性,所以我猜如果我知道如何使用它,我就可以使用它。

This is a 3d n00b question.

I'm working on a WPF control which implements the basics of Silverlight's PerspectiveTransform feature, allowing a 2D plane to be rotated on any of the three axes. It works pretty well. However I'm a little stuck on the math required to determine whether or not the back of the plane is showing. My naive code for figuring that out now is:

bool isBackShowing = Math.Abs(RotationX) > 90 && Math.Abs(RotationY) < 90;
if (!isBackShowing)
{
    isBackShowing = Math.Abs(RotationX) < 90 && Math.Abs(RotationY) > 90;
}

However, this fails when the rotation is between +-270 and +-360 on either axis.

The underlying transform is using a Quaternion object to do the actual rotation, and that has nice Axis and Angle properties, so I'm guessing I could just use that if I knew how.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囍孤女 2024-09-10 06:34:13

您需要计算平面法线和视图方向的点积。

如果为正,则飞机背对着您。

如果为负,则飞机正面向您。

如果它为零,那么您正在查看平面边缘。

要找到平面法线,请取平面上的任意三个点 - 我们将它们称为 OA 和 B。取从 O 到 A 和 O 到 B 的向量。如果取这两个向量的叉积,您将得到法线。请务必小心,因为计算的顺序很重要。一本关于 3D 几何的好书/网站将提供宝贵的帮助

维基百科

You need to do the dot product of the plane normal and the view direction.

If it's positive then the plane is facing away from you.

If it's negative then the plane is facing towards you.

If it's zero then you are looking at the plane edge on.

To find the plane normal take any three points on the plane - lets call them O A and B. Take the vectors from O to A and O to B. If you take the cross product of these two vectors you'll get the normal. Be careful as the order you do the calculation matters. A good book/web site on 3D geometry will be of invaluable help

Wikipedia

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文