public void HandlesSmallerTheta()
        {
            var sphereCoord1 = new SphereCoordinate(-Math.PI, 0);
            var sphereCoord2 = new SphereCoordinate(-2 * Math.PI, 0);

            Assert.AreEqual(new SphereCoordinate(Math.PI, 0), sphereCoord1);
            Assert.AreEqual(new SphereCoordinate(0, Math.PI), sphereCoord2);
        }
        public void HandlesSmallerTheta()
        {
            var sphereCoord1 = new SphereCoordinate(-Math.PI, 0);
            var sphereCoord2 = new SphereCoordinate(-2 * Math.PI, 0);

            Assert.AreEqual(new SphereCoordinate(Math.PI, 0), sphereCoord1);
            Assert.AreEqual(new SphereCoordinate(0, Math.PI), sphereCoord2);
        }
Example #3
0
        private static void Main(string[] args)
        {
            var start1 = new SphereCoordinate(0.5 * Math.PI, -0.25 * Math.PI);

            Console.WriteLine((CartesianVector)start1);

            var end1 = new SphereCoordinate(0.5 * Math.PI, 0.25 * Math.PI);

            Console.WriteLine((CartesianVector)end1);

            var start2 = new SphereCoordinate(0.25 * Math.PI, 0);

            Console.WriteLine((CartesianVector)start2);

            var end2 = new SphereCoordinate(0.75 * Math.PI, 0);

            Console.WriteLine((CartesianVector)end2);

            var arc1 = new GreatCircleSegment(start1, end1);
            var arc2 = new GreatCircleSegment(start2, end2);

            Console.WriteLine();
            Console.WriteLine(arc1.Midpoint);
            Console.WriteLine(new CartesianVector(0, 0, 1));
            Console.WriteLine((SphereCoordinate)arc1.Midpoint);
            Console.WriteLine((SphereCoordinate) new CartesianVector(0, 0, 1));
            Console.WriteLine((CartesianVector)(SphereCoordinate)arc1.Midpoint);
            Console.WriteLine();

            SphereCoordinate intersection;

            Console.WriteLine(arc1.Intersects(arc2, out intersection) + "   " + intersection + "   " + (CartesianVector)intersection);

            Console.WriteLine();
            var quarterSpherePoly = new VoronoiCell(new SphereCoordinate(0, 0), new SphereCoordinate(0.5 * Math.PI, 0), new SphereCoordinate(0.5 * Math.PI, 0.5 * Math.PI), new SphereCoordinate(0.5 * Math.PI, Math.PI));

            Console.WriteLine("Area of quarter sphere Polygon: " + quarterSpherePoly.Area);
            Console.WriteLine("Area of whole sphere: " + 4 * Math.PI);
            Console.WriteLine("Area of quarter sphere: " + Math.PI);

            Console.WriteLine();
            Console.WriteLine(Math.Acos(new CartesianVector(0, 1, 0).DotProduct(new SphereCoordinate(Math.PI / 2, 0))));
            Console.WriteLine(Math.Acos(new CartesianVector(0, 1, 0).DotProduct(new SphereCoordinate(Math.PI / 2, -Math.PI / 2))));
            Console.WriteLine(Math.Acos(new CartesianVector(0, 1, 0).DotProduct(new SphereCoordinate(Math.PI / 2, 0))));
            Console.WriteLine(Math.Acos(new CartesianVector(0, 1, 0).DotProduct(new SphereCoordinate(Math.PI / 2, -Math.PI / 2))));

            Console.WriteLine();
            Console.WriteLine(Math.Acos(new CartesianVector(1, 1, 0).AsUnitVector.DotProduct(new SphereCoordinate(Math.PI / 2, 0))));
            Console.WriteLine(Math.Acos(new CartesianVector(1, 1, 0).AsUnitVector.DotProduct(new SphereCoordinate(Math.PI / 4, -Math.PI / 2))));

            Console.WriteLine();
            Console.WriteLine(Math.Acos(new CartesianVector(0, 1, 0).DotProduct(new CartesianVector(1, 1, 0).AsUnitVector)));
            Console.WriteLine(Math.PI / 4);

            Console.ReadLine();
        }
        public void HandlesArcGoingThrough0Azimuthal()
        {
            var start1 = new SphereCoordinate(Math.PI / 2, 1.75 * Math.PI);
            var end1 = new SphereCoordinate(Math.PI / 2, Math.PI / 4);

            var start2 = new SphereCoordinate(Math.PI / 4, 0);
            var end2 = new SphereCoordinate(0.75 * Math.PI, 0);

            var arc1 = new GreatCircleSegment(start1, end1);
            var arc2 = new GreatCircleSegment(start2, end2);

            SphereCoordinate intersection;
            Assert.IsTrue(arc1.Intersects(arc2, out intersection));
            Assert.AreEqual(intersection, new SphereCoordinate(Math.PI / 2, 0));
        }
        public void HandlesArcGoingThrough0Azimuthal()
        {
            var start1 = new SphereCoordinate(Math.PI / 2, 1.75 * Math.PI);
            var end1   = new SphereCoordinate(Math.PI / 2, Math.PI / 4);

            var start2 = new SphereCoordinate(Math.PI / 4, 0);
            var end2   = new SphereCoordinate(0.75 * Math.PI, 0);

            var arc1 = new GreatCircleSegment(start1, end1);
            var arc2 = new GreatCircleSegment(start2, end2);

            SphereCoordinate intersection;

            Assert.IsTrue(arc1.Intersects(arc2, out intersection));
            Assert.AreEqual(intersection, new SphereCoordinate(Math.PI / 2, 0));
        }
Example #6
0
        /// <summary>
        /// Checks whether the given <see cref="SphereCoordinate"/> is within this <see cref="VoronoiCell"/>.
        /// </summary>
        /// <param name="sphereCoordinate">The <see cref="SphereCoordinate"/> to check.</param>
        /// <returns>Whether the given <see cref="SphereCoordinate"/> is within this <see cref="VoronoiCell"/>.</returns>
        public bool IsInside(SphereCoordinate sphereCoordinate)
        {
            var centerToPoint = new GreatCircleSegment(Center, sphereCoordinate);

            // Check if any sides intersect with the arc from Center to point.
            SphereCoordinate _;

            if (startCorner == null)
            {
                return(FirstPart.Intersects(centerToPoint, out _));
            }
            else
            {
                foreach (var corner in Corners)
                {
                    if (corner.ToNext.Intersects(centerToPoint, out _))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #7
0
 // Use this for initialization
 void Start()
 {
     colision = false;
     sphCoord = new SphereCoordinate(this.transform.position);
 }
Example #8
0
 /// <summary>
 /// Creates a new instance of the <see cref="VoronoiCell"/> class with the given center and sides.
 /// </summary>
 /// <param name="center">The point used as center for Voronoi calculations. Assumed to be inside.</param>
 /// <param name="firstPart">The <see cref="GreatCircle"/> that makes the first part of the Polygon.</param>
 public VoronoiCell(SphereCoordinate center, GreatCircle firstPart)
 {
     Center    = center;
     FirstPart = firstPart;
 }
Example #9
0
 public Corner(SphereCoordinate point)
 {
     Point = point;
 }
Example #10
0
 // Use this for initialization
 void Start()
 {
     colision = false;
     sphCoord = new SphereCoordinate(this.transform.position);
 }
 public VoronoiPoint(SphereCoordinate point, bool calculated = false, VoronoiCell polygon = null)
 {
     Point      = point;
     Calculated = calculated;
     Polygon    = polygon;
 }