-inline bool sphere_line_intersection (
- XYZ *p1, XYZ *p2, XYZ *p3, float *r )
-{
-
- // x1,p1->y,p1->z P1 coordinates (point of line)
- // p2->x,p2->y,p2->z P2 coordinates (point of line)
- // p3->x,p3->y,p3->z, r P3 coordinates and radius (sphere)
- // x,y,z intersection coordinates
- //
- // This function returns a pointer array which first index indicates
- // the number of intersection point, followed by coordinate pairs.
-
- //~ static float x , y , z;
- static float a, b, c, /*mu,*/ i ;
-
- if(p1->x>p3->x+*r&&p2->x>p3->x+*r)return(0);
- if(p1->x<p3->x-*r&&p2->x<p3->x-*r)return(0);
- if(p1->y>p3->y+*r&&p2->y>p3->y+*r)return(0);
- if(p1->y<p3->y-*r&&p2->y<p3->y-*r)return(0);
- if(p1->z>p3->z+*r&&p2->z>p3->z+*r)return(0);
- if(p1->z<p3->z-*r&&p2->z<p3->z-*r)return(0);
- a = square(p2->x - p1->x) + square(p2->y - p1->y) + square(p2->z - p1->z);
- b = 2* ( (p2->x - p1->x)*(p1->x - p3->x)
- + (p2->y - p1->y)*(p1->y - p3->y)
- + (p2->z - p1->z)*(p1->z - p3->z) ) ;
- c = square(p3->x) + square(p3->y) +
- square(p3->z) + square(p1->x) +
- square(p1->y) + square(p1->z) -
- 2* ( p3->x*p1->x + p3->y*p1->y + p3->z*p1->z ) - square(*r) ;
- i = b * b - 4 * a * c ;
-
- if ( i < 0.0 )
- {
- // no intersection
- return(0);
- }
- return(1);
-}
-
-inline XYZ DoRotationRadian(XYZ thePoint, float xang, float yang, float zang){
- static XYZ newpoint;
- static XYZ oldpoint;
-
- oldpoint=thePoint;
-
- if(yang!=0){
- newpoint.z=oldpoint.z*cosf(yang)-oldpoint.x*sinf(yang);
- newpoint.x=oldpoint.z*sinf(yang)+oldpoint.x*cosf(yang);
- oldpoint.z=newpoint.z;
- oldpoint.x=newpoint.x;
- }
-
- if(zang!=0){
- newpoint.x=oldpoint.x*cosf(zang)-oldpoint.y*sinf(zang);
- newpoint.y=oldpoint.y*cosf(zang)+oldpoint.x*sinf(zang);
- oldpoint.x=newpoint.x;
- oldpoint.y=newpoint.y;
- }
-
- if(xang!=0){
- newpoint.y=oldpoint.y*cosf(xang)-oldpoint.z*sinf(xang);
- newpoint.z=oldpoint.y*sinf(xang)+oldpoint.z*cosf(xang);
- oldpoint.z=newpoint.z;
- oldpoint.y=newpoint.y;
- }
-
- return oldpoint;