本文整理汇总了C++中line::origin方法的典型用法代码示例。如果您正苦于以下问题:C++ line::origin方法的具体用法?C++ line::origin怎么用?C++ line::origin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类line
的用法示例。
在下文中一共展示了line::origin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make_tuple
std::tuple<bool, float> line::intersect(const line &other) const {
//from http://stackoverflow.com/a/1968345
double p0_x = m_origin.x();
double p0_y = m_origin.y();
double p1_x = m_target.x();
double p1_y = m_target.y();
double p2_x = other.origin().x();
double p2_y = other.origin().y();
double p3_x = other.target().x();
double p3_y = other.target().y();
double s1_x = p1_x - p0_x;
double s1_y = p1_y - p0_y;
double s2_x = p3_x - p2_x;
double s2_y = p3_y - p2_y;
if ((-s2_x * s1_y + s1_x * s2_y) == 0) {
return std::make_tuple(false, 0.0f);
}
double s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y);
double t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y);
double w = 0.1;
if (s >= 0-w && s <= 1+w && t >= 0-w && t <= 1+w)
{
// Collision detected
return std::make_tuple(true, t);
}
return std::make_tuple(false, 0.0f);
}