两个向量的叉积。
两个向量的叉积会产生一个第三个向量,该向量垂直于这两个输入向量。结果的大小等于两个输入的大小相乘,然后乘以它们之间角度的正弦值。您可以使用“左手定则”确定结果向量的方向。
应用于 Cross(a, b) 的左手定则。
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { // Get the normal to a triangle from the three corner points a, b, and o, where o is the origin point of vectors a and b. Vector3 GetNormal(Vector3 a, Vector3 b, Vector3 o) { // Find vectors corresponding to two of the sides of the triangle. Vector3 side1 = a - o; Vector3 side2 = b - o;
// Cross the vectors to get a perpendicular vector, then normalize it. This is the Result vector in the drawing above. return Vector3.Cross(side1, side2).normalized; } }