首页 > 代码库 > cocos2d-x 判断两条直线是否相交
cocos2d-x 判断两条直线是否相交
bool GraphicsUtil::linesCross(b2Vec2 v0, b2Vec2 v1, b2Vec2 t0, b2Vec2 t1, b2Vec2 &intersectionPoint){ if ( areVecsEqual(v1,t0) || areVecsEqual(v0,t0) || areVecsEqual(v1,t1) || areVecsEqual(v0,t1) ) return false; b2Vec2 vnormal = v1 - v0; vnormal = b2Cross(1.0f, vnormal); float v0d = b2Dot(vnormal, v0); float t0d = b2Dot(vnormal, t0); float t1d = b2Dot(vnormal, t1); if ( t0d > v0d && t1d > v0d ) return false; if ( t0d < v0d && t1d < v0d ) return false; b2Vec2 tnormal = t1 - t0; tnormal = b2Cross(1.0f, tnormal); t0d = b2Dot(tnormal, t0); v0d = b2Dot(tnormal, v0); float v1d = b2Dot(tnormal, v1); if ( v0d > t0d && v1d > t0d ) return false; if ( v0d < t0d && v1d < t0d ) return false; intersectionPoint = v0 + ((t0d-v0d)/(v1d-v0d)) * (v1-v0); return true;}
cocos2d-x 判断两条直线是否相交
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。