定义
一个数字列表,表示各个维度上的有向位移。假设向量是(1,1,1),则x轴的有向位移是1,y轴的有向位移是1,z轴的有向位移是1。
向量是一个有大小有方向的物理量。
–大小就是向量的模长。
–方向描述了空间中向量的指向。
向量的大小
(1,1,1)只能代表各个维度上的有向位移,它不能代表大小,不能代表方向。
大小是模长,根据数学公式计算,几何意义是从原点到向量点线段的长度。
unity提供了计算模长的api: magnitude,同时也提供了计算x平方+y平方+z平方的的api:sqrMagnitude
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class aaa : MonoBehaviour
{
// Update is called once per frame
void Update ()
{
Debug.DrawLine(Vector3.zero,transform.position);
}
}
Debug.DrawLine 能在场景中画出两个向量之间的连线,直观的看出方向。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class aaa : MonoBehaviour
{
public float mathf;
public float mag;
public float distance;
// Update is called once per frame
void Update ()
{
Vector3 pos = transform.position;
//利用数学公式求模长
mathf