如何计算 SCNPlane 的法向量? [英] How to calculate normal vector of a SCNPlane?

查看:16
本文介绍了如何计算 SCNPlane 的法向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:定义由 SCNPlane 表示的平面的法向量.

Goal: Define the normal vector for a plane represented by SCNPlane.

如 Apple 文档中所述使用矢量 - 计算三角形的法线,我可以根据平面的 3 个点计算法向量.这里的问题是我不知道如何获得 3 分,使他们能够制作出正确的三角形.我注意到 SCNPlane 有一个属性 boundingBox,它可以代表 2 个三角形顶点(minmax>).如何找到放置在 SCNPlane 上的第三个顶点?我不能使用 SCNPlane 的中心,因为它与 boundingBox 中的 minmax 点一起创建了一条线.

As mentioned in Apple's documentation Working with Vectors - Calculate the Normal of a Triangle, I can calculate the normal vector based on 3 points from the plane. The issue here is that I don't know how I can get 3 points that they make proper triangle. I've noticed that SCNPlane has a property boundingBox and it can represent 2 of the triangle vertices (min and max). How can I find the 3rd vertex that is placed on the SCNPlane? I cannot use the center of the SCNPlane, because it creates a line along with min and max points from boundingBox.

有没有其他方法可以帮助我为 SCNPlane 检索法向量?

Is there any other way that can help me to retrieve a normal vector for the SCNPlane?

推荐答案

来自文档 我们了解到

表面是一面的.它的表面法向量指向其局部坐标空间的正 z 轴方向,因此默认情况下只能从该方向看到.

The surface is one-sided. Its surface normal vectors point in the positive z-axis direction of its local coordinate space, so it is only visible from that direction by default.

SCNPlane 的法线在本地空间中总是 (0, 0, 1) 并且不能改变.

The normal of a SCNPlane is always (0, 0, 1) in local space and that cannot change.

当它附加到一个节点时,该节点的方向决定了另一个坐标系中的法线.您可以使用 simdConvertVector:toNode:在坐标空间之间转换:

When it is attached to a node, the orientation of that node determines the normal in an another coordinate system. You can use simdConvertVector:toNode: to convert between coordinate spaces:

// normal expressed in world space
let normal = simd_normalize(node.simdConvertVector(simd_float3(0, 0, 1), to: nil))

这篇关于如何计算 SCNPlane 的法向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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