function I3k_vec3_angle1 (p1, p2, p3) return I3k_vec3_angle2 (I3K_VEC3 (p1.x-p2.x, 0, p1.z-p2.z), p3); Endfunction 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 Thenangle = 0;elseif Math.Abs (dot + 1) <= Epsilon Thenangle = Math.pi;elseangle = Math.acos (dot); local cross = _v1.x * _v2.z – _v2.x * _v1.z;if Cross < 0 Thenangle = 2 * Math.pi-angle;endendreturn angle;endfunction i3k_vec3_normalize1 (v) return I3k_vec3_normalize2 (v.x, V.Y , v.z); endfunction 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;endreturn i3k_vec3 (_x, _y, _z); end
Lua realizes angle angle by itself