/// <summary> /// Checks whether the given <see cref="GreatCircleSegment"/> intersects with this <see cref="GreatCicle"/>. /// The point of intersection can then be found in the out-Parameter. /// </summary> /// <param name="arc">The arc segment to be checked.</param> /// <param name="intersection">The point of intersection, if they intersect.</param> /// <returns>Whether the <see cref="GreatCircleSegment"/> intersects this <see cref="GreatCircle"/> or not.</returns> public bool Intersects(GreatCircleSegment arc, out SphereCoordinate intersection) { intersection = default(SphereCoordinate); CartesianVector possibleIntersection; if (!Intersects(arc.BaseCircle, out possibleIntersection)) { return(false); } if (arc.IsOnArc(possibleIntersection)) { intersection = possibleIntersection; return(true); } if (arc.IsOnArc(-possibleIntersection)) { intersection = -possibleIntersection; return(true); } return(false); }
/// <summary> /// Checks whether the given <see cref="GreatCircleSegment"/> intersects with this one. /// The point of intersection can then be found in the out-Parameter. /// </summary> /// <param name="other">The arc segment to be checked.</param> /// <param name="intersection">The point of intersection, if they intersect.</param> /// <returns>Whether the two <see cref="GreatCircleSegment"/>s intersect or not.</returns> public bool Intersects(GreatCircleSegment other, out SphereCoordinate intersection) { // http://www.boeing-727.com/Data/fly%20odds/distance.html intersection = default(SphereCoordinate); if (Length.IsAlmostEqualTo(0) || other.Length.IsAlmostEqualTo(0)) { return(false); } CartesianVector possibleIntersection1; if (!BaseCircle.Intersects(other.BaseCircle, out possibleIntersection1)) { return(false); } var possibleIntersection2 = -possibleIntersection1; if (IsOnArc(possibleIntersection1) && other.IsOnArc(possibleIntersection1)) { intersection = possibleIntersection1; return(true); } if (IsOnArc(possibleIntersection2) && other.IsOnArc(possibleIntersection2)) { intersection = possibleIntersection2; return(true); } return(false); }
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(); }
/// <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; }
/// <summary> /// Checks whether the given <see cref="GreatCircleSegment"/> intersects with this one. /// The point of intersection can then be found in the out-Parameter. /// </summary> /// <param name="other">The arc segment to be checked.</param> /// <param name="intersection">The point of intersection, if they intersect.</param> /// <returns>Whether the two <see cref="GreatCircleSegment"/>s intersect or not.</returns> public bool Intersects(GreatCircleSegment other, out SphereCoordinate intersection) { // http://www.boeing-727.com/Data/fly%20odds/distance.html intersection = default(SphereCoordinate); if (Length.IsAlmostEqualTo(0) || other.Length.IsAlmostEqualTo(0)) return false; CartesianVector possibleIntersection1; if (!BaseCircle.Intersects(other.BaseCircle, out possibleIntersection1)) return false; var possibleIntersection2 = -possibleIntersection1; if (IsOnArc(possibleIntersection1) && other.IsOnArc(possibleIntersection1)) { intersection = possibleIntersection1; return true; } if (IsOnArc(possibleIntersection2) && other.IsOnArc(possibleIntersection2)) { intersection = possibleIntersection2; return true; } return false; }
/// <summary> /// Creates a new instance of the <see cref="GreatCircle"/> struct given a segment of it. /// </summary> /// <param name="segment">A part of the great circle.</param> public GreatCircle(GreatCircleSegment segment) : this(segment.Start, segment.End) { }
/// <summary> /// Checks whether the given <see cref="GreatCircleSegment"/> intersects with this <see cref="GreatCicle"/>. /// The point of intersection can then be found in the out-Parameter. /// </summary> /// <param name="arc">The arc segment to be checked.</param> /// <param name="intersection">The point of intersection, if they intersect.</param> /// <returns>Whether the <see cref="GreatCircleSegment"/> intersects this <see cref="GreatCircle"/> or not.</returns> public bool Intersects(GreatCircleSegment arc, out SphereCoordinate intersection) { intersection = default(SphereCoordinate); CartesianVector possibleIntersection; if (!Intersects(arc.BaseCircle, out possibleIntersection)) return false; if (arc.IsOnArc(possibleIntersection)) { intersection = possibleIntersection; return true; } if (arc.IsOnArc(-possibleIntersection)) { intersection = -possibleIntersection; return true; } return false; }