public static double NextBell(this Random rand, RandomBellArgs args) { double retVal = BezierUtil.GetPoint(rand.NextDouble(), args.Bezier).Y; if (retVal < 0) { retVal = 0; } else if (retVal > 1) { retVal = 1; } return(retVal); }
/// <summary> /// The percent will go to 1/max to max /// </summary> public static double NextBellPercent(this Random rand, RandomBellArgs args, double max) { // Get a value from 0 to 1 (the bell args could be anything, but it would make sense for this method if it's centered on .5) double retVal = rand.NextBell(args); // Adjust to centered at zero. Multiply by two so it goes -1 to 1. Then multiply by max-1 so it goes -max-1 to max-1 // (the 1 gets added in the next step) retVal = (retVal - .5) * (2 * (max - 1)); // Turn into a multiplier if (retVal < 0) { retVal = 1 / (1 + Math.Abs(retVal)); } else { retVal += 1; } return(retVal); }
public static double NextBell(RandomBellArgs args) { return StaticRandom.GetRandomForThread().NextBell(args); }
/// <summary> /// The percent will go to 1/max to max /// </summary> public static double NextBellPercent(this Random rand, RandomBellArgs args, double max) { // Get a value from 0 to 1 (the bell args could be anything, but it would make sense for this method if it's centered on .5) double retVal = rand.NextBell(args); // Adjust to centered at zero. Multiply by two so it goes -1 to 1. Then multiply by max-1 so it goes -max-1 to max-1 // (the 1 gets added in the next step) retVal = (retVal - .5) * (2 * (max - 1)); // Turn into a multiplier if (retVal < 0) { retVal = 1 / (1 + Math.Abs(retVal)); } else { retVal += 1; } return retVal; }
public static double NextBell(this Random rand, RandomBellArgs args) { double retVal = BezierUtil.GetPoint(rand.NextDouble(), args.Bezier).Y; if (retVal < 0) retVal = 0; else if (retVal > 1) retVal = 1; return retVal; }
private void DrawBellArms() { #region OLD //var controlPoints = new List<Tuple<Point, Point>>(); //// Arm1 //if (!trkBellArmsLeftLen.Value.IsNearZero()) //{ // Vector arm1 = new Vector(1, 1).ToUnit() * trkBellArmsLeftLen.Value; // arm1 = arm1. // ToVector3D(). // GetRotatedVector(new Vector3D(0, 0, -1), trkBellArmsLeftAngle.Value). // ToVector2D(); // controlPoints.Add(Tuple.Create(new Point(0, 0), arm1.ToPoint())); //} //// Arm2 //if (!trkBellArmsRightLen.Value.IsNearZero()) //{ // Vector arm2 = new Vector(-1, -1).ToUnit() * trkBellArmsRightLen.Value; // arm2 = arm2. // ToVector3D(). // GetRotatedVector(new Vector3D(0, 0, -1), trkBellArmsRightAngle.Value). // ToVector2D(); // Point point = new Point(1, 1); // controlPoints.Add(Tuple.Create(point, point + arm2)); //} //// Bezier //Point3D[] controlPoints3D = controlPoints. // Select(o => o.Item2.ToPoint3D()). // ToArray(); //BezierSegment3D bezier = new BezierSegment3D(0, 1, controlPoints3D, new[] { new Point3D(0, 0, 0), new Point3D(1, 1, 0) }); #endregion RandomBellArgs bezier = new RandomBellArgs(trkBellArmsLeftLen.Value, trkBellArmsLeftAngle.Value, trkBellArmsRightLen.Value, trkBellArmsRightAngle.Value); // Points Random rand = StaticRandom.GetRandomForThread(); IEnumerable<double> samples = Enumerable.Range(0, 75000). //Select(o => BezierUtil.GetPoint(rand.NextDouble(), bezier).Y); Select(o => rand.NextBell(bezier)); IEnumerable<Point> idealLine = BezierUtil.GetPoints(100, bezier.Bezier). Select(o => o.ToPoint2D()); // Draw DrawGraph(samples, idealLine); Rect bounds = GetBounds(); if (!trkBellArmsLeftLen.Value.IsNearZero()) { Point from = GetScaledPoint(bezier.Bezier.EndPoint0, bounds); Point to = GetScaledPoint(bezier.Bezier.ControlPoints[0], bounds); AddLine(from, to, _brushLightBlue); } if (!trkBellArmsRightLen.Value.IsNearZero()) { Point from = GetScaledPoint(bezier.Bezier.EndPoint1, bounds); Point to = GetScaledPoint(bezier.Bezier.ControlPoints[bezier.Bezier.ControlPoints.Length - 1], bounds); AddLine(from, to, _brushLightBlue); } // Report coords lblBellValues.Text = GetBellArmValues(); lblBellCtrlPoints.Text = GetBellPoints(bezier.Bezier.ControlPoints.Select(o => o.ToPoint2D())); }
public static double NextBell(RandomBellArgs args) { return(StaticRandom.GetRandomForThread().NextBell(args)); }