📄 circrect.c
字号:
/* Fast Circle-Rectangle Intersection Checkingby Clifford A. Shafferfrom "Graphics Gems", Academic Press, 1990*/#include "GGems.h"boolean Check_Intersect(R, C, Rad)/* Return TRUE iff rectangle R intersects circle with centerpoint C and radius Rad. */ Box2 *R; Point2 *C; double Rad;{ double Rad2; Rad2 = Rad * Rad; /* Translate coordinates, placing C at the origin. */ R->max.x -= C->x; R->max.y -= C->y; R->min.x -= C->x; R->min.y -= C->y; if (R->max.x < 0) /* R to left of circle center */ if (R->max.y < 0) /* R in lower left corner */ return ((R->max.x * R->max.x + R->max.y * R->max.y) < Rad2); else if (R->min.y > 0) /* R in upper left corner */ return ((R->max.x * R->max.x + R->min.y * R->min.y) < Rad2); else /* R due West of circle */ return(ABS(R->max.x) < Rad); else if (R->min.x > 0) /* R to right of circle center */ if (R->max.y < 0) /* R in lower right corner */ return ((R->min.x * R->min.x) < Rad2); else if (R->min.y > 0) /* R in upper right corner */ return ((R->min.x * R->min.x + R->min.y + R->min.y) < Rad2); else /* R due East of circle */ return (R->min.x < Rad); else /* R on circle vertical centerline */ if (R->max.y < 0) /* R due South of circle */ return (ABS(R->max.y) < Rad); else if (R->min.y > 0) /* R due North of circle */ return (R->min.y < Rad); else /* R contains circle centerpoint */ return(TRUE);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -