def test_spherical_polygon_4_vertices_nearly_colinear_surface_area_calculation(
         self):
     '''Test spherical polygon surface area calculation for a polygon with 4 vertices AND an internal angle that is very close to 180 degrees. Trying to stress test / probe possible issues with arc cosine accuracy, etc.'''
     regular_spherical_triangle_coords = self.spherical_triangle_coordinate_array  #([[0,0,1],[0,1,0],[1,0,0]]) #3 points on a unit sphere
     #I want to generate a fourth point that is ALMOST on the same great circle arc as two other vertices, because this is a nasty test case
     linear_midpoint_last_two_vertices = (
         regular_spherical_triangle_coords[1] +
         regular_spherical_triangle_coords[2]) / 2.0
     linear_midpoint_spherical_polar_coords = voronoi_utility.convert_cartesian_array_to_spherical_array(
         linear_midpoint_last_two_vertices)
     spherical_midpoint_spherical_polar_coords = numpy.zeros((1, 3))
     spherical_midpoint_spherical_polar_coords[0, 0] = 1.0
     spherical_midpoint_spherical_polar_coords[
         0, 1] = linear_midpoint_spherical_polar_coords[
             1] + 0.000001  #slightly off the arc
     spherical_midpoint_spherical_polar_coords[
         0, 2] = linear_midpoint_spherical_polar_coords[
             2] + 0.000001  #slightly off the arc
     near_midpoint_cartesian = voronoi_utility.convert_spherical_array_to_cartesian_array(
         spherical_midpoint_spherical_polar_coords)
     polygon_coords = numpy.zeros((4, 3))
     polygon_coords[0] = regular_spherical_triangle_coords[0]
     polygon_coords[1] = regular_spherical_triangle_coords[1]
     polygon_coords[2] = near_midpoint_cartesian[0, ...]
     polygon_coords[3] = regular_spherical_triangle_coords[2]
     measured_surface_area = voronoi_utility.calculate_surface_area_of_a_spherical_Voronoi_polygon(
         polygon_coords, 1.0
     )  #the function itself will pass an exception if there is a negative surface area
     self.assertGreater(measured_surface_area, 0.0)
 def test_spherical_polygon_4_vertices_exactly_colinear_surface_area_calculation(
         self):
     '''Test spherical polygon surface area calculation for a polygon with 4 vertices--3 of which are on the same great circle arc--this should surely cause a problem!! (Apparently not.)'''
     regular_spherical_triangle_coords = self.spherical_triangle_coordinate_array  #([[0,0,1],[0,1,0],[1,0,0]]) #3 points on a unit sphere
     linear_midpoint_last_two_vertices = (
         regular_spherical_triangle_coords[1] +
         regular_spherical_triangle_coords[2]) / 2.0
     linear_midpoint_spherical_polar_coords = voronoi_utility.convert_cartesian_array_to_spherical_array(
         linear_midpoint_last_two_vertices)
     spherical_midpoint_spherical_polar_coords = numpy.zeros((1, 3))
     spherical_midpoint_spherical_polar_coords[0, 0] = 1.0
     spherical_midpoint_spherical_polar_coords[
         0, 1] = linear_midpoint_spherical_polar_coords[1]
     spherical_midpoint_spherical_polar_coords[
         0, 2] = linear_midpoint_spherical_polar_coords[2]
     near_midpoint_cartesian = voronoi_utility.convert_spherical_array_to_cartesian_array(
         spherical_midpoint_spherical_polar_coords)
     polygon_coords = numpy.zeros((4, 3))
     polygon_coords[0] = regular_spherical_triangle_coords[0]
     polygon_coords[1] = regular_spherical_triangle_coords[1]
     polygon_coords[2] = near_midpoint_cartesian[0, ...]
     polygon_coords[3] = regular_spherical_triangle_coords[2]
     measured_surface_area = voronoi_utility.calculate_surface_area_of_a_spherical_Voronoi_polygon(
         polygon_coords, 1.0
     )  #the function itself will pass an exception if there is a negative surface area
     self.assertGreater(measured_surface_area, 0.0)
 def test_problematic_spherical_polygon_surface_area(self):
     '''Test the surface area of a spherical polygon that I know has previously caused issues with negative surface area as part of a Voronoi diagram. Now using a simplified version of that polygon with 1 less vertex--but still get a negative result.'''
     problematic_polygon_array = numpy.array([[-0.12278101, 0.38828208, 0.90397089],
      [-0.18533492 ,0.28384049, 0.9317119 ],
      [ 0.07210294 ,0.29806975, 0.94284522],
      [ 0.1316095  ,0.32464041, 0.92751769]])
     measured_surface_area = voronoi_utility.calculate_surface_area_of_a_spherical_Voronoi_polygon(problematic_polygon_array,1.0)
     self.assertGreater(measured_surface_area,0.0)
 def test_spherical_triangle_surface_area_calculation(self):
     '''Test spherical polygon surface area calculation on the relatively simple case of a spherical triangle on the surface of a unit sphere.'''
     #the surface area of a spherical triangle is a special case of a spherical polygon (http://mathworld.wolfram.com/SphericalTriangle.html)
     sum_spherical_triangle_inner_angles = voronoi_utility.calculate_and_sum_up_inner_sphere_surface_angles_Voronoi_polygon(self.spherical_triangle_coordinate_array,1.0)
     spherical_excess = sum_spherical_triangle_inner_angles - math.pi #because the radius of the sphere is 1 the spherical excess is also the surface area
     self.assertGreater(spherical_excess,0.0)
     test_surface_area = voronoi_utility.calculate_surface_area_of_a_spherical_Voronoi_polygon(self.spherical_triangle_coordinate_array,1.0)
     numpy.testing.assert_almost_equal(test_surface_area,spherical_excess,decimal=12)
 def test_spherical_polygon_4_vertices_surface_area_calculation(self):
     '''Test spherical polygon surface area calculation on the more complex case of a spherical polygon with 4 vertices on a unit sphere.'''
     sum_spherical_polygon_inner_angles = voronoi_utility.calculate_and_sum_up_inner_sphere_surface_angles_Voronoi_polygon(self.spherical_polygon_4_vertices_coord_array,1.0)
     subtraction_value = 2 * math.pi # (n-2) * pi
     target_area = sum_spherical_polygon_inner_angles - subtraction_value
     #print 'target_area (should be pi):', target_area 
     self.assertGreater(sum_spherical_polygon_inner_angles,subtraction_value,'The polygon with 4 vertices has a negative surface area.')
     measured_surface_area = voronoi_utility.calculate_surface_area_of_a_spherical_Voronoi_polygon(self.spherical_polygon_4_vertices_coord_array, 1.0)
     numpy.testing.assert_almost_equal(measured_surface_area,target_area,decimal=12)
 def test_problematic_spherical_polygon_surface_area(self):
     '''Test the surface area of a spherical polygon that I know has previously caused issues with negative surface area as part of a Voronoi diagram. Now using a simplified version of that polygon with 1 less vertex--but still get a negative result.'''
     problematic_polygon_array = numpy.array(
         [[-0.12278101, 0.38828208, 0.90397089],
          [-0.18533492, 0.28384049, 0.9317119],
          [0.07210294, 0.29806975, 0.94284522],
          [0.1316095, 0.32464041, 0.92751769]])
     measured_surface_area = voronoi_utility.calculate_surface_area_of_a_spherical_Voronoi_polygon(
         problematic_polygon_array, 1.0)
     self.assertGreater(measured_surface_area, 0.0)
 def test_spherical_triangle_surface_area_calculation(self):
     '''Test spherical polygon surface area calculation on the relatively simple case of a spherical triangle on the surface of a unit sphere.'''
     #the surface area of a spherical triangle is a special case of a spherical polygon (http://mathworld.wolfram.com/SphericalTriangle.html)
     sum_spherical_triangle_inner_angles = voronoi_utility.calculate_and_sum_up_inner_sphere_surface_angles_Voronoi_polygon(
         self.spherical_triangle_coordinate_array, 1.0)
     spherical_excess = sum_spherical_triangle_inner_angles - math.pi  #because the radius of the sphere is 1 the spherical excess is also the surface area
     self.assertGreater(spherical_excess, 0.0)
     test_surface_area = voronoi_utility.calculate_surface_area_of_a_spherical_Voronoi_polygon(
         self.spherical_triangle_coordinate_array, 1.0)
     numpy.testing.assert_almost_equal(test_surface_area,
                                       spherical_excess,
                                       decimal=12)
 def test_spherical_polygon_4_vertices_surface_area_calculation(self):
     '''Test spherical polygon surface area calculation on the more complex case of a spherical polygon with 4 vertices on a unit sphere.'''
     sum_spherical_polygon_inner_angles = voronoi_utility.calculate_and_sum_up_inner_sphere_surface_angles_Voronoi_polygon(
         self.spherical_polygon_4_vertices_coord_array, 1.0)
     subtraction_value = 2 * math.pi  # (n-2) * pi
     target_area = sum_spherical_polygon_inner_angles - subtraction_value
     #print 'target_area (should be pi):', target_area
     self.assertGreater(
         sum_spherical_polygon_inner_angles, subtraction_value,
         'The polygon with 4 vertices has a negative surface area.')
     measured_surface_area = voronoi_utility.calculate_surface_area_of_a_spherical_Voronoi_polygon(
         self.spherical_polygon_4_vertices_coord_array, 1.0)
     numpy.testing.assert_almost_equal(measured_surface_area,
                                       target_area,
                                       decimal=12)
 def test_spherical_polygon_4_vertices_exactly_colinear_surface_area_calculation(self):
     '''Test spherical polygon surface area calculation for a polygon with 4 vertices--3 of which are on the same great circle arc--this should surely cause a problem!! (Apparently not.)'''
     regular_spherical_triangle_coords = self.spherical_triangle_coordinate_array #([[0,0,1],[0,1,0],[1,0,0]]) #3 points on a unit sphere
     linear_midpoint_last_two_vertices = (regular_spherical_triangle_coords[1] + regular_spherical_triangle_coords[2]) / 2.0
     linear_midpoint_spherical_polar_coords = voronoi_utility.convert_cartesian_array_to_spherical_array(linear_midpoint_last_two_vertices)
     spherical_midpoint_spherical_polar_coords = numpy.zeros((1,3))
     spherical_midpoint_spherical_polar_coords[0,0] = 1.0
     spherical_midpoint_spherical_polar_coords[0,1] = linear_midpoint_spherical_polar_coords[1] 
     spherical_midpoint_spherical_polar_coords[0,2] = linear_midpoint_spherical_polar_coords[2]
     near_midpoint_cartesian = voronoi_utility.convert_spherical_array_to_cartesian_array(spherical_midpoint_spherical_polar_coords)
     polygon_coords = numpy.zeros((4,3))
     polygon_coords[0] = regular_spherical_triangle_coords[0]
     polygon_coords[1] = regular_spherical_triangle_coords[1]
     polygon_coords[2] = near_midpoint_cartesian[0,...]
     polygon_coords[3] = regular_spherical_triangle_coords[2]
     measured_surface_area = voronoi_utility.calculate_surface_area_of_a_spherical_Voronoi_polygon(polygon_coords,1.0) #the function itself will pass an exception if there is a negative surface area
     self.assertGreater(measured_surface_area,0.0)
 def test_spherical_polygon_4_vertices_nearly_colinear_surface_area_calculation(self):
     '''Test spherical polygon surface area calculation for a polygon with 4 vertices AND an internal angle that is very close to 180 degrees. Trying to stress test / probe possible issues with arc cosine accuracy, etc.'''
     regular_spherical_triangle_coords = self.spherical_triangle_coordinate_array #([[0,0,1],[0,1,0],[1,0,0]]) #3 points on a unit sphere
     #I want to generate a fourth point that is ALMOST on the same great circle arc as two other vertices, because this is a nasty test case
     linear_midpoint_last_two_vertices = (regular_spherical_triangle_coords[1] + regular_spherical_triangle_coords[2]) / 2.0
     linear_midpoint_spherical_polar_coords = voronoi_utility.convert_cartesian_array_to_spherical_array(linear_midpoint_last_two_vertices)
     spherical_midpoint_spherical_polar_coords = numpy.zeros((1,3))
     spherical_midpoint_spherical_polar_coords[0,0] = 1.0
     spherical_midpoint_spherical_polar_coords[0,1] = linear_midpoint_spherical_polar_coords[1] + 0.000001 #slightly off the arc
     spherical_midpoint_spherical_polar_coords[0,2] = linear_midpoint_spherical_polar_coords[2] + 0.000001 #slightly off the arc
     near_midpoint_cartesian = voronoi_utility.convert_spherical_array_to_cartesian_array(spherical_midpoint_spherical_polar_coords)
     polygon_coords = numpy.zeros((4,3))
     polygon_coords[0] = regular_spherical_triangle_coords[0]
     polygon_coords[1] = regular_spherical_triangle_coords[1]
     polygon_coords[2] = near_midpoint_cartesian[0,...]
     polygon_coords[3] = regular_spherical_triangle_coords[2]
     measured_surface_area = voronoi_utility.calculate_surface_area_of_a_spherical_Voronoi_polygon(polygon_coords,1.0) #the function itself will pass an exception if there is a negative surface area
     self.assertGreater(measured_surface_area,0.0)