Ejemplo n.º 1
0
        public void TestBoundingSphere()
        {
            Sphere3 sphere = new Sphere3(
                new Vector3(15.0f, 15.0f, 15.0f), 5.0f
                );

            Sphere3 boundingSphere = sphere.BoundingSphere;

            Assert.AreEqual(
                sphere, boundingSphere,
                "Bounding sphere for sphere is identical to the sphere itself"
                );
        }
Ejemplo n.º 2
0
        public void TestBoundingBox()
        {
            Sphere3 sphere = new Sphere3(
                new Vector3(15.0f, 15.0f, 15.0f), 5.0f
                );

            AxisAlignedBox3 boundingBox = sphere.BoundingBox;

            Assert.AreEqual(
                new Vector3(10.0f, 10.0f, 10.0f), boundingBox.Min,
                "Minimum corner of bounding box correctly determined"
                );
            Assert.AreEqual(
                new Vector3(20.0f, 20.0f, 20.0f), boundingBox.Max,
                "Maximum corner of bounding box correctly determined"
                );
        }
Ejemplo n.º 3
0
        public void TestBoundingSphere()
        {
            AxisAlignedBox3 box = new AxisAlignedBox3(
                new Vector3(10.0f, 10.0f, 10.0f), new Vector3(20.0f, 20.0f, 20.0f)
                );

            Sphere3 boundingSphere = box.BoundingSphere;

            Assert.AreEqual(
                new Vector3(15.0f, 15.0f, 15.0f), boundingSphere.Center,
                "Center of bounding sphere correctly determined"
                );
            Assert.AreEqual(
                (float)Math.Sqrt(75.0f), boundingSphere.Radius,
                "Radius of bounding sphere exactly encloses the box"
                );
        }
Ejemplo n.º 4
0
        public void TestBoundingSphere()
        {
            Cylinder3 testCylinder = new Cylinder3(
                Matrix.CreateTranslation(new Vector3(100.0f, 200.0f, 300.0f)), 10.0f, 20.0f
                );
            Sphere3 boundingSphere = testCylinder.BoundingSphere;

            GeoAssertHelper.AreAlmostEqual(
                new Vector3(100.0f, 200.0f, 300.0f), boundingSphere.Center,
                Specifications.MaximumDeviation, "Center of bounding sphere correctly determined"
                );

            Assert.That(
                boundingSphere.Radius,
                Is.EqualTo(14.142135623730950488016887242097f).Within(
                    Specifications.MaximumDeviation
                    ).Ulps,
                "Radius of bounding sphere exactly encloses the box"
                );
        }
Ejemplo n.º 5
0
        public void TestMassProperties()
        {
            Sphere3 testSphere =
                new Sphere3(new Vector3(100.0f, 100.0f, 100.0f), 20.0f);

            Assert.AreEqual(
                new Vector3(100.0f, 100.0f, 100.0f), testSphere.CenterOfMass,
                "Center of mass is correctly positioned"
                );
            Assert.AreEqual(
                33510.32421875f, testSphere.Mass,
                Specifications.MaximumDeviation,
                "Mass of sphere is exactly determined"
                );
            Assert.AreEqual(
                5026.5482457436692f, testSphere.SurfaceArea,
                Specifications.MaximumDeviation,
                "Surface area of sphere is exactly determined"
                );
        }
Ejemplo n.º 6
0
    public void TestMassProperties() {
      Sphere3 testSphere =
        new Sphere3(new Vector3(100.0f, 100.0f, 100.0f), 20.0f);

      Assert.AreEqual(
        new Vector3(100.0f, 100.0f, 100.0f), testSphere.CenterOfMass,
        "Center of mass is correctly positioned"
      );
      Assert.AreEqual(
        33510.32421875f, testSphere.Mass,
        Specifications.MaximumDeviation,
        "Mass of sphere is exactly determined"
      );
      Assert.AreEqual(
        5026.5482457436692f, testSphere.SurfaceArea,
        Specifications.MaximumDeviation,
        "Surface area of sphere is exactly determined"
      );

    }
Ejemplo n.º 7
0
        public void TestRandomPointOnSurface()
        {
            Sphere3 unitSphere  = new Sphere3(Vector3.Zero, 1.0f);
            Sphere3 innerSphere = new Sphere3(Vector3.Zero, 1.0f - Specifications.HullAccuracy);
            Sphere3 outerSphere = new Sphere3(Vector3.Zero, 1.0f + Specifications.HullAccuracy);

            DefaultRandom random = new DefaultRandom();

            Vector3 total = Vector3.Zero;

            for (int i = 0; i < Specifications.ProbabilisticFunctionSamples; ++i)
            {
                Vector3 point = unitSphere.RandomPointOnSurface(random);

                Assert.IsFalse(
                    innerSphere.Contains(point), "Random point lies on the sphere's hull"
                    );
                Assert.IsTrue(
                    outerSphere.Contains(point), "Random point lies on the sphere's hull"
                    );

                total += point;
            }

            total /= Specifications.ProbabilisticFunctionSamples;

            Assert.AreEqual(
                0.0f, total.X, Specifications.ProbabilisticFunctionDeviation,
                "Random points average on the center of the sphere on the X axis"
                );
            Assert.AreEqual(
                0.0f, total.Y, Specifications.ProbabilisticFunctionDeviation,
                "Random points average on the center of the sphere on the Y axis"
                );
            Assert.AreEqual(
                0.0f, total.Z, Specifications.ProbabilisticFunctionDeviation,
                "Random points average on the center of the sphere on the Z axis"
                );
        }
Ejemplo n.º 8
0
        /// <summary>Determines if the volume will impact on a sphere</summary>
        /// <param name="thisVelocity">Velocity with which this volume is moving</param>
        /// <param name="sphere">Sphere that will be checked for intersection</param>
        /// <returns>The point of first contact, if any</returns>
        /// <remarks>
        ///   <para>
        ///     Conventional tests that resort to stepping often fail to detect collisions
        ///     between fast-moving objects. This impact determination test will always
        ///     detect a collision if it occurs, giving the exact time of the impact.
        ///   </para>
        ///   <para>
        ///     This is a simplified test that assumes a linear trajectory and does
        ///     not take off-center object rotation into account. It is well suited to use
        ///     on two bounding spheres in order to determine if a collision between the
        ///     shape contained is possible at all.
        ///   </para>
        ///   <para>
        ///     Ideas taken from the "Simple Intersection Tests for Games" article
        ///     on gamasutra by Gomez.
        ///   </para>
        /// </remarks>
        public float[] LocateImpact(Vector3 thisVelocity, Sphere3 sphere)
        {
            Vector3 distance = Center - sphere.Center;
            float   radii    = Radius + sphere.Radius;
            float   radii2   = radii * radii;

            // Already inside the other circle
            if (distance.LengthSquared() < radii2)
            {
                return new float[] { 0.0f }
            }
            ;

            float a = thisVelocity.LengthSquared();
            float b = Vector3.Dot(thisVelocity, distance) * 2.0f;
            float c = distance.LengthSquared() - radii2;
            float q = b * b - 4.0f * a * c;

            // If the other sphere is not crossing our location, then no impact will happen
            if (q < 0.0)
            {
                return(null);
            }

            float sq = (float)Math.Sqrt(q);
            float d  = 1.0f / (2.0f * a);
            float r1 = (-b + sq) * d;
            float r2 = (-b - sq) * d;

            if (r1 < r2)
            {
                return new float[] { r1 }
            }
            ;
            else
            {
                return new float[] { r2 }
            };
        }
Ejemplo n.º 9
0
    public void TestMovingSphereIntersection() {
      Sphere3 leftSphere = new Sphere3(new Vector3(0.0f, 0.0f, 0.0f), 10.0f);
      Sphere3 rightSphere = new Sphere3(new Vector3(100.0f, 0.0f, 0.0f), 10.0f);

      Assert.AreEqual(
        new float[] { 0.0f },
        leftSphere.LocateImpact(new Vector3(0.0f, 0.0f, 0.0f), leftSphere),
        "Contact with clone occured immediately"
      );

      Assert.That(
        leftSphere.LocateImpact(new Vector3(200.0f, 0.0f, 0.0f), rightSphere),
        Is.EqualTo(new float[] { 0.4f }).Within(Specifications.MaximumDeviation).Ulps,
        "Fast moving contact with right sphere is determined exactly"
      );

      Assert.That(
        rightSphere.LocateImpact(new Vector3(-200.0f, 0.0f, 0.0f), leftSphere),
        Is.EqualTo(new float[] { 0.4f }).Within(Specifications.MaximumDeviation).Ulps,
        "Fast moving contact with left sphere is determined exactly"
      );
    }
Ejemplo n.º 10
0
        public void TestMovingSphereIntersection()
        {
            Sphere3 leftSphere  = new Sphere3(new Vector3(0.0f, 0.0f, 0.0f), 10.0f);
            Sphere3 rightSphere = new Sphere3(new Vector3(100.0f, 0.0f, 0.0f), 10.0f);

            Assert.AreEqual(
                new float[] { 0.0f },
                leftSphere.LocateImpact(new Vector3(0.0f, 0.0f, 0.0f), leftSphere),
                "Contact with clone occured immediately"
                );

            Assert.That(
                leftSphere.LocateImpact(new Vector3(200.0f, 0.0f, 0.0f), rightSphere),
                Is.EqualTo(new float[] { 0.4f }).Within(Specifications.MaximumDeviation).Ulps,
                "Fast moving contact with right sphere is determined exactly"
                );

            Assert.That(
                rightSphere.LocateImpact(new Vector3(-200.0f, 0.0f, 0.0f), leftSphere),
                Is.EqualTo(new float[] { 0.4f }).Within(Specifications.MaximumDeviation).Ulps,
                "Fast moving contact with left sphere is determined exactly"
                );
        }
Ejemplo n.º 11
0
 /// <summary>Visit a sphere</summary>
 /// <param name="sphere">Sphere to visit</param>
 public abstract void Visit(Sphere3 sphere);
Ejemplo n.º 12
0
 /// <summary>Determines if the volume clips the circle</summary>
 /// <param name="sphere">Circle that will be checked for intersection</param>
 /// <returns>True if the objects overlap</returns>
 public bool Intersects(Sphere3 sphere)
 {
     throw new NotImplementedException("Not implemented yet");
 }
Ejemplo n.º 13
0
 public Sphere3(Sphere3 other)
   : this(other.Center, other.Radius) { }
Ejemplo n.º 14
0
    /// <summary>Determines if the volume will impact on a sphere</summary>
    /// <param name="thisVelocity">Velocity with which this volume is moving</param>
    /// <param name="sphere">Sphere that will be checked for intersection</param>
    /// <returns>The point of first contact, if any</returns>
    /// <remarks>
    ///   <para>
    ///     Conventional tests that resort to stepping often fail to detect collisions
    ///     between fast-moving objects. This impact determination test will always
    ///     detect a collision if it occurs, giving the exact time of the impact.
    ///   </para>
    ///   <para>
    ///     This is a simplified test that assumes a linear trajectory and does
    ///     not take off-center object rotation into account. It is well suited to use
    ///     on two bounding spheres in order to determine if a collision between the
    ///     shape contained is possible at all.
    ///   </para>
    ///   <para>
    ///     Ideas taken from the "Simple Intersection Tests for Games" article
    ///     on gamasutra by Gomez.
    ///   </para>
    /// </remarks>
    public float[] LocateImpact(Vector3 thisVelocity, Sphere3 sphere) {
      Vector3 distance = Center - sphere.Center;
      float radii = Radius + sphere.Radius;
      float radii2 = radii * radii;

      // Already inside the other circle 
      if(distance.LengthSquared() < radii2)
        return new float[] { 0.0f };

      float a = thisVelocity.LengthSquared();
      float b = Vector3.Dot(thisVelocity, distance) * 2.0f;
      float c = distance.LengthSquared() - radii2;
      float q = b * b - 4.0f * a * c;

      // If the other sphere is not crossing our location, then no impact will happen
      if(q < 0.0)
        return null;

      float sq = (float)Math.Sqrt(q);
      float d = 1.0f / (2.0f * a);
      float r1 = (-b + sq) * d;
      float r2 = (-b - sq) * d;

      if(r1 < r2)
        return new float[] { r1 };
      else
        return new float[] { r2 };
    }
Ejemplo n.º 15
0
 /// <summary>Determines if the volume clips the circle</summary>
 /// <param name="sphere">Circle that will be checked for intersection</param>
 /// <returns>True if the objects overlap</returns>
 public bool Intersects(Sphere3 sphere) {
   return Collisions.SphereSphereCollider.CheckContact(
     this.Center, this.Radius, sphere.Center, sphere.Radius
   );
 }
Ejemplo n.º 16
0
 /// <summary>Determines if the volume clips the circle</summary>
 /// <param name="sphere">Circle that will be checked for intersection</param>
 /// <returns>True if the objects overlap</returns>
 public bool Intersects(Sphere3 sphere)
 {
     return(Collisions.ObbSphereCollider.CheckContact(
                this.Transform, this.Extents, sphere.Center, sphere.Radius
                ));
 }
Ejemplo n.º 17
0
 /// <summary>Determines if the volume clips the circle</summary>
 /// <param name="sphere">Circle that will be checked for intersection</param>
 /// <returns>True if the objects overlap</returns>
 public bool Intersects(Sphere3 sphere)
 {
     return(Collisions.MeshSphereCollider.CheckContact(
                this, sphere.Center, sphere.Radius
                ));
 }
Ejemplo n.º 18
0
 public Sphere3(Sphere3 other)
     : this(other.Center, other.Radius)
 {
 }
Ejemplo n.º 19
0
    public void TestBoundingBox() {
      Sphere3 sphere = new Sphere3(
        new Vector3(15.0f, 15.0f, 15.0f), 5.0f
      );

      AxisAlignedBox3 boundingBox = sphere.BoundingBox;

      Assert.AreEqual(
        new Vector3(10.0f, 10.0f, 10.0f), boundingBox.Min,
        "Minimum corner of bounding box correctly determined"
      );
      Assert.AreEqual(
        new Vector3(20.0f, 20.0f, 20.0f), boundingBox.Max,
        "Maximum corner of bounding box correctly determined"
      );
    }
Ejemplo n.º 20
0
 /// <summary>Determines if the volume clips the circle</summary>
 /// <param name="sphere">Circle that will be checked for intersection</param>
 /// <returns>True if the objects overlap</returns>
 public bool Intersects(Sphere3 sphere)
 {
     return(Collisions.AabbSphereCollider.CheckContact(
                this.Min, this.Max, sphere.Center, sphere.Radius
                ));
 }
Ejemplo n.º 21
0
 /// <summary>Determines if the volume clips the circle</summary>
 /// <param name="sphere">Circle that will be checked for intersection</param>
 /// <returns>True if the objects overlap</returns>
 public bool Intersects(Sphere3 sphere) {
   return Collisions.AabbSphereCollider.CheckContact(
     this.Min, this.Max, sphere.Center, sphere.Radius
   );
 }
Ejemplo n.º 22
0
    public void TestRandomPointOnSurface() {
      Sphere3 unitSphere = new Sphere3(Vector3.Zero, 1.0f);
      Sphere3 innerSphere = new Sphere3(Vector3.Zero, 1.0f - Specifications.HullAccuracy);
      Sphere3 outerSphere = new Sphere3(Vector3.Zero, 1.0f + Specifications.HullAccuracy);

      DefaultRandom random = new DefaultRandom();

      Vector3 total = Vector3.Zero;
      for(int i = 0; i < Specifications.ProbabilisticFunctionSamples; ++i) {
        Vector3 point = unitSphere.RandomPointOnSurface(random);

        Assert.IsFalse(
          innerSphere.Contains(point), "Random point lies on the sphere's hull"
        );
        Assert.IsTrue(
          outerSphere.Contains(point), "Random point lies on the sphere's hull"
        );

        total += point;
      }

      total /= Specifications.ProbabilisticFunctionSamples;

      Assert.AreEqual(
        0.0f, total.X, Specifications.ProbabilisticFunctionDeviation,
        "Random points average on the center of the sphere on the X axis"
      );
      Assert.AreEqual(
        0.0f, total.Y, Specifications.ProbabilisticFunctionDeviation,
        "Random points average on the center of the sphere on the Y axis"
      );
      Assert.AreEqual(
        0.0f, total.Z, Specifications.ProbabilisticFunctionDeviation,
        "Random points average on the center of the sphere on the Z axis"
      );
      
    }
Ejemplo n.º 23
0
    public void TestBoundingSphere() {
      Sphere3 sphere = new Sphere3(
        new Vector3(15.0f, 15.0f, 15.0f), 5.0f
      );

      Sphere3 boundingSphere = sphere.BoundingSphere;
      Assert.AreEqual(
        sphere, boundingSphere,
        "Bounding sphere for sphere is identical to the sphere itself"
      );
    }
Ejemplo n.º 24
0
 /// <summary>Determines where the range clips a sphere</summary>
 /// <param name="sphere">Sphere that will be checked for intersection</param>
 /// <returns>The times at which the range enters or leaves the volume</returns>
 public LineContacts FindContacts(Sphere3 sphere) {
   return Collisions.Ray3Sphere3Collider.FindContacts(
     Origin, Direction, sphere.Center, sphere.Radius
   );
 }
Ejemplo n.º 25
0
 /// <summary>Determines if the volume clips the circle</summary>
 /// <param name="sphere">Circle that will be checked for intersection</param>
 /// <returns>True if the objects overlap</returns>
 public bool Intersects(Sphere3 sphere) {
   return Collisions.ObbSphereCollider.CheckContact(
     this.Transform, this.Extents, sphere.Center, sphere.Radius
   );
 }
Ejemplo n.º 26
0
 /// <summary>Determines where the range clips a sphere</summary>
 /// <param name="sphere">Sphere that will be checked for intersection</param>
 /// <returns>The times at which the range enters or leaves the volume</returns>
 public LineContacts FindContacts(Sphere3 sphere) {
   throw new NotImplementedException();
   /*
   return filterContacts(
     Collisions.Line3Sphere3Collider.FindContacts(
       this.Start, this.End - this.Start, sphere.Center, sphere.Radius
     )
   );
   */
 }
Ejemplo n.º 27
0
 /// <summary>Visit a sphere</summary>
 /// <param name="sphere">Sphere to visit</param>
 public abstract void Visit(Sphere3 sphere);
Ejemplo n.º 28
0
 /// <summary>Determines if the volume clips the circle</summary>
 /// <param name="sphere">Circle that will be checked for intersection</param>
 /// <returns>True if the objects overlap</returns>
 public bool Intersects(Sphere3 sphere) {
   throw new NotImplementedException("Not implemented yet");
 }