function i3k_vec3 (x, Y, Z) return {x = x, y = y, z = z};
End Function I3k_vec3_normalize1 (v) return I3k_vec3_normalize2 (v.x, V.y, v.z);
End Function I3k_vec3_normalize2 (x, y, z) local _x = x;
Local _y = y;
Local _z = Z;
Local d = math.sqrt (_x * _x + _y * _y + _z * _z);
If D ~= 0 Then _x = _x/d;
_y = _y/d;
_z = _z/d;
End return I3K_VEC3 (_x, _y, _z);
End--only X, Z function i3k_vec3_angle1 (p1, p2, p3) return I3k_vec3_angle2 (I3K_VEC3 (p1.x-p2.x, 0, p1.z-p2.z), p3);
End Function I3k_vec3_angle2 (P1, p2) Local _V1 = I3k_vec3_normalize1 (p1);
Local _V2 = I3k_vec3_normalize1 (p2);
Local epsilon = 0.000001;
Local dot = _v1.x * _v2.x + _v1.z * _V2.Z;
Local angle = 0;
If Math.Abs (dot-1) <= epsilon then = 0;
ElseIf Math.Abs (dot + 1) <= epsilon then angle = Math.PI;
else angle = Math.acos (dot);
Local cross = _v1.x * _v2.z-_v2.x * _V1.Z;
If cross < 0 Then angle = 2 * math.pi-angle;
End and return angle;
End