unity3d如何算出一个点到一个平面的垂直距离

来源:互联网 发布:彩印编织袋价格算法 编辑:程序博客网 时间:2024/05/16 15:07
using UnityEngine;
using System.Collections;
public class NewBehaviourScript :MonoBehaviour

public Transform planeTarget;
public Transform target;
void Update ()
{
if (!planeTarget) {
Debug.LogWarning ("planeTarget is null"); 
return;
}
if (!target) {
Debug.LogWarning ("target is null"); 
return;
}
//Plane 类提供了处理平面所用到的基本算法
//3的点构成一个面,或者坐标和法线构成一个面
//这里使用planeTarget 坐标和法线,平面的法线也就是正面方向(up方向)
Plane plane = new Plane (planeTarget.up,planeTarget.position); 
float distance = plane.GetDistanceToPoint (target.position);
Debug.Log ("distance:" + distance); 
}
}
0 0