【unity】Vector3.Angle&Cross&a

作者: 黒可乐 | 来源:发表于2016-11-17 16:11 被阅读294次
    Vector3.Angle
    计算A点与B点以世界坐标原点为夹角的角度
    Vector3.Angle(A.posion,B.position);
    

    计算以B点为顶点BA,BC为边的夹角
    Vector3.Angle(B.position-A.posion,B.position-C.position);
    
    Vector3.Cross

    求两个向量的法向量

    黄线为BA,BC法向量
    Debug.DrawLine(B.position,Vector3.Cross(B.position-A.posion,B.position-C.position));
    

    三角形ABC围绕顶点B旋转,三条边都在跟随旋转。就可以使用这个求出旋转顶点的法向量以此来实时监测三角形的每条边的是否正确的跟随旋转。实现三角液压器算法就可以用这个。当然也需要判断旋转角度的正负。

    Vector3.Dot

    可以用来判断一个物体相对于另一个物体的位置,因为a·b=|a||b|cos<a,b>,当然用mathf.acos与vector3.normalize,也可以求出角度。

    Vector3 dir=transform.TransformDirction(Vector3.forward);//这里可是任何方向
    Vector3 toOther = other.position - transform.position;  
    if ((forward, toOther) < 0) 
        print("The other transform is behind me!");
    

    换而言之上面这个就是求other在transform正方向上的投影。然后根据角度就可以判断出是否在一条线上。当然标准化了的两个向量点乘,在一个正方向返回就是1,反方向返回就是-1。

    相关文章

      网友评论

      本文标题:【unity】Vector3.Angle&Cross&a

      本文链接:https://www.haomeiwen.com/subject/piklpttx.html