跳转至

圆形与球体

表达方式

struct Circle
{
  Vector2 center;
  float   radius;
};

struct Sphere
{
  Vector3 center;
  float   radius;
};

相交测试

bool intersects(const Circle& a, const Circle& b)
{
  const float min_distance = a.radius + b.radius;
  return (a.center - b.center).norm_sq() <= min_distance * min_distance;
}

bool intersects(const Sphere& a, const Sphere& b)
{
  const float min_distance = a.radius + b.radius;
  return (a.center - b.center).norm_sq() <= min_distance * min_distance;
}

评论