#pragma strictpublic var M_pa:vector3 = new Vector3 (2.0f, 4.0f, 0.0f);p ublic var M_pb:vector3 = new Vector3 ( -4.0f, 2.0 f,0.0f);p rivate var M_ptemp:vector3 = new Vector3 (0.0f,0.0f,0.0f);p rivate var m_ftemp:float = 0.0f;private var M_fangl E:float = 0.0f;function Awake () {Debug.Log ("vector reduced by twice times:" + Vectorscale (m_pa,2). ToString ()); Debug.Log (M_pa.operator * 2 ();); Debug.Log ("negative vector of vectors:" + fvector (M_PB). ToString ()); Debug.Log ("Vector normalization:" + VECTORZUO3 (M_PA). ToString ()); Debug.Log (Vector3.normalize (M_PA)); Debug.Log ("a vector to the length of the B vector:" + vector2vectordis (M_PA,M_PB)); Debug.Log (Vector3.distance (M_PA,M_PB)); Debug.Log ("The angle between the b vector and a vector:" + vectorandvectorangle (M_PA,M_PB)); Debug.Log (Vector3.angle (M_PA,M_PB)); Debug.Log ("A vector is perpendicular to the vector of the B vector:" + VectorZuoye6 (M_PA,M_PB). ToString ()); Debug.Log (M_pa-vector3.project (M_PA,M_PB)); Debug.Log ("The angle of the two vectors on the plane:" + VectorZuoye7 (M_PA,M_PB));} modulo function verctormagnitudetest (A:VECTOR3): Float{return mathf.sqrt (a.x * a.x + a.y * a.y + a.z * a.z);} Seeking toAmount of dot product function Vectordottest (A:VECTOR3,B:VECTOR3): float{m_ftemp = a.x * b.x + a.y * b.y + a.z * B.z;return m_ftemp;} Cross-multiply function vectorchatest (A:vector3, B:vector3): vector3{m_ptemp.x = a.y * b.z-a.z * b.y;m_ptemp.y = a.z * b. x-a.x * b.z;m_ptemp.z = a.x * B.Y-A.Y * B.x;return m_ptemp;} Vector scaling function Vectorscale (a:vector3,n:int): vector3{m_ptemp = A;if (n! = 0)//sentenced 0{m_ptemp.x/= n;m_ptemp.y/= n;m_pt Emp.z/= N;} return m_ptemp; }//Vector's negative vector function Fvector (A:VECTOR3): vector3{m_ptemp = a;m_ptemp.x = 0.0F-M_PTEMP.X;M_PTEMP.Y = 0.0f-m_ptemp.y;m_pte Mp.z = 0.0f-m_ptemp.z;return m_ptemp;} Vector normalization function VectorZuo3 (A:VECTOR3): vector3{m_ptemp = A;//var fdis:float = A.magnitude;//qiu mo devar fdis:float = Verctormagnitudetest (a);//modulo m_ptemp.x = a.x/fdis;//does not need to be sentenced to 0m_ptemp.y = A.y/fdis;m_ptemp.z = A.z/fdis;return m_pTemp; }//a vector to B-vector length function Vector2vectordis (A:VECTOR3,B:VECTOR3): float{m_ptemp.x = B.X-A.X;M_PTEMP.Y = B.y-a.y;m_ptem P.z = B.z-a.z;m_ftemp = Verctormagnitudetest (m_ptemp);//return m_ftemp with a custom modulo function;} The angle between the b vector and a vector//Arcos ((A and B points)/(A-mode *b mode)) function Vectorandvectorangle (A:VECTOR3,B:VECTOR3): Float{var fDo T:float = Vectordottest (A, B);//Vector's dot multiplication var fdism:float = verctormagnitudetest (a) * Verctormagnitudetest (b); var ftemp:fl Oat = Mathf.acos (fdot/fdism); M_fangle = ftemp * Mathf.rad2deg;return m_fangle;} Vector of a vector perpendicular to B vector//A vector –b* ((point multiplication of A and B)///square of modulo) function VectorZuoye6 (A:vector3, B:vector3): Vector3{var pTemp1 : Vector3 = B;var Ptemp2:vector3 = a;ptemp1.x *= vectordottest (A/b)/(Verctormagnitudetest (b) *verctormagnitudetest (b)); Using custom dot product and modulus functions ptemp1.y *= vectordottest (A, B)/(Verctormagnitudetest (c) *verctormagnitudetest (b));// Using custom dot product and modulus functions ptemp1.z *= vectordottest (A, B)/(Verctormagnitudetest (c) *verctormagnitudetest (b));//with custom dot product and modulus functions m_ ptemp.x = PTEMP2.X-PTEMP1.X;M_PTEMP.Y = Ptemp2.y-ptemp1.y;m_ptemp.z = Ptemp2.z-ptemp1.z;return m_pTemp;} The angle between the a vector and the B vector on the plane formed by vector A and vector b//ARSin (A and B fork multiplication of the die/(A-mode *b die)) function VectorZuoye7 (A:VECTOR3,B:VECTOR3): float{m_ftemp = Mathf.asin (Verctormagnitudetest (V Ectorchatest (b))/(Verctormagnitudetest (a) * Verctormagnitudetest (b)));//With custom cross-multiplication and modulus functions m_fangle = m_ftemp * Mathf.rad 2deg;return M_fangle;}
Unity3d Cultivation Road: Game development, 3d mathematics knowledge of the exercise "1" (constantly updated ....) )