/// <summary> Get the probability of a <paramref name="sample"/> in the <see cref="RecursiveDistanceDistribution"/> </summary>
 /// <param name="sample">The sample to get the probability for</param>
 /// <returns>The probability of the <paramref name="sample"/></returns>
 public double ProbabilityDensity(Position1 sample)
 {
     if (!(this as IDistanceDistribution).Contains(sample))
     {
         return(0);
     }
     else
     {
         double pLeft  = Left.ProbabilityDensity(sample);
         double pRight = Right.ProbabilityDensity(sample);
         if (pLeft <= 0 && pRight <= 0)
         {
             return(0);
         }
         else if (pLeft <= 0)
         {
             return((1 - Left.CumulativeProbability(sample)) * pRight);
         }
         else if (pRight <= 0)
         {
             return((1 - Right.CumulativeProbability(sample)) * pLeft);
         }
         else
         {
             return((1 - Left.CumulativeProbability(sample)) * pRight + (1 - Right.CumulativeProbability(sample)) * pLeft);
         }
     }
 }
示例#2
0
        /// <summary> Position the <see cref="IFilm"/> according to the <paramref name="camera"/> </summary>
        /// <param name="camera">The <see cref="ICamera"/> to position for</param>
        public void PositionFilm(object?_, ICamera camera)
        {
            Position2 size     = new(camera.AspectRatio, 1);
            Position1 distance = 0.5f * Rectangle.Width.Vector / ((float)Math.Tan(camera.HorizontalFOV / 360 * Math.PI));

            Rectangle = new(camera.Position + camera.ViewDirection * distance, size, camera.Rotation);
        }
示例#3
0
        public void Transform()
        {
            var c = new DataCube3 <int, int, int, int>();

            c.Set(0, 0, 0, 1);
            c.Set(0, 0, 1, 2);
            c.Set(0, 1, 0, 3);
            c.Set(0, 1, 1, 4);
            c.Set(1, 0, 0, 10);
            c.Set(1, 0, 1, 20);
            c.Set(1, 1, 0, 30);
            c.Set(1, 1, 1, 40);

            var sum = c.Transform(_ => Position0.Create(), (a, b) => a + b);

            Assert.Equal(1 + 2 + 3 + 4 + 10 + 20 + 30 + 40, sum.Value.Get());

            var Position = c.Transform(_ => Position0.Create(), (a, b) => a * b);

            Assert.Equal(1 * 2 * 3 * 4 * 10 * 20 * 30 * 40, Position.Value.Get());

            var firstDimensionSums = c.Transform(p => Position1.Create(p.ProductValue1), (a, b) => a + b);

            Assert.Equal(2, firstDimensionSums.Values.Count());
            Assert.Equal(1 + 2 + 3 + 4, firstDimensionSums.Get(0).Get());
            Assert.Equal(10 + 20 + 30 + 40, firstDimensionSums.Get(1).Get());
        }
示例#4
0
        /// <summary> Intersect the <see cref="AxisAlignedBox"/> by a <paramref name="ray"/>.
        /// Using Amy Williams's "An Efficient and Robust Ray–Box Intersection" Algorithm </summary>
        /// <param name="ray">The <see cref="Ray"/> to intersect the <see cref="IAxisAlignedBox"/> with</param>
        /// <returns>Whether and when the <see cref="Ray"/> intersects the <see cref="IAxisAlignedBox"/></returns>
        public IEnumerable <Position1> IntersectDistances(IRay ray)
        {
            Position1 tmin = (Bounds[ray.Sign.X].X - ray.Origin.X) * ray.InvDirection.X;
            Position1 tmax = (Bounds[1 - ray.Sign.X].X - ray.Origin.X) * ray.InvDirection.X;

            Position1 tymin = (Bounds[ray.Sign.Y].Y - ray.Origin.Y) * ray.InvDirection.Y;
            Position1 tymax = (Bounds[1 - ray.Sign.Y].Y - ray.Origin.Y) * ray.InvDirection.Y;

            if ((tmin > tymax) || (tmax < tymin))
            {
                yield break;
            }
            tmin = Position1.Max(tmin, tymin);
            tmax = Position1.Min(tmax, tymax);

            Position1 tzmin = (Bounds[ray.Sign.Z].Z - ray.Origin.Z) * ray.InvDirection.Z;
            Position1 tzmax = (Bounds[1 - ray.Sign.Z].Z - ray.Origin.Z) * ray.InvDirection.Z;

            if ((tmin > tzmax) || (tmax < tzmin))
            {
                yield break;
            }
            yield return(Position1.Max(tmin, tzmin));

            yield return(Position1.Min(tmax, tzmax));
        }
        public void GetPosition(object p)
        {
            switch (p.ToString())
            {
            case "1":
                Position1 = (double)ActPos1.Value;
                Inifile.INIWriteValue(iniPosition, "Axis1", "Position1", Position1.ToString());
                break;

            case "2":
                Position2 = (double)ActPos1.Value;
                Inifile.INIWriteValue(iniPosition, "Axis1", "Position2", Position2.ToString());
                break;

            case "3":
                Position3 = (double)ActPos1.Value;
                Inifile.INIWriteValue(iniPosition, "Axis1", "Position3", Position3.ToString());
                break;

            case "4":
                Position4 = (double)ActPos1.Value;
                Inifile.INIWriteValue(iniPosition, "Axis1", "Position4", Position4.ToString());
                break;

            case "5":
                Position5 = (double)ActPos1.Value;
                Inifile.INIWriteValue(iniPosition, "Axis1", "Position5", Position5.ToString());
                break;
            }
        }
示例#6
0
    public static long Solve1(string[] lines)
    {
        Position1 pos = lines
                        .Select(Parse)
                        .Aggregate(new Position1(0, 0), (acc, inst) => acc.Move(inst));

        return(pos.X * pos.Y);
    }
 /// <summary>
 /// Makes the contents of this message dump to a easy to understand string
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(string.Format(
                "{0} - {1:1;0;0}{2:1;0;0}",
                ErrorCode,
                Position1.GetHashCode(),
                Position2.GetHashCode()));
 }
示例#8
0
        public CCPoint GetWorldPosition(float hexRadius, float hexMargin)
        {
            var p1     = Position1.GetWorldPosition(hexRadius, hexMargin);
            var p2     = Position2.GetWorldPosition(hexRadius, hexMargin);
            var p3     = Position3.GetWorldPosition(hexRadius, hexMargin);
            var result = (p1 + p2 + p3) / 3;

            return(result);
        }
示例#9
0
        //public NavMeshAABB AABB1 { get; set; }
        //public NavMeshAABB AABB2 { get; set; }

        public override string ToString()
        {
            return(Unknown_00h.ToString() + ", " +
                   Position1.ToString() + ", " + Position2.ToString() + ", " +
                   Unknown_10h.ToString() + ", " + Unknown_12h.ToString() + ", " +
                   Unknown_14h.ToString() + ", " + Unknown_16h.ToString() + ", " +
                   Unknown_18h.ToString() + ", " + Unknown_1Ah.ToString());
            //AABB1.ToString() + ", " + AABB2.ToString();
        }
示例#10
0
        public Position1 Sample(Random random)
        {
            Position1 distance = Domain.Entry + (float)distribution.InverseCumulativeDistribution(random.NextDouble());

            if (float.IsNaN(distance))
            {
                throw new InvalidOperationException($"Exponential distribution returned invalid distance {distance}");
            }
            return(distance <= Domain.Exit ? distance : Position1.PositiveInfinity);
        }
示例#11
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Position1.GetHashCode();
         hashCode = (hashCode * 397) ^ Position2.GetHashCode();
         hashCode = (hashCode * 397) ^ Position3.GetHashCode();
         return(hashCode);
     }
 }
        public double CumulativeProbability(Position1 sample)
        {
            var    relevant   = distributions.TakeWhile(d => d.Domain.Entry <= sample);
            double inverseCdf = 1d;

            foreach (var d in relevant)
            {
                inverseCdf *= 1d - d.CumulativeProbability(sample);
            }
            return(1d - inverseCdf);
        }
 /// <summary> Get the cummulative probability of a <paramref name="sample"/> in the <see cref="RecursiveDistanceDistribution"/> </summary>
 /// <param name="sample">The sample to get the cummulative probability for</param>
 /// <returns>The cummulative probability of the <paramref name="sample"/></returns>
 public double CumulativeProbability(Position1 sample)
 {
     if (sample < Domain.Entry)
     {
         return(0);
     }
     else
     {
         double l = Left.CumulativeProbability(sample);
         double r = Right.CumulativeProbability(sample);
         return(l + r - l * r);
     }
 }
        /// <summary> Sample the <see cref="IRecursiveDistanceDistribution{T}"/> </summary>
        /// <param name="random">The <see cref="Random"/> to use for sampling</param>
        /// <returns>A <paramref name="random"/> <see cref="Position1"/></returns>
        public Position1 Sample(Random random)
        {
            Position1 left = Left.Sample(random);

            if (left.CompareTo(Right.Domain.Entry) <= 0)
            {
                return(left);
            }
            else
            {
                return(Utils.Min(left, Right.Sample(random)));
            }
        }
示例#15
0
 public IDistanceDistribution?GetDistances(IRay ray, ISpectrum spectrum, IInterval interval)
 {
     if (ray.WithinBounds(interval.Entry))
     {
         Position1 entry = Position1.Max(0, ((float)interval.Entry).Decrement(IntervalLength));
         Position1 exit  = interval.Entry;
         return(new UniformInterval(new Interval(entry, exit)));
     }
     else
     {
         return(null);
     }
 }
示例#16
0
        // TODO Optimize
        public IEnumerable <HexagonNode> GetAdjacentHexagonNodes()
        {
            var positions = new[] { Position1, Position2, Position3 };

            var adj1 = Position1.GetAdjacentHexagonPositions();
            var adj2 = Position2.GetAdjacentHexagonPositions();
            var adj3 = Position3.GetAdjacentHexagonPositions();

            var new3   = adj1.Intersect(adj2).First(a => !positions.Contains(a));
            var new2   = adj1.Intersect(adj3).First(a => !positions.Contains(a));
            var new1   = adj2.Intersect(adj3).First(a => !positions.Contains(a));
            var result = new[] { new HexagonNode(new1, Position2, Position3), new HexagonNode(Position1, new2, Position3), new HexagonNode(Position1, Position2, new3) };

            return(result);
        }
示例#17
0
 public double CumulativeProbability(Position1 sample)
 {
     if (sample <= Domain.Entry)
     {
         return(0);
     }
     else if (sample <= Domain.Exit)
     {
         return(distribution.CumulativeDistribution(((float)sample).Previous() - Domain.Entry));
     }
     else
     {
         return(distribution.CumulativeDistribution(Domain.CoveredArea));
     }
 }
        public double ProbabilityDensity(Position1 sample)
        {
            double probabilityDensity = 0;
            double cdf = CumulativeProbability(sample);

            if (cdf == 1d)
            {
                return(0f);
            }
            var contains = distributions.TakeWhile(d => d.Domain.Entry <= sample);

            foreach (var current in contains)
            {
                double currentCdf = current.CumulativeProbability(sample);
                double othersCdf  = (currentCdf - cdf) / (currentCdf - 1);
                probabilityDensity += current.Probability(sample) * (1 - othersCdf);
            }
            return(probabilityDensity);
        }
        public Position1 Sample(Random random)
        {
            Position1 smallestSample = Position1.PositiveInfinity;

            foreach (var d in distributions)
            {
                if (d.Domain.Entry > smallestSample)
                {
                    break;
                }
                else
                {
                    Position1 sample = d.Sample(random);
                    if (smallestSample > sample)
                    {
                        smallestSample = sample;
                    }
                }
            }
            return(smallestSample);
        }
示例#20
0
        /// <summary> Clip the <see cref="AxisAlignedBox"/> by a <paramref name="plane"/> </summary>
        /// <param name="plane">The <see cref="AxisAlignedPlane"/> to clip the <see cref="AxisAlignedBox"/> with</param>
        /// <returns>A new clipped <see cref="AxisAlignedBox"/> if it's not clipped entirely</returns>
        public IEnumerable <AxisAlignedBox> Clip(AxisAlignedPlane plane)
        {
            Position3 minCorner = MinCorner;
            Position3 maxCorner = MaxCorner;

            if (plane.Normal == Normal3.UnitX)
            {
                minCorner = new(Position1.Max(MinCorner.X, plane.Position.X), MinCorner.Y, MinCorner.Z);
            }
            else if (plane.Normal == -Normal3.UnitX)
            {
                maxCorner = new(Position1.Min(MinCorner.X, plane.Position.X), MaxCorner.Y, MaxCorner.Z);
            }
            else if (plane.Normal == Normal3.UnitY)
            {
                minCorner = new(MinCorner.X, Position1.Max(MinCorner.Y, plane.Position.Y), MinCorner.Z);
            }
            else if (plane.Normal == -Normal3.UnitY)
            {
                maxCorner = new(MaxCorner.X, Position1.Min(MaxCorner.Y, plane.Position.Y), MaxCorner.Z);
            }
            else if (plane.Normal == Normal3.UnitZ)
            {
                minCorner = new(MinCorner.X, MinCorner.Y, Position1.Max(MinCorner.Z, plane.Position.Z));
            }
            else if (plane.Normal == -Normal3.UnitZ)
            {
                maxCorner = new(MaxCorner.X, MaxCorner.Y, Position1.Min(MaxCorner.Z, plane.Position.Z));
            }
            if (minCorner == MinCorner && maxCorner == MaxCorner)
            {
                yield return(this);
            }
            else if (minCorner.X < maxCorner.X && minCorner.Y < maxCorner.Y && minCorner.Z < maxCorner.Z)
            {
                yield return(new AxisAlignedBox(minCorner, maxCorner));
            }
        }
示例#21
0
        public WeightedPMF <IPrimitive> GetPrimitives(Position1 sample)
        {
            Debug.Assert(DistanceDistribution.Contains(sample));
            List <(WeightedPMF <IPrimitive>, double)> pmfs = new();
            double cdf      = DistanceDistribution.CumulativeProbability(sample);
            var    contains = Queries.Where(d => d.DistanceDistribution.Contains(sample));

            if (contains.Count() == 1)
            {
                IDistanceQuery query    = contains.First();
                double         queryCdf = query.DistanceDistribution.CumulativeProbability(sample);
                if (queryCdf == 1 || cdf == queryCdf)
                {
                    return(query.GetPrimitives(sample));
                }
                double othersCdf = (queryCdf - cdf) / (queryCdf - 1);
                return(new WeightedPMF <IPrimitive>((query.GetPrimitives(sample), othersCdf)));
            }
            else
            {
                foreach (var query in contains)
                {
                    WeightedPMF <IPrimitive> pmf = query.GetPrimitives(sample);
                    double queryCdf = query.DistanceDistribution.CumulativeProbability(sample);
                    if (queryCdf == 1)
                    {
                        return(pmf);
                    }
                    double othersCdf          = (queryCdf - cdf) / (queryCdf - 1);
                    double probabilityDensity = query.DistanceDistribution.Probability(sample) * (1 - othersCdf);
                    if (probabilityDensity > 0)
                    {
                        pmfs.Add((pmf, probabilityDensity));
                    }
                }
                return(new WeightedPMF <IPrimitive>(pmfs.ToArray()));
            }
        }
示例#22
0
 /// <summary> Get the material density at the specified <paramref name="distance"/> </summary>
 /// <param name="distance">The distance to get the material density at</param>
 /// <returns>The material density at the specified <paramref name="distance"/></returns>
 public double MaterialDensity(Position1 distance) => Domain.Includes(distance) ? Density : 0d;
示例#23
0
 /// <summary> Create a new <see cref="Interval"/> </summary>
 /// <param name="entry">The entry point of the <see cref="Interval"/></param>
 /// <param name="exit">The exit point of the <see cref="Interval"/></param>
 public Interval(Position1 entry, Position1 exit)
 {
     Debug.Assert(!float.IsNaN(entry) && !float.IsNaN(exit));
     Entry = entry;
     Exit  = exit;
 }
示例#24
0
 public Position3 GetPosition(IRay ray, Position1 distance, IShape shape)
 {
     return(ray.Travel(distance));
 }
示例#25
0
 public WeightedPMF <IPrimitive> GetPrimitives(Position1 sample) => new((Primitive, DistanceDistribution.ProbabilityDensity(sample)));
示例#26
0
 public double ProbabilityDensity(Position1 sample)
 {
     return(Domain.Includes(sample) ? distribution.Density(sample - Domain.Entry) : 0);
 }
示例#27
0
 public Point1(Position1 position, Normal1 normal)
 {
     Position = position;
     Normal   = normal;
 }
示例#28
0
 public double CumulativeProbability(Position1 sample) => sample > Distance ? 1d : 0d;
示例#29
0
        /// <inheritdoc />
        protected override void OnRender()
        {
            ImGui.SetNextWindowPos(new Vector2(10.0f, 100.0f));
            ImGui.SetNextWindowSize(new Vector2(200.0f, 700.0f));
            ImGui.Begin("Tuning", ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize);

            ImGui.Separator();

            ImGui.PushItemWidth(ImGui.GetWindowWidth() * 0.5f);

            const ImGuiComboFlags comboFlags = 0;

            string[] bendModels    = { "Spring", "PBD Ang", "XPBD Ang", "PBD Dist", "PBD Height" };
            string[] stretchModels = { "PBD", "XPBD" };

            ImGui.Text("Rope 1");

            var bendModel1 = (int)Tuning1.BendingModel;

            if (ImGui.BeginCombo("Bend Model##1", bendModels[bendModel1], comboFlags))
            {
                for (var i = 0; i < bendModels.Length; ++i)
                {
                    var isSelected = bendModel1 == i;
                    if (ImGui.Selectable(bendModels[i], isSelected))
                    {
                        bendModel1           = i;
                        Tuning1.BendingModel = (BendingModel)i;
                    }

                    if (isSelected)
                    {
                        ImGui.SetItemDefaultFocus();
                    }
                }

                ImGui.EndCombo();
            }

            ImGui.SliderFloat("Damping##B1", ref Tuning1.BendDamping, 0.0f, 4.0f, "%.1f");
            ImGui.SliderFloat("Hertz##B1", ref Tuning1.BendHertz, 0.0f, 60.0f, "%.0f");
            ImGui.SliderFloat("Stiffness##B1", ref Tuning1.BendStiffness, 0.0f, 1.0f, "%.1f");

            ImGui.Checkbox("Isometric##1", ref Tuning1.Isometric);
            ImGui.Checkbox("Fixed Mass##1", ref Tuning1.FixedEffectiveMass);
            ImGui.Checkbox("Warm Start##1", ref Tuning1.WarmStart);

            var stretchModel1 = (int)Tuning1.StretchingModel;

            if (ImGui.BeginCombo("Stretch Model##1", stretchModels[stretchModel1], comboFlags))
            {
                for (var i = 0; i < stretchModels.Length; ++i)
                {
                    var isSelected = stretchModel1 == i;
                    if (ImGui.Selectable(stretchModels[i], isSelected))
                    {
                        stretchModel1           = i;
                        Tuning1.StretchingModel = (StretchingModel)i;
                    }

                    if (isSelected)
                    {
                        ImGui.SetItemDefaultFocus();
                    }
                }

                ImGui.EndCombo();
            }

            ImGui.SliderFloat("Damping##S1", ref Tuning1.StretchDamping, 0.0f, 4.0f, "%.1f");
            ImGui.SliderFloat("Hertz##S1", ref Tuning1.StretchHertz, 0.0f, 60.0f, "%.0f");
            ImGui.SliderFloat("Stiffness##S1", ref Tuning1.StretchStiffness, 0.0f, 1.0f, "%.1f");

            ImGui.SliderInt("Iterations##1", ref Iterations1, 1, 100, "%d");

            ImGui.Separator();

            ImGui.Text("Rope 2");

            var bendModel2 = (int)Tuning2.BendingModel;

            if (ImGui.BeginCombo("Bend Model##2", bendModels[bendModel2], comboFlags))
            {
                for (var i = 0; i < bendModels.Length; ++i)
                {
                    var isSelected = bendModel2 == i;
                    if (ImGui.Selectable(bendModels[i], isSelected))
                    {
                        bendModel2           = i;
                        Tuning2.BendingModel = (BendingModel)i;
                    }

                    if (isSelected)
                    {
                        ImGui.SetItemDefaultFocus();
                    }
                }

                ImGui.EndCombo();
            }

            ImGui.SliderFloat("Damping##", ref Tuning2.BendDamping, 0.0f, 4.0f, "%.1f");
            ImGui.SliderFloat("Hertz##", ref Tuning2.BendHertz, 0.0f, 60.0f, "%.0f");
            ImGui.SliderFloat("Stiffness##", ref Tuning2.BendStiffness, 0.0f, 1.0f, "%.1f");

            ImGui.Checkbox("Isometric##2", ref Tuning2.Isometric);
            ImGui.Checkbox("Fixed Mass##2", ref Tuning2.FixedEffectiveMass);
            ImGui.Checkbox("Warm Start##2", ref Tuning2.WarmStart);

            var stretchModel2 = (int)Tuning2.StretchingModel;

            if (ImGui.BeginCombo("Stretch Model##2", stretchModels[stretchModel2], comboFlags))
            {
                for (var i = 0; i < stretchModels.Length; ++i)
                {
                    var isSelected = stretchModel2 == i;
                    if (ImGui.Selectable(stretchModels[i], isSelected))
                    {
                        stretchModel2           = i;
                        Tuning2.StretchingModel = (StretchingModel)i;
                    }

                    if (isSelected)
                    {
                        ImGui.SetItemDefaultFocus();
                    }
                }

                ImGui.EndCombo();
            }

            ImGui.SliderFloat("Damping##S2", ref Tuning2.StretchDamping, 0.0f, 4.0f, "%.1f");
            ImGui.SliderFloat("Hertz##S2", ref Tuning2.StretchHertz, 0.0f, 60.0f, "%.0f");
            ImGui.SliderFloat("Stiffness##S2", ref Tuning2.StretchStiffness, 0.0f, 1.0f, "%.1f");

            ImGui.SliderInt("Iterations##2", ref Iterations2, 1, 100, "%d");

            ImGui.Separator();

            ImGui.SliderFloat("Speed", ref Speed, 10.0f, 100.0f, "%.0f");

            if (ImGui.Button("Reset"))
            {
                Position1.Set(-5.0f, 15.0f);
                Position2.Set(5.0f, 15.0f);
                Rope1.Reset(Position1);
                Rope2.Reset(Position2);
            }

            ImGui.PopItemWidth();

            ImGui.End();

            Rope1.Draw(Drawer);
            Rope2.Draw(Drawer);

            DrawString("Press comma and period to move left and right");
            base.OnRender();
        }
示例#30
0
 public Position3 GetPosition(IRay ray, Position1 distance, IShape shape)
 {
     return(shape.IntersectPosition(ray, distance));
 }