Lua自己实现angle角
2016-06-22 18:35
579 查看
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 angle = 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 end return angle; 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
相关文章推荐
- lua中.和:区别
- lua and or not 逻辑运算符
- lua源代码执行顺序
- lua 打印调试日记
- Lua的协同程序(coroutine)
- Lua与C++的交互
- Lua的元方法__newindex元方法
- Lua中强大的元方法__index详解
- LUA———Lua和C 区别
- LUA———函数重名
- lua 堆栈
- lua utf8 gbk 编码转换
- Lua笔记 & 与C之间的交互
- lua中的正则表达式
- vim编译安装+lua模块
- openresty + luajit
- Eclipse调试JDK源代码~watch(监视)变量时报:<error(s)_during_the_evaluation>
- 解决string.len 处理 utf-8 中文字符不正确的问题
- Lua判断OS并添加cpath
- Lua判断OS并添加cpath