function Cc.exports.VectorRotateByAngle (vector,angle)-Calculates the vector after the rotation of the vectors, angle: positive counterclockwise, negative input clockwise
Angle = angle*math.pi/180
Local sinangle = Math.sin (angle)
Local cosangle = Math.Cos (angle)
Return CC.P (vector.x * cosangle-vector.y * sinangle,vector.x * sinangle + vector.y * cosangle)
End
function Cc.exports.AngleBetweenVector (V1,V2)-Calculates the angle of two vectors with a positive value
Local n = v1.x*v2.x + v1.y*v2.y
Local m = Vector2tolen (v1) *vector2tolen (v2)
Return Math.acos (n/m) * (180/MATH.PI)
End
function Cc.exports.NomalizeVector (vector)--unit vector
Local Veclen = math.sqrt (vector.x*vector.x + vector.y*vector.y)--unit vector
Return CC.P (Vector.x/veclen,vector.y/veclen)
End
function Cc.exports.VectorToLen (VEC2)--calculating the length of a vector
Return Math.sqrt (VEC2.X*VEC2.X+VEC2.Y*VEC2.Y)
End
Vector patterns commonly used in 2d games