Data Str & Algorithm HW Solutions 86

Data Str & Algorithm HW Solutions 86 - return...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
86 Chap. 13 Advanced Tree Structures 13.9 // Return TRUE iff rectangle R intersects circle with // centerpoint C and radius Rad. boolean CheckIntersect(Rectangle* R, Point* 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
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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; }...
View Full Document

This note was uploaded on 12/27/2011 for the course MAP 2302 taught by Professor Bell,d during the Fall '08 term at UNF.

Ask a homework question - tutors are online