Away3D - 计算两点间的距离、两点间的中点
在Away3D开发中,有时需要计算两个点(Vector3D )之间的距离或者中点。假设有如下v1、v2两个坐标点。
1,两点间的距离(线段长度)
2,两点间的中点(线段中点)
var v1:Vector3D = new Vector3D(0,0,0); var v2:Vector3D = new Vector3D(200,200,200); var lenght:Number = v1.subtract(v2).length; //346.41016151377545
2,两点间的中点(线段中点)
var v1:Vector3D = new Vector3D(0,0,0); var v2:Vector3D = new Vector3D(200,200,200); //方法1 var v3:Vector3D = new Vector3D((v1.x+v2.x)/2, (v1.y+v2.y)/2, (v1.z+v2.z)/2); //方法2 var temV:Vector3D = v1.add(v2); var v3:Vector3D = new Vector3D(temV.x/2, temV.y/2, temV.z/2);