- Vec2::angle的返回值为[0,180]
Vec2::angle(Vec2(1,0), Vec2(1,1)); // 45°
Vec2::angle(Vec2(1,0), Vec2(1,-1)); // 45°
- getAngle的返回值为[-90,90]
Vec2(1,0).getAngle(Vec2(1,1)); // 45
Vec2(1,0).getAngle(Vec2(1, -1));// -45
- 点乘判断前后
几何定义:a·b=|a|*|b|*cos<a,b>
2个向量的夹角[0,360]
cos(-90°)~cos(90°) = [1,0]
cos(90°)~cos(270°) = [0,-1]
- 叉乘判断左右
几何定义:|c|=|a||b|sin<a,b>
sin(0°)~sin(180°) = [1,0]
sin(180°)~sin(360°) = [0,-1]
Vec2 vec = Vec2(0, 1)-Vec2::ZERO;
float ret = 0;
// 注意,必须是相同的起点,这个非常重要
ret = vec.cross(Vec2(0, 1)-Vec2::ZERO); // 0
ret = vec.cross(Vec2(0, -1)-Vec2::ZERO);// -0
ret = vec.cross(Vec2(1, 0)-Vec2::ZERO); // -1
ret = vec.cross(Vec2(-1, 0)-Vec2::ZERO);// 1
ret = vec.cross(Vec2(1, 1)-Vec2::ZERO);// -1
ret = vec.cross(Vec2(1, -1)-Vec2::ZERO);// -1
ret = vec.cross(Vec2(-1, 1)-Vec2::ZERO);// 1
ret = vec.cross(Vec2(-1, -1)-Vec2::ZERO);// 1
>0 左边
<0 右边
网友评论