public void UnboundedConeBoundingBox()
        {
            var s   = new shape.Cone();
            var box = s.Bounds();

            Assert.Equal(pt.Point(double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity), box.Minimum);
            Assert.Equal(pt.Point(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity), box.Maximum);
        }
Exemple #2
0
        public void IntersectingConeWithRayParallelOneHalves()
        {
            var s         = new shape.Cone();
            var direction = pt.Vector(0, 1, 1).Normalize();
            var r         = new Ray(pt.Point(0, 0, -1), direction);
            var xs        = s.Intersect(r);

            Assert.Single(xs);
            Assert.Equal(0.35355, xs[0].T, 5);
        }
Exemple #3
0
        public void ComputingNormalVectorCone(double pX, double pY, double pZ, double vX, double vY, double vZ)
        {
            var s = new shape.Cone();

            var point  = pt.Point(pX, pY, pZ);
            var normal = pt.Vector(vX, vY, vZ).Normalize();

            var n = s.NormalAt(point);

            CustomAssert.Equal(normal, n, 5);
        }
        public void BoundedConeBoundingBox()
        {
            var s = new shape.Cone()
            {
                Minimum = -5,
                Maximum = 3
            };

            var box = s.Bounds();

            Assert.Equal(pt.Point(-5, -5, -5), box.Minimum);
            Assert.Equal(pt.Point(5, 3, 5), box.Maximum);
        }
Exemple #5
0
        public void IntersectConeRay(double pX, double pY, double pZ, double vX, double vY, double vZ, double t0, double t1)
        {
            var s = new shape.Cone();

            var origin    = pt.Point(pX, pY, pZ);
            var direction = pt.Vector(vX, vY, vZ).Normalize();

            var ray = new Ray(origin, direction);
            var xs  = s.Intersect(ray);

            Assert.Equal(2, xs.Length);
            Assert.Equal(t0, xs[0].T, 5);
            Assert.Equal(t1, xs[1].T, 5);
        }
Exemple #6
0
        public void IntersectConeEndCap(double pX, double pY, double pZ, double vX, double vY, double vZ, double count)
        {
            var s = new shape.Cone()
            {
                Minimum = -0.5,
                Maximum = 0.5,
                Closed  = true
            };

            var origin    = pt.Point(pX, pY, pZ);
            var direction = pt.Vector(vX, vY, vZ).Normalize();

            var ray = new Ray(origin, direction);
            var xs  = s.Intersect(ray);

            Assert.Equal(count, xs.Length);
        }
Exemple #7
0
        private void IceCreamButton_Click(object sender, RoutedEventArgs e)
        {
            List <shapes.Shape> shapes = new List <shapes.Shape>();

            var a = new patterns.Stripe(RTF.Color.Maroon, RTF.Color.White);

            var cone = new shapes.Cone()
            {
                Transform = transform.Scaling(0.5, 1, 0.5),
                Material  = new RTF.Material()
                {
                    Pattern  = a,
                    Specular = 0
                },
                Maximum = 3,
                Minimum = 0
            };

            shapes.Add(cone);

            var strawberry = new shapes.Sphere()
            {
                Transform = transform.Scaling(2, 2, 2) * transform.Translation(0, 2, 0),
                Material  = new RTF.Material()
                {
                    Pattern    = new patterns.Perturbed(new patterns.Stripe(RTF.Color.Pink, RTF.Color.Red)),
                    Reflective = 0.8,
                    Shininess  = 200
                }
            };

            shapes.Add(strawberry);

            var watch  = System.Diagnostics.Stopwatch.StartNew();
            var canvas = CreateWorld(shapes);

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            canvas.SaveAsPPMFile(FolderPath.Text + $"\\IceCream[{elapsedMs}ms].ppm");
        }
Exemple #8
0
        private List <Intersection> IntersectCaps(Cone cone, Ray ray)
        {
            var xs = new List <Intersection>();

            if (cone.Closed == false || Math.Abs(ray.Direction.Y) <= EPSILON)
            {
                return(xs);
            }

            var t = (cone.Minimum - ray.Origin.Y) / ray.Direction.Y;

            if (CheckCap(ray, t, cone.Minimum))
            {
                xs.Add(new Intersection(t, cone));
            }

            t = (cone.Maximum - ray.Origin.Y) / ray.Direction.Y;
            if (CheckCap(ray, t, cone.Maximum))
            {
                xs.Add(new Intersection(t, cone));
            }

            return(xs);
        }