| | | 1 | | using UnityEngine; |
| | | 2 | | |
| | | 3 | | public static class Utilities { |
| | 1910 | 4 | | public static Vector3 GenerateRandomNoise(Vector3 standardDeviation) { |
| | 1910 | 5 | | return new Vector3(SampleStandardNormal() * standardDeviation.x, |
| | | 6 | | SampleStandardNormal() * standardDeviation.y, |
| | | 7 | | SampleStandardNormal() * standardDeviation.z); |
| | 1910 | 8 | | } |
| | | 9 | | |
| | 1910 | 10 | | public static Vector3 GenerateRandomNoise(Simulation.CartesianCoordinates standardDeviation) { |
| | 1910 | 11 | | return GenerateRandomNoise(Coordinates3.FromProto(standardDeviation)); |
| | 1910 | 12 | | } |
| | | 13 | | |
| | 5730 | 14 | | public static float SampleStandardNormal() { |
| | | 15 | | // Use the Box-Muller transform to sample from a standard normal distribution with mean = 0 and |
| | | 16 | | // standard deviation = 1. |
| | 5730 | 17 | | float u1 = 0f; |
| | | 18 | | // Avoid taking the logarithm of 0. |
| | 17190 | 19 | | while (u1 == 0f) { |
| | 5730 | 20 | | u1 = Random.value; |
| | 5730 | 21 | | } |
| | 5730 | 22 | | float u2 = Random.value; |
| | 5730 | 23 | | return Mathf.Sqrt(-2.0f * Mathf.Log(u1)) * Mathf.Sin(2.0f * Mathf.PI * u2); |
| | 5730 | 24 | | } |
| | | 25 | | |
| | 0 | 26 | | public static float ConvertMpsToKnots(float mps) { |
| | 0 | 27 | | return mps * 1.94384f; |
| | 0 | 28 | | } |
| | | 29 | | |
| | 0 | 30 | | public static float ConvertMetersToFeet(float meters) { |
| | 0 | 31 | | return meters * 3.28084f; |
| | 0 | 32 | | } |
| | | 33 | | } |