Created
October 16, 2012 23:17
-
-
Save anonymous/3902691 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <math.h> | |
| #define PI 3.141 | |
| struct atom | |
| { | |
| float x; | |
| float y; | |
| float z; | |
| float radius; | |
| float distance; | |
| }; | |
| int main () | |
| { | |
| struct atom lithium1, lithium2; | |
| lithium1.x=0; | |
| lithium1.y=0; | |
| lithium1.z=0; | |
| lithium1.radius=2; | |
| lithium2.x=0; | |
| lithium2.y=0; | |
| lithium2.z=0; | |
| lithium2.radius=2; | |
| for (float t=0; t<10; t+=1) | |
| { | |
| lithium1.x=sin(t*2*PI); | |
| lithium1.y=cos(t*2*PI); | |
| lithium1.z=0.2*t; | |
| lithium2.x=cos(t*2*PI); | |
| lithium2.y=sin(t*2*PI); | |
| lithium2.z=0.2*t; | |
| distance=sqrt(((lithium1.x-lithium2.x)*(lithium1.x-lithium2.x))+((lithium1.y-lithium2.y)*(lithium1.y-lithium2.y))); | |
| if (distance < lithium1.radius+lithium2.radius){ | |
| printf("Collision"); | |
| float x; | |
| float y; | |
| collisionPointX= | |
| ((lithium1.x*lithium2.radius)+(lithium2.x*lithium1.radius)) | |
| /(lithium1.radius+lithium2.radius); | |
| collisionPointY= | |
| ((lithium1.y*lithium2.radius)+(lithium2.y*lithium1.radius)) | |
| /(lithium1.radius+lithium2.radius); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment