{"name":"vectorCos","title":"vectorCos","type":"command","url":"https://community.bistudio.com/wiki/vectorCos","revid":379310,"updated":"2026-10-30T23:49:30Z","groups":["Math - Vectors"],"status":"ok","games":{"arma3":"1.22"},"since":"arma3 1.22","arma3_since":"1.22","description":"Cosine of angle between two 3D or 2D vectors.","syntaxes":[{"syntax":"vector1 vectorCos vector2","params":[{"name":"vector1","type":"Vector3D or Arma 3 v2.00 Vector2D","description":"When Vector2D is provided the z coordinate is defaulted to 0","type_expr":"Vector3D | Vector2D"},{"name":"vector2","type":"Vector3D or Arma 3 v2.00 Vector2D","description":"When Vector2D is provided the z coordinate is defaulted to 0","type_expr":"Vector3D | Vector2D"}],"returns":{"type":"Number","type_expr":"Number"},"form":"binary","left":{"text":"vector1"},"right":{"text":"vector2"}}],"examples":[{"code":["_cos = getPos player vectorCos [0,0,2];"]}],"see_also":["vectorAdd","vectorDiff","vectorCrossProduct","vectorDotProduct","vectorMagnitude","vectorMagnitudeSqr","vectorMultiply","vectorDistance","vectorDistanceSqr","vectorDir","vectorUp","setVectorDir","setVectorUp","setVectorDirAndUp","vectorNormalized","vectorFromTo","matrixMultiply","matrixTranspose"],"notes":[{"user":"ffur2007slx2_5","date":"2014-06-28T00:00:00Z","text":"Arma 3 v1.22 Algorithm:\n\n```sqf\nVector1 = [x1,y1,z1]; Vector2 = [x2,y2,z2];\nResult = ((x1 * x2) + (y1 * y2) + (z1 * z2))/((sqrt (x1 ^ 2 + y1 ^ 2 + z1 ^ 2))*(sqrt (x2 ^ 2 + y2 ^ 2 + z2 ^ 2)));\n```\n\nGiven two vectors of attributes, A and B, the cosine similarity, cos(θ), is represented using a dot product and magnitude. The resulting similarity values indicating intermediate similarity or dissimilarity between two vectors."}]}