// CIRCLE with R=1 public static Vector2 Circle(ref UMT.MersenneTwister _rand) { float t = (float)_rand.Next(); float _2pi = (float)Math.PI * 2; float a = MTRandom.ScaleFloatToRange(t, 0, _2pi, 0, Int32.MaxValue); return(new Vector2((float)Math.Cos(a), (float)Math.Sin(a))); }
private static Vector3 PickCubePoints(ref UMT.MersenneTwister _rand) { float x = MTRandom.ScaleFloatToRange(_rand.NextSingle(true), -1, 1, 0, 1); float y = MTRandom.ScaleFloatToRange(_rand.NextSingle(true), -1, 1, 0, 1); float z = MTRandom.ScaleFloatToRange(_rand.NextSingle(true), -1, 1, 0, 1); return(new Vector3(x, y, z)); }
/// <summary> /// Returns a point on the unit sphere that is within a cone along the z-axis /// </summary> /// <param name="spotAngle">[0..180] specifies the angle of the cone. </param> /// <remarks> /// FROM: http://unifycommunity.com/wiki/index.php?title=UnitSphere /// </remarks> public static Vector3 GetPointOnCap(float spotAngle, ref UMT.MersenneTwister _rand) { float angle1 = MTRandom.ScaleFloatToRange(_rand.NextSingle(true), 0.0f, Mathf.PI * 2, 0, 1); float angle2 = MTRandom.ScaleFloatToRange(_rand.NextSingle(true), 0.0f, spotAngle * Mathf.Deg2Rad, 0, 1); Vector3 V = new Vector3(Mathf.Sin(angle1), Mathf.Cos(angle1), 0); V *= Mathf.Sin(angle2); V.z = Mathf.Cos(angle2); return(V); }
private void RandomValues() { CleanUp(); DebugStreamer.AddMessage("Returns a pseudo-random number between 0.0 [inclusive] and 1.0 [inclusive]"); DebugStreamer.AddMessage("MTRandom mrand = new MTRandom(seed)"); mrand = new MTRandom(user_seed); DebugStreamer.AddMessage("mrand.value()"); for (int i = 0; i < max_objects; i++) { float x = mrand.value(); float x_position = MTRandom.ScaleFloatToRange(x, -2.0f, 2.0f, 0.0f, 1.0f); GameObject sphere = MakeObject(new Vector3(x_position,x_position,0.0f)); sphere.name = x.ToString(); } }
public static Vector2 Circle(ref UMT.MersenneTwister _rand, MTRandom.Normalization n, float t) { float r; switch (n) { case MTRandom.Normalization.STDNORMAL: r = MTRandom.ScaleFloatToRange((float)NormalDistribution.Normalize(_rand.NextSingle(true), t), 0, Int32.MaxValue, 0, 1); break; case MTRandom.Normalization.POWERLAW: r = (float)PowerLaw.Normalize(_rand.NextSingle(true), t, 0, Int32.MaxValue); break; default: r = (float)_rand.Next(); break; } float _2pi = (float)Math.PI * 2; float a = MTRandom.ScaleFloatToRange(r, 0, _2pi, 0, Int32.MaxValue); return(new Vector2((float)Math.Cos(a), (float)Math.Sin(a))); }