向量點乘,叉乘,乘標量(自用)


1.點乘用於判斷向量之間的前后關系

2.叉乘用於判斷向量之間的左右關系

3.數乘可對向量長度進行縮放。

 1     public Transform A;
 2     public Transform B;
 3 
 4 
 5     private void Start()
 6     {
 7         if (Vector3.Dot(transform.forward,A.position) == 0)
 8         {
 9             print("A 在正左方或者正右方");
10         }
11         if (Vector3.Dot(transform.forward, A.position) < 0)
12         {
13             print("A 在后方");
14 
15         }
16         if (Vector3.Dot(transform.forward, A.position) > 0)
17         {
18             print("A 在前方");
19         }
20         if (Vector3.Dot(transform.forward, B.position) == 0)
21         {
22             print("B 在正左方或者正右方");
23         }
24         if (Vector3.Dot(transform.forward, B.position) < 0)
25         {
26             print("B 在后方");
27 
28         }
29         if (Vector3.Dot(transform.forward, B.position) > 0)
30         {
31             print("B 在前方");
32         }
33 
34 
35         if (Vector3.Cross(transform.forward, A.position).y == 0)
36         {
37             print("A 在正前或者正后方");
38         }
39         if (Vector3.Cross(transform.forward, A.position).y < 0)
40         {
41             print("A 在左方");
42 
43         }
44         if (Vector3.Cross(transform.forward, A.position).y > 0)
45         {
46             print("A 在右方");
47         }
48         if (Vector3.Cross(transform.forward, B.position).y == 0)
49         {
50             print("B 在正前或者正后方");
51         }
52         if (Vector3.Cross(transform.forward, B.position).y < 0)
53         {
54             print("B 在左方");
55 
56         }
57         if (Vector3.Cross(transform.forward, B.position).y > 0)
58         {
59             print("B 在右方");
60         }
61 
62 
63     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM