root / branches / simulator / projects / simulator / simulator / circles.c @ 1113
History | View | Annotate | Download (697 Bytes)
1 |
#include <stdlib.h> |
---|---|
2 |
#include <math.h> |
3 |
|
4 |
|
5 |
float rayHits (double Or_x,double Or_y,double Oc_xdouble ,double Oc_y,double Vr_x,double Vr_y) |
6 |
|
7 |
/* Or_x = Origin of ray, x-coordinate
|
8 |
Or_y = Origin of ray, y-coordinate
|
9 |
Oc_x = Origin of circle, x-coordinate
|
10 |
Oc_y = Origin of circle, y-coordinate
|
11 |
Vr_x = Direction of ray, x
|
12 |
Vr_y = Direction of ray, y
|
13 |
*/
|
14 |
|
15 |
{ |
16 |
if( ((2*Vr_x*(Or_x - Oc_x))^2 - 4*Vr_x*(Or_x - Oc_x)^2) < 0) // Discriminant < 0 |
17 |
{ |
18 |
return -1; |
19 |
} |
20 |
|
21 |
if( ((2*Vr_x*(Or_x - Oc_x))^2 - 4*Vr_x*(Or_x - Oc_x)^2) = 0) // Discriminant = 0 |
22 |
{ |
23 |
return -((2*Vr_x*(Or_x - Oc_x))^2 - 4*Vr_x*(Or_x - Oc_x)^2) / (2*Vr_x)); |
24 |
} |
25 |
|
26 |
return -1; |
27 |
|
28 |
\ |
29 |
} |
30 |
|