Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Search  

/home/mrm/Simex/simulations/hr_bike/pv_geometry.cxx File Reference

#include "pv_geometry.h"
#include <cmath>

Include dependency graph for pv_geometry.cxx:

Include dependency graph

Functions

double rad_to_deg (double rad)
double deg_to_rad (double deg)
int pv_intersection_line_sphere (Pv_Point p1, Pv_Point p2, Pv_Point p3, double r)
int pv_intersection_segment_sphere (Pv_Point p1, Pv_Point p2, Pv_Point p3, double r)

Function Documentation

double rad_to_deg double    rad
 

00005                              {
00006   return(rad*180./M_PI);
00007 
00008 }

double deg_to_rad double    deg
 

00009                              {
00010   return(deg*M_PI/180.);
00011 }

int pv_intersection_line_sphere Pv_Point    p1,
Pv_Point    p2,
Pv_Point    p3,
double    r
 

00017                                      { /*radius of sphere*/
00018   int result=-2;
00019   double a=pow(p2.x-p1.x,2)+pow(p2.y-p1.y,2)+pow(p2.z-p1.z,2);
00020   double b=2*((p2.x-p1.x)*(p1.x-p3.x)+
00021               (p2.y-p1.y)*(p1.y-p3.y)+
00022               (p2.z-p1.z)*(p1.z-p3.z));
00023   double c=(pow(p3.x,2)+pow(p3.y,2)+pow(p3.z,2)+
00024             pow(p1.x,2)+pow(p1.y,2)+pow(p1.z,2)-
00025             2*(p3.x*p1.x+
00026                p3.y*p1.y+
00027                p3.z*p1.z)-
00028             pow(r,2));
00029   double exp=pow(b,2)-4*a*c;
00030 
00031   if(a==0){
00032     result=-1;
00033   }
00034   else if(exp<0){
00035     result=0;
00036   }
00037   else if(exp==0){
00038     result=1;
00039   }
00040   else if(exp>0){
00041     result=2;
00042   }
00043   assert(result=-1 || result==0 || result==1 || result==2);
00044   return(result);
00045   /*-1 :  the two given points are not distincts: no line!
00046    * 0 :  no intersection between line and sphere
00047    * 1 :  1 intersectin between line and sphere
00048    * 2 :  2 intersection between line and sphere*/
00049 }

int pv_intersection_segment_sphere Pv_Point    p1,
Pv_Point    p2,
Pv_Point    p3,
double    r
 

00055                                         { /*radius of sphere*/
00056   int result=-2;
00057   double a=pow(p2.x-p1.x,2)+pow(p2.y-p1.y,2)+pow(p2.z-p1.z,2);
00058   double b=2*((p2.x-p1.x)*(p1.x-p3.x)+
00059               (p2.y-p1.y)*(p1.y-p3.y)+
00060               (p2.z-p1.z)*(p1.z-p3.z));
00061   double c=(pow(p3.x,2)+pow(p3.y,2)+pow(p3.z,2)+
00062             pow(p1.x,2)+pow(p1.y,2)+pow(p1.z,2)-
00063             2*(p3.x*p1.x+
00064                p3.y*p1.y+
00065                p3.z*p1.z)-
00066             pow(r,2));
00067   double exp=pow(b,2)-4*a*c;
00068   if(a==0){
00069     result=-1;
00070   }
00071   else if(exp<0){
00072     result=0;
00073   }
00074   else if(exp>=0){
00075     /*the line intersects the sphere in one or two points*/
00076     /*is the point within the segment?*/
00077     double sol1=(-b-sqrt(exp))/(2*a);
00078     double sol2=(-b+sqrt(exp))/(2*a);
00079     /*we do not check at p1
00080      *we check only for the segment and p2*/
00081     if( (sol1>0 && sol1<=1) ||
00082         (sol2>0 && sol2<=1)){
00083       result=1;
00084     }
00085     else{
00086       result=0;
00087     }
00088   }
00089   assert(result==-1 || result==0 || result==1);
00090   return(result);
00091   /*warning: we do not consider intersections at p1
00092    *only within the segment and at p2
00093    *-1 :  the two given points are not distincts!
00094    * 0 :  no intersection between segment and sphere
00095    * 1 :  at least one intersection between segment and sphere*/
00096 }


Generated on Sat Jul 19 04:02:19 2003 for SIMEX by doxygen1.2.18