Exemple #1
0
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;
}
Eigen::Vector2f EllipseGenerator::operator()()
{
  float phi = _arc_dist(G_engine);
  Eigen::Array2f circle_point(std::cos(phi), std::sin(phi));
  Eigen::Array2f ellipse_point = _geometry.radius.array() * circle_point;
  Eigen::Vector2f noise(_noise_dist(G_engine), _noise_dist(G_engine));
  Eigen::Vector2f rotated_ellipse_point = _rotation * (ellipse_point.matrix() + noise);
  return rotated_ellipse_point + _geometry.center;
}