private static RealVector GenerateRandomInSpere(RealVector currentPoint, double radius, Area area) { RealVector normallyDistributed = gorn.GetNormalVector(area.ToDictionary(kvp => kvp.Key, kvp => Tuple.Create(0.0, 1.0))); var r = Math.Sqrt(normallyDistributed.Elements.Values.Select(v => v * v).Sum()); RealVector shift = (normallyDistributed * (gorn.GetContinuousUniform(0.0, radius) / r)).Elements; RealVector generatedPoint = (currentPoint + shift).Elements; return(generatedPoint.Constrain(area)); }
public static void TestConstrain() { RealVector r1 = v1 .Constrain(new Dictionary <string, Tuple <double, double> > { { "x", Tuple.Create(-1.0, 0.0) } }) .Constrain(new Dictionary <string, Tuple <double, double> > { { "y", Tuple.Create(3.0, 10.0) } }) .Constrain(new Dictionary <string, Tuple <double, double> > { { "z", Tuple.Create(-5.0, 5.0) } }); RealVector r2 = new Dictionary <string, double> { { "x", 0.0 }, { "y", 3.0 }, { "z", 3.0 } }; Assert.True(r1 == r2); }