orbel_xv2aeq.f 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ***********************************************************************
  2. c ORBEL_XV2AEQ.F
  3. ***********************************************************************
  4. * PURPOSE: Given the cartesian position and velocity of an orbit,
  5. * compute the osculating orbital elements a, e, and q only.
  6. *
  7. C input:
  8. c x,y,z ==> position of object (real scalars)
  9. c vx,vy,vz ==> velocity of object (real scalars)
  10. c gmsum ==> G*(M1+M2) (real scalar)
  11. c
  12. c Output:
  13. c ialpha ==> conic section type ( see PURPOSE, integer scalar)
  14. C a ==> semi-major axis or pericentric distance if a parabola
  15. c (real scalar)
  16. c e ==> eccentricity (real scalar)
  17. c q ==> perihelion distance (real scalar); q = a(1 - e)
  18. c
  19. * ALGORITHM: See e.g. p.70 of Fitzpatrick's "Priciples of Cel. Mech."
  20. * REMARKS: Based on M. Duncan's orbel_xv2el.f
  21. * This routine is generally applied to study (hyperbolic) close
  22. c encounters of test particles with planets.
  23. * AUTHOR: L. Dones
  24. * DATE WRITTEN: February 24, 1994
  25. * REVISIONS:
  26. ***********************************************************************
  27. subroutine orbel_xv2aeq(x,y,z,vx,vy,vz,gmsum,
  28. & ialpha,a,e,q)
  29. include '../swift.inc'
  30. c... Inputs Only:
  31. real*8 x,y,z,vx,vy,vz,gmsum
  32. c... Outputs
  33. integer ialpha
  34. real*8 a,e,q
  35. c... Internals:
  36. real*8 hx,hy,hz,h2,r,v2,energy,fac
  37. c----
  38. c... Executable code
  39. * Compute the angular momentum H, and thereby the inclination INC.
  40. hx = y*vz - z*vy
  41. hy = z*vx - x*vz
  42. hz = x*vy - y*vx
  43. h2 = hx*hx + hy*hy + hz*hz
  44. * Compute the radius R and velocity squared V2, and the dot
  45. * product RDOTV, the energy per unit mass ENERGY .
  46. r = sqrt(x*x + y*y + z*z)
  47. v2 = vx*vx + vy*vy + vz*vz
  48. energy = 0.5d0*v2 - gmsum/r
  49. * Determine type of conic section and label it via IALPHA
  50. if(abs(energy*r/gmsum) .lt. sqrt(TINY)) then
  51. ialpha = 0
  52. else
  53. if(energy .lt. 0.d0) ialpha = -1
  54. if(energy .gt. 0.d0) ialpha = +1
  55. endif
  56. * Depending on the conic type, determine the remaining elements
  57. ***
  58. c ELLIPSE :
  59. if(ialpha .eq. -1) then
  60. a = -0.5d0*gmsum/energy
  61. fac = 1.d0 - h2/(gmsum*a)
  62. if (fac .gt. TINY) then
  63. e = sqrt ( fac )
  64. else
  65. e = 0.d0
  66. endif
  67. q = a*(1.d0 - e)
  68. endif
  69. ***
  70. ***
  71. c HYPERBOLA
  72. if(ialpha .eq. +1) then
  73. a = +0.5d0*gmsum/energy
  74. fac = h2/(gmsum*a)
  75. if (fac .gt. TINY) then
  76. e = sqrt ( 1.d0 + fac )
  77. q = -a*(1.d0 - e)
  78. c have to insert minus sign in expression for q because this code
  79. c takes a > 0, even for a hyperbola
  80. else
  81. c we only get here if a hyperbola is essentially a parabola
  82. c so we calculate e accordingly to avoid singularities
  83. e = 1.d0
  84. q = 0.5*h2/gmsum
  85. endif
  86. endif
  87. ***
  88. ***
  89. c PARABOLA : ( NOTE - in this case "a", which is formally infinite,
  90. c is arbitrarily set equal to the pericentric distance q).
  91. if(ialpha .eq. 0) then
  92. a = 0.5d0*h2/gmsum
  93. e = 1.d0
  94. q = a
  95. endif
  96. ***
  97. ***
  98. return
  99. end ! orbel_xv2aeq
  100. c------------------------------------------------------------------