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