{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# sol5 - 5#include #include 1 Accepts two...

This preview shows pages 1–3. Sign up to view the full content.

'סמ ליגרת-תונכת סרוק 5 ןורתפל אמגוד 1 םילגעמ ךותיח תקידב . #include <stdio.h> #include <math.h> /* Accepts two circles (x1,y1,r1) (x2,y2,r2), returns 1 if they intersect and 0 otherwise */ int do_intersect ( double x1, double y1, double r1, double x2, double y2, double r2); /* Accept two points (x1,y1) (x2,y2), returns the Euclidean distance */ double distance ( double x1, double y1, double x2, double y2); int main() { int ans; double x1,y1,r1,x2,y2,r2; // test #1 x1 = 0; y1 = 0; r1 = 2; x2= 6.3, y2 = 8.1; r2 = 5.2; ans = do_intersect(x1,y1,r1,x2,y2,r2); printf ( "(%g,%g,%g) intersects with (%g,%g,%g)? %d\n" ,x1,y1,r1,x2,y2,r2,ans); // test #2 x1 = 1.3; y1 = 1; r1 = 2.5; x2= 3.9, y2 = 5; r2 = 2.5; ans = do_intersect(x1,y1,r1,x2,y2,r2); printf ( "(%g,%g,%g) intersects with (%g,%g,%g)? %d\n" ,x1,y1,r1,x2,y2,r2,ans); // test #3 x1 = 2; y1 = 3; r1 = 10; x2= 4.1, y2 = 5.1; r2 = 1; ans = do_intersect(x1,y1,r1,x2,y2,r2); printf ( "(%g,%g,%g) intersects with (%g,%g,%g)? %d\n" ,x1,y1,r1,x2,y2,r2,ans); return 0; } int do_intersect ( double x1, double y1, double r1, double x2, double y2, double r2) { double dist = distance(x1,y1,x2,y2); if ((dist <= r1 + r2) && (dist >= fabs(r1 - r2)) ) { return 1; } return 0;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
} double distance ( double x1,
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}