1.  
  2.  
  3. void CFunnel::GetCorner(CVector3 *P1, CVector3 *Cntr, float Radius, bool WichSide, CVector3 &TResult)
  4. {
  5. if(WichSide)
  6. {
  7. float x0 = P1->x;
  8. float y0 = P1->z;
  9.  
  10. float x1 = Cntr->x;
  11. float y1 = Cntr->z;
  12.  
  13. // get distance from P1 to C
  14. float D = P1->GetDistance(*Cntr);
  15.  
  16. // get center of 2nd circle
  17. float x2 = (x0+x1)/2;
  18. float y2 = (y0+y1)/2;
  19.  
  20. // get ramp.
  21. float m = (x2-x1)/(y1-y2);
  22. float n = (x1*x1 - x2*x2 + y1*y1 - y2*y2 + ((D*D)/4) - Radius*Radius)/( 2*(y1-y2));
  23.  
  24. // get parameters
  25. float A = m*m + 1;
  26. float B = 2*(m*n - x1 - y1*m);
  27. float C = n*n + x1*x1 - 2*y1*n - Radius*Radius;
  28.  
  29. // get FINAL eq. solutions
  30. float delta = sqrt(B*B - 4*A*C);
  31.  
  32. float a = (-B - delta) / (2*A);
  33. float b = m*a+n;
  34.  
  35. TResult = CVector3(a,0,b);
  36. }
  37. else
  38. {
  39. float x0 = P1->x;
  40. float y0 = P1->z;
  41.  
  42. float x1 = Cntr->x;
  43. float y1 = Cntr->z;
  44.  
  45. // get distance from P1 to C
  46. float D = P1->GetDistance(*Cntr);
  47.  
  48. // get center of 2nd circle
  49. float x2 = (x0+x1)/2;
  50. float y2 = (y0+y1)/2;
  51.  
  52. // get ramp.
  53. float m = (x2-x1)/(y1-y2);
  54. float n = (x1*x1 - x2*x2 + y1*y1 - y2*y2 + ((D*D)/4) - Radius*Radius)/( 2*(y1-y2));
  55.  
  56. // get parameters
  57. float A = m*m + 1;
  58. float B = 2*(m*n - x1 - y1*m);
  59. float C = n*n + x1*x1 - 2*y1*n - Radius*Radius;
  60.  
  61. // get FINAL eq. solutions
  62. float delta = sqrt(B*B - 4*A*C);
  63.  
  64.  
  65. float c = (-B + delta) / (2*A);
  66. float d = m*c+n;
  67.  
  68. TResult = CVector3(c,0,d);
  69. }
  70. }