Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SpherePointGenerator.c
Go to the documentation of this file.
2{
3 const float GOLDEN_RATIO = 1.618033988749895; // limited to 16 places, rounded away from zero
4 const float INV_GOLDEN_RADIO_RAD = 3.883222077450933; // 2 * Pi / GOLDEN_RATIO limited to 16 places, rounded away from zero
5 const float PI4 = 12.56637061435917; // 4 * Pi limited to 16 places, rounded away from zero
6 const float POINT_DIST_SPHERE_EXP = 2.231; // Significantly improves accuracy of spacing predictions. This number was manually goal-searched by optimising for Root Mean Square Error on GetPointOnUnitSphere's results and predictions that use this exponent.
7 const float INV_POINT_DIST_SPHERE_EXP = 0.4482294935006723; // 1 / 2.231 limited to 16 places, rounded away from zero
8
9 //------------------------------------------------------------------------------------------------
15 static vector GetPointOnUnitSphereFromEquator(int amount, int index)
16 {
17 int isIndexOdd = 1 & index;
18 int centerOffset = index >> 1;
19 if (isIndexOdd)
20 centerOffset = -(centerOffset + 1);
21 int centeredIndex = ((int)(0.5 * amount)) + centerOffset;
22 return GetPointOnUnitSphere(amount, centeredIndex);
23 }
24
25 //------------------------------------------------------------------------------------------------
30 static vector GetPointOnUnitSphere(int amount, int index)
31 {
32 if (amount < 1)
33 return vector.Zero;
34
35 float theta = index * INV_GOLDEN_RADIO_RAD;
36 float phi = Math.Acos(1 - 2 * index / amount); // Math.Acos already limits the domain to [-1, 1], which is acceptable. No additional bounds checking is needed.
37 return { Math.Cos(theta) * Math.Sin(phi), Math.Cos(phi), Math.Sin(theta) * Math.Sin(phi) };
38 }
39
40 //------------------------------------------------------------------------------------------------
44 static int EstimatePointsFromSpacingOnUnitSphere(float spacing)
45 {
46 if (float.AlmostEqual(spacing, 0))
47 return float.INFINITY;
48
49 float areaPerPoint = Math.Pow(spacing, POINT_DIST_SPHERE_EXP);
50 float pointsEst = PI4 / areaPerPoint;
51 return Math.Ceil(pointsEst);
52 }
53
54 //------------------------------------------------------------------------------------------------
58 static float EstimateSpacingFromPointsOnUnitSphere(int amount)
59 {
60 if (amount < 1)
61 return -1;
62
63 float areaPerPoint = PI4 / amount;
64 return Math.Pow(areaPerPoint, INV_POINT_DIST_SPHERE_EXP);
65 }
66}
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition Math.c:13
Definition int.c:13