예제 #1
0
파일: shapes.cpp 프로젝트: Zac-King/GameAI
const collision line_line(const line &a, const line &b)
{
	collision r;

	auto m1 = (a.position.y - a.end.y) / (a.position.x - a.end.x);
	auto m2 = (b.position.y - b.end.y) / (b.position.x - b.end.x);

	auto b1 = a.position.y - m1*a.position.x;
	auto b2 = b.position.y - m2*b.position.x;

	float x = (b2 - b1) / (m1 - m2);
	float y = m1*x + b1;

	if ((a.position.x - a.end.x) == 0) // if a is a vertical line, then there is only 1 possible x value.
	{	x = a.position.x;	y = m2 *x + b2;	}
	if ((b.position.x - b.end.x) == 0)
	{	x = b.position.x;	y = m1 *x + b1;	}

	r.contact = { x, y }; point p(r.contact);
	r.result = circle_point(circle(a.mid(), a.length() / 2), p).result
		    && circle_point(circle(b.mid(), b.length() / 2), p).result;

	if (m1 == m2)
	{
		r.result = false;
		return r;
	}
	return r;
}
예제 #2
0
bool is_laying(construction_line<T1> const & src, line<Pt2> const & target)
{
    typedef typename quan::meta::binary_op<
    T1, quan::meta::minus,typename Pt2::value_type
    >::type value_type;
    construction_line<value_type> cons_target(target.from,target.to - target.from);
    std::pair<bool,quan::two_d::vect<value_type> > intersect_pt = intersect(src,cons_target);
    if (!intersect_pt.first) {
        return false;
    }
    typename value_type mag_target = target.length();
    quan::two_d::vect<value_type> v1 (target.from - intersect_pt.second);
    if (magnitude(v1) > mag_target) return false;
    quan::two_d::vect<value_type> v2 (target.to -intersect_pt.second);
    if(magnitude(v2) > mag_target) return false;
    return true;
}