# Difference between revisions of "User:Dsekercioglu/MEA"

Thanks Xor. I found a bug with the orbital one which gave 2 times more advancing velocity and fixed the calculation.
After brute force MEA calculations, I realised that moving perpendicular wasn't the best option to maximise the MEA. I found a function with polynomial regression which works very well.
Old Brute Force MEA
```        double highestMea;
for (int a = 0; a < 360000; a++) { // For higher accuracy. Normal value is 360.
double angle = Math.toRadians(a / 1000.0);
double mea = Math.asin(Math.sin(angle) / (bulletSpeed / 8 - Math.cos(angle) / 2));
if (mea > highestMea) {
highestMea = mea;
}
}
return highestMea;
```
This function is slow because of many iterations.
Fast Accurate MEA
By using WolframAlpha and Polynomial Regression, I found a function which gives very close results to the Brute Force MEA.
```        double x = bulletSpeed;
double a = 4.626248824E-7;
double b = -4.203721619E-5;
double c = 1.571662957E-3;
double d = -3.085855208E-2;
double e = 3.337262571E-1;
double f = -2.893934846E-1;
double angle = a * Math.pow(x, 5) + b * Math.pow(x, 4) + c * Math.pow(x, 3) + d * Math.pow(x, 2) + e * x + f;
return = Math.asin(Math.sin(angle) / (bulletSpeed / 8 - Math.cos(angle) / 2));
```
Here are some results.
BulletSpeed/Type Traditional Perfect Orbit Brute Force Fast Accurate MEA
11.0 0.8143399421265254 0.7272727272727273 0.8958173020564033 0.8958173020565081
11.5 0.7693273435231462 0.6956521739130435 0.8360222463105106 0.8360222462765713
12.0 0.7297276562269663 0.6666666666666666 0.7853981633891073 0.7853981633902923
12.5 0.694498265626556 0.64 0.7416704288178478 0.7416704288001901
13.0 0.6628738236501358 0.6153846153846154 0.703330828084537 0.7033308280352042
13.5 0.634273648122496 0.5925925925925926 0.6693206919818205 0.669320691948796
14.0 0.6082455789102096 0.5714285714285714 0.638865144210421 0.638865144223163
14.5 0.5844300733415584 0.5517241379310345 0.6113785029510655 0.6113785029690175
15.0 0.5625362445438555 0.5333333333333333 0.586406643219448 0.5864066432158043
15.5 0.5423253027748484 0.5161290322580645 0.5635900430367358 0.5635900430387886
16.0 0.5235987755982989 0.5 0.5426391022263398 0.5426391022493595
16.5 0.5061899196266034 0.48484848484848486 0.5233170954861992 0.5233170954933015
17.0 0.4899573262537283 0.47058823529411764 0.5054280633854913 0.5054280633707354
17.5 0.47478007356550933 0.45714285714285713 0.4888080038530859 0.48880800383339884
18.0 0.4605539916813224 0.4444444444444444 0.47331833170002513 0.4733183317049672
18.5 0.44718874522671376 0.43243243243243246 0.45884093498067674 0.4588409349816298
19.0 0.43460552560736715 0.42105263157894735 0.4452743791524153 0.44527437914716245
19.5 0.42273520519034663 0.41025641025641024 0.43253095218979704 0.43253095218741416
As you can see it gives higher results than Perfect orbit and Traditional MEA and very accurate according to the results.
Pros
• It is fast.
• It is accurate.