home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Include / physics.js < prev    next >
Encoding:
Text File  |  2002-05-13  |  2.6 KB  |  79 lines

  1. /***************************************************************
  2. ADOBE SYSTEMS INCORPORATED 
  3. Copyright 2002 Adobe Systems Incorporated 
  4. All Rights Reserved 
  5.  
  6. NOTICE:  Adobe permits you to use, modify, and distribute this 
  7. file in accordance with the terms of the Adobe license agreement 
  8. accompanying it.  If you have received this file from a source 
  9. other than Adobe, then your use, modification, or distribution
  10. of it requires the prior written permission of Adobe. 
  11. ***************************************************************/
  12. /***************************************************************
  13. Author: Mary Obelnicki
  14. ***************************************************************/
  15.  
  16. /***************************************************************
  17.  
  18. This include includes two functions that facilitate the calculate
  19. of objects moving in space.  These functions depend on the include,
  20. Vector.js.  Please see Vector.js for details on Vector objects.
  21.  
  22. newPosition(position, velocity, acceleration, dt)
  23.     takes the initial conditions for position, velocity, and 
  24.     acceleration and returns the position after <dt>.  The function 
  25.     assumes constant forces (i.e. no changes in acceleration)
  26.     
  27.     Arguments:
  28.         <position> vector of the initial position
  29.         <velocity> vector of the initial velocity
  30.         <acceleration> vector of the acceleration
  31.         <dt> amount of time to pass, forward in time
  32.  
  33. newVelocity(velocity, acceleration, dt)
  34.     takes the initial condition for velocity and acceleration 
  35.     and returns the velocity after <dt>.
  36.     
  37.     Arguments:
  38.         <velocity> vector of the initial velocity
  39.         <acceleration> vector of the acceleration
  40.         <dt> amount of time to pass, forward in time
  41.  
  42. ***************************************************************/
  43.  
  44. /***************************************************************
  45. DO NOT EDIT BELOW THIS LINE
  46. ***************************************************************/
  47.  
  48. #include "Vector.js"
  49.  
  50. function newPosition(position, velocity, acceleration, dt)
  51. {
  52.     var ddt = Vector.add(Vector.scalerMult(velocity, dt),
  53.              Vector.scalerMult(acceleration, dt*dt/2)); 
  54.     return Vector.add(position, ddt); 
  55. }
  56.  
  57. function newVelocity(velocity, acceleration, dt)
  58. {
  59.     return Vector.add(velocity,
  60.               Vector.scalerMult(acceleration, dt)); 
  61. }
  62.  
  63. function previousPosition(position, velocity, acceleration, dt)
  64. {
  65.     return newPosition(position,
  66.                Vector.scalerMult(velocity, -1), 
  67.                acceleration, 
  68.                dt); 
  69. }
  70.  
  71. function previousVelocity(velocity, acceleration, dt)
  72. {
  73.     return newVelocity(velocity, 
  74.                Vector.scalerMult(acceleration, -1), 
  75.                dt); 
  76. }
  77.  
  78.  
  79.