orbel_xv2aei.f 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. c***********************************************************************
  2. c ORBEL_XV2AEI.F
  3. ***********************************************************************
  4. * PURPOSE: Given the cartesian position and velocity of an orbit,
  5. * compute the osculating orbital elements a, e, and (cos(i))^2 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
  15. c parabola (or an HYPERBOLA!) (real scalar)
  16. c e ==> eccentricity (real scalar)
  17. c inc ==> inclination (real scalar)
  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_xv2aei(x,y,z,vx,vy,vz,gmsum,
  28. & ialpha,a,e,inc)
  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,inc
  35. c... Internals:
  36. real*8 hx,hy,hz,h2,h,r,v2,energy,fac,sini
  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. h = sqrt(h2)
  45. if(hz.gt.h) then
  46. hz = h
  47. hx = 0.0d0
  48. hy = 0.0d0
  49. endif
  50. inc = acos(hz/h)
  51. * Compute the radius R and velocity squared V2, and the dot
  52. * product RDOTV, the energy per unit mass ENERGY .
  53. r = sqrt(x*x + y*y + z*z)
  54. v2 = vx*vx + vy*vy + vz*vz
  55. energy = 0.5d0*v2 - gmsum/r
  56. * Determine type of conic section and label it via IALPHA
  57. if(abs(energy*r/gmsum) .lt. sqrt(TINY)) then
  58. ialpha = 0
  59. else
  60. if(energy .lt. 0.d0) ialpha = -1
  61. if(energy .gt. 0.d0) ialpha = +1
  62. endif
  63. * Depending on the conic type, determine the remaining elements
  64. ***
  65. c ELLIPSE :
  66. if(ialpha .eq. -1) then
  67. a = -0.5d0*gmsum/energy
  68. fac = 1.d0 - h2/(gmsum*a)
  69. if (fac .gt. TINY) then
  70. e = sqrt ( fac )
  71. else
  72. e = 0.d0
  73. endif
  74. endif
  75. ***
  76. ***
  77. c HYPERBOLA
  78. if(ialpha .eq. +1) then
  79. a = +0.5d0*gmsum/energy
  80. fac = h2/(gmsum*a)
  81. if (fac .gt. TINY) then
  82. e = sqrt ( 1.d0 + fac )
  83. c have to insert minus sign in expression for q because this code
  84. c takes a > 0, even for a hyperbola
  85. else
  86. c we only get here if a hyperbola is essentially a parabola
  87. c so we calculate e accordingly to avoid singularities
  88. e = 1.d0
  89. endif
  90. endif
  91. ***
  92. ***
  93. c PARABOLA : ( NOTE - in this case "a", which is formally infinite,
  94. c is arbitrarily set equal to the pericentric distance q).
  95. if(ialpha .eq. 0) then
  96. a = 0.5d0*h2/gmsum
  97. e = 1.d0
  98. endif
  99. ***
  100. ***
  101. return
  102. end ! orbel_xv2aei
  103. c------------------------------------------------------------------