Skip to content

Instantly share code, notes, and snippets.

@FloooD
Created March 22, 2011 00:56
Show Gist options
  • Save FloooD/880563 to your computer and use it in GitHub Desktop.
Save FloooD/880563 to your computer and use it in GitHub Desktop.
returns 1 if a line segment intersects a circle. returns 0 otherwise. (note: uses polar coordinates.)
int line_seg_circ_polar(float er, float etheta, float cr, float ctheta, float cradius)
{
if (cradius >= cr) return 1;
if (fabsf(etheta - ctheta) > asinf(cradius / cr)) return 0;
if (er * er < cr * cr - cradius * cradius && er * er + cr * cr - 2 * er * cr * cosf(etheta - ctheta) > cradius * cradius) return 0;
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment