Skip to content

Commit 381d3b8

Browse files
committed
RK4 Math fix
1 parent f2af468 commit 381d3b8

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

rebound.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,9 @@
659659
cAcceleration =
660660
(tension * (this._endValue - tempPosition)) - friction * tempVelocity;
661661

662-
tempPosition = position + cVelocity * Spring.SOLVER_TIMESTEP_SEC * 0.5;
662+
tempPosition = position + cVelocity * Spring.SOLVER_TIMESTEP_SEC;
663663
tempVelocity =
664-
velocity + cAcceleration * Spring.SOLVER_TIMESTEP_SEC * 0.5;
664+
velocity + cAcceleration * Spring.SOLVER_TIMESTEP_SEC;
665665
dVelocity = tempVelocity;
666666
dAcceleration =
667667
(tension * (this._endValue - tempPosition)) - friction * tempVelocity;

spec/reboundSpec.js

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -94,38 +94,44 @@ describe('Spring', function() {
9494

9595
it('performs the expected numerical integration', function() {
9696
var expectedValues = [
97-
0.00009528483384916665, 0.028055130517962948, 0.09762221624500955, 0.19049729510981317,
98-
0.2936714067404636, 0.40497286144544664, 0.5111546203653615, 0.608094950748042,
99-
0.6989512644000222, 0.7763987794431019, 0.8407054339615845, 0.8958918579042241,
100-
0.9389972480971012, 0.9717337781699595, 0.9971592132059878, 1.0147625813663106,
101-
1.0262208257725207, 1.0332956493268395, 1.0364894607275925, 1.0369398983555251,
102-
1.035403885129236, 1.032578591121358, 1.0290563359258007, 1.0250064291810552,
103-
1.0209746156852837, 1.017177199769159, 1.01352576938495, 1.0103417579447809,
104-
1.0076425888100107, 1.0052779569597994, 1.0033901510059924, 1.0019218958288727,
105-
1.0007486041427742, 0.9999054758294816, 0.9993272477227115, 0.9989374541332141,
106-
0.9987229619135461, 0.9986362506581137, 0.9986416423402271, 0.9987133189462081,
107-
0.9988248788496944, 0.9989660543527678, 0.9991147367563946, 0.999260176669424,
108-
0.9994041755139224, 0.9995328710495801, 0.9996443410389881, 0.9997440186579756,
109-
0.9998252721214403, 0.9998898549593689, 0.9999427545081083, 0.9999819409115459,
110-
1.0000098947929037, 1
111-
];
97+
0.00011425836769833332, 0.02826894887325712, 0.09786685539023218,
98+
0.1906494054868597, 0.29365843980608936, 0.40474896134789684,
99+
0.5107172515563908, 0.6074646735059072, 0.6981529338231078,
100+
0.7754777086457709, 0.839707819077817, 0.8948595531478145,
101+
0.9379716344919623, 0.9707479956875202, 0.9962428035545625,
102+
1.0139342469614867, 1.0254911376885876, 1.0326752603538492,
103+
1.0359769203762703, 1.0365293261033242, 1.0350922763323542,
104+
1.0323542266285861, 1.0289066506717395, 1.0249225975602652,
105+
1.0209434111787616, 1.0171866123097923, 1.0135669403763488,
106+
1.0104047123230713, 1.0077191568237913, 1.0053619452157372,
107+
1.0034760195970387, 1.0020056186933401, 1.0008270224418958,
108+
0.9999766409388905, 0.9993901328804057, 0.9989911526141649,
109+
0.9987676456533224, 0.9986724777596906, 0.9986697290588868,
110+
0.9987342814912026, 0.9988397756522094, 0.9989756166030785,
111+
0.9991200309747728, 0.9992621551645858, 0.9994035221256672,
112+
0.9995303572870538, 0.9996405939737665, 0.9997394992090661,
113+
0.9998204037171646, 0.9998849475545486, 0.9999380421221211,
114+
0.9999775818502517, 1.0000059803454007, 1.0000264835439028, 1 ];
112115

113116
var expectedVelocities = [
114-
0.22809713393833664, 3.1836279556537797, 5.189693552210269, 6.308133231261666,
115-
6.777680072142652, 6.779820703245073, 6.4423806169966324, 5.8988969764596115,
116-
5.2027207222858145, 4.464480016354999, 3.739124457374943, 3.0186340411984003,
117-
2.3728782790346234, 1.812176854322289, 1.3096658169399373, 0.8990634713436961,
118-
0.5719079083707492, 0.30321776183243665, 0.10352766527348324, -0.039503489141740795,
119-
-0.1423507144869582, -0.2058607850785233, -0.23984623785015569, -0.2526432950540898,
120-
-0.24879364530323395, -0.23414513023207698, -0.2115811308267352, -0.185501057593562,
121-
-0.15853434660787047, -0.13076036811539526, -0.10514546934610718, -0.08237222075625747,
122-
-0.06151931327812765, -0.0441214723178374, -0.029969085071624765, -0.018082334323351185,
123-
-0.009015079581744903, -0.0023131392365830466, 0.0027155555738820987, 0.00603264077492341,
124-
0.00803456840095728, 0.009095655645431211, 0.009368949074455861, 0.009106122079028167,
125-
0.008453224982293001, 0.007581738755800811, 0.006613800148558283, 0.005570115988782897,
126-
0.004574621636742495, 0.003665965171462857, 0.002814740532247959, 0.0020893441663066958,
127-
0.0014872204418175175, 0
128-
];
117+
0.2276775324800067, 3.1774598721505054, 5.1793267330810915,
118+
6.295509849377661, 6.764476633590014, 6.76742694258232, 6.431820383696734,
119+
5.890780309158667, 5.1974947091126475, 4.462143087776778,
120+
3.7394582582521605, 3.021424291526861, 2.3776517513733193,
121+
1.8184393728184831, 1.3169969453548693, 0.906988991160123,
122+
0.5800273047791344, 0.31119327922524626, 0.11108882863895153,
123+
-0.03254366218086566, -0.1361569165953432, -0.2004956653386716,
124+
-0.23531870559388396, -0.24897437017600185, -0.24591942995283073,
125+
-0.2319823912240368, -0.2100747888822411, -0.18454561286117094,
126+
-0.1580280108075904, -0.13062975758538428, -0.10529753257479642,
127+
-0.08272714732814185, -0.062017752864186065, -0.044703645341229135,
128+
-0.030588635672438014, -0.01870387489501671, -0.009611048353110578,
129+
-0.0028653747019518534, 0.002221614953962866, 0.005602663755134356,
130+
0.0076693990836953, 0.008796769142543886, 0.009131171230224182,
131+
0.008922837011801944, 0.00832006031857832, 0.007490584515806349,
132+
0.006556941548531174, 0.00554210142341889, 0.004568554860624362,
133+
0.0036759782316913665, 0.002836575672722143, 0.0021186451259753557,
134+
0.0015206065620057547, 0.0010057481768040006, 0 ];
129135

130136
var actualValues = [], actualVelocities = [];
131137

0 commit comments

Comments
 (0)