Created
October 15, 2020 12:09
-
-
Save gunavaran/bcd0a1db3ba1150c5d9eac533249580a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//courtesy: MIT Open Courseware (https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-172-performance-engineering-of-software-systems-fall-2018/lecture-slides/MIT6_172F18_lec2.pdf) | |
#include <stdbool.h> | |
#include <math.h> | |
typedef struct{ | |
double x; //x-coordinate | |
double y; //y-coordinate | |
double z; //z-coordinate | |
double r; // radius of the ball | |
} ball_t; | |
double square (double x){ | |
return x * x; | |
} | |
bool collides(ball_t *b1, ball_t *b2){ | |
double distance = sqrt(square(b1->x - b2->x) + square(b1->y - b2->y) + square(b1->z - b2->z)); | |
return distance <= b1->r + b2->r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment