前言
- 基于图形学中对平面的定义,可知定义平面的5种方法(详细描述),而在Unity中共三种确定平面的方法
Plane结构
- 三种构造函数
//平面内一个+平面法向量 public Plane(Vector3 inNormal, Vector3 inPoint); //平面法向量+长度 public Plane(Vector3 inNormal, float d); //平面内任意不共线的三个点 public Plane(Vector3 a, Vector3 b, Vector3 c);
- 关于
public Plane(Vector3 inNormal, float d)
,这个应该稍微难懂,其中d表示平面距离原点(0,0,0)的距离
求平面的法向量
-
已知平面内非同一直线上的三个点P1、P2、P3,则法向量计算公式为
N → = P 1 P 2 → × P 1 P 3 → \overrightarrow{N } =\overrightarrow{P1 P2} \times \overrightarrow{P1 P3} N=P1P2×P1P3 -
代码:
Vector3 n = Vector3.Cross(p2 - p1 , p3 - p1);