码迷,mamicode.com
首页 > Windows程序 > 详细

API:float dis=vector.magnitude

时间:2019-08-05 19:09:44      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:api   代码   void   float   ali   数学   osi   this   pos   

代码实现:

//模长
void Demo01()
{
Vector3 pos = this.transform.position;

Debug.DrawLine(Vector3.zero,this.transform.position);
//利用数学公式求模长
float m1 =Mathf.Sqrt( Mathf.Pow(pos.x,2)+Mathf.Pow(pos.y,2)+Mathf.Pow(pos.z,2));
//利用Unity封装的方法(API)求模长
float m2 = pos.magnitude;
//利用距离公式求模长
float m3 = Vector3.Distance(Vector3.zero,pos);

Debug.LogFormat("{0},{1},{2}",m1,m2,m3);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
向量的方向:
获取向量也称为“标准化向量”或“归一化向量”,即获取该向量的单位向量

单位向量:大小为1的向量

几何意义:将该向量拉长或缩短,使模长等于1

公式:V/|V|

vector2为vector1的单位向量
vector1.Normalized();将vector自身设置为单位向量
--------------------- 

API:float dis=vector.magnitude

标签:api   代码   void   float   ali   数学   osi   this   pos   

原文地址:https://www.cnblogs.com/hyhy904/p/11304684.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!