A characterization of affine hyperquadrics