NullPointerException when making an intersection on two SphericalPolygonSet
Summary
Hello guys,
First of all, a big thank you for the excellent work you have done in Orekit.
I have a NullPointerException when making the intersection between two SphericalPolygonSet. However, I think the input format is respected for the coordinates, the format I'm using is :
a. format is [lat, lon]
b. order is anticlockwise
c. the first coordinates != the last one
How to replicate
Here is the code to replicate the bug :
import org.hipparchus.geometry.partitioning.Region;
import org.hipparchus.geometry.partitioning.RegionFactory;
import org.hipparchus.geometry.spherical.twod.Sphere2D;
import org.hipparchus.geometry.spherical.twod.SphericalPolygonsSet;
import org.orekit.models.earth.tessellation.EllipsoidTessellator;
import static org.hipparchus.util.FastMath.toRadians;
public class TestIntersection {
/**
* Main method demonstrating the usage of the class.
*
* @param args Command-line arguments (not used).
*/
public static void main(String[] args) {
// Step 1 : define the coordinates :
// a. format is [lat, lon]
// b. order is anticlockwise
// c. the first coordinates != the last one
double[][] shapeCoordinates1 = {
{18.52684751402596,-76.97880893719434},
{18.451108862175584,-76.99484778988442},
{18.375369256045143,-77.01087679277504},
{18.299628701801268,-77.02689599675749},
{18.223887203723567,-77.04290545732495},
{18.148144771769385,-77.05890521550272},
{18.072401410187016,-77.0748953260324},
{17.99665712514784,-77.09087584010511},
{17.92091192468999,-77.10684680260262},
{17.84516581113023,-77.12280827309398},
{17.769418792522664,-77.13876029654094},
{17.747659863099422,-77.14334087084347},
{17.67571798336192,-77.15846791369165},
{17.624293265977183,-77.16928381433733},
{17.5485398681768,-77.18520934447962},
{17.526779103104783,-77.1897823275402},
{17.49650619905315,-77.0342031192472},
{17.588661518962343,-77.01473903648854},
{17.728574326965138,-76.98517769352242},
{17.80416324015021,-76.96919708557023},
{17.87969526622326,-76.95321858415689},
{17.955280973332677,-76.93721874766547},
{18.030855567607098,-76.92121123297645},
{18.106414929680927,-76.90519686376611},
{18.182031502555215,-76.88916022728444},
{18.257597934434987,-76.87312403715188},
{18.3331742522667,-76.85707550881591},
{18.408750874895002,-76.84101662269072},
{18.57249082100609,-76.80620195239239},
{18.602585205425896,-76.96276018365842}
};
double[][] shapeCoordinates2 = {
{18.338614038907608,-78.37885677406668},
{18.195574802144037,-78.24425107003432},
{18.20775293886321,-78.0711865934217},
{18.07679345301507,-77.95901517339438},
{18.006705181057598,-77.85325354879791},
{17.857293838883137,-77.73787723105598},
{17.854243316622103,-77.57442744758828},
{17.875595873376014,-77.38213358468467},
{17.72607423578937,-77.23470828979222},
{17.71386286451302,-77.12253686976543},
{17.790170276013725,-77.14817605148616},
{17.869495404611797,-77.14497115377101},
{17.854243309397717,-76.9302429967729},
{17.954882874700132,-76.84371075846688},
{17.94268718313505,-76.6898756681441},
{17.869495397388064,-76.54886016868198},
{17.863394719203555,-76.35015651034861},
{17.93049065091843,-76.23478019260665},
{18.155989976776553,-76.32451732862788},
{18.22601854027039,-76.63218750927341},
{18.33861403170316,-76.85653034932697},
{18.405527980074993,-76.97831646249921},
{18.4541763474828,-77.28598664314421},
{18.496732365966466,-77.705828243816},
{18.451136227912485,-78.00708862903122},
{18.405527980074993,-78.25707065080552}
};
// Step 3 : Build the SphericalPolygonsSet
SphericalPolygonsSet shape1 = EllipsoidTessellator.buildSimpleZone(1e-10, coordinatesToRadians(shapeCoordinates1));
SphericalPolygonsSet shape2 = EllipsoidTessellator.buildSimpleZone(1e-10, coordinatesToRadians(shapeCoordinates2));
// Step 4 : Make the intersection
Region<Sphere2D> intersection = new RegionFactory<Sphere2D>()
.intersection(shape1, shape2);
}
/**
* Converts coordinates from degrees to radians.
*
* @param coordinates The coordinates in degrees.
* @return The coordinates in radians.
*/
private static double[][] coordinatesToRadians(double[][] coordinates) {
// Convert coordinates to radians
double[][] coordinatesRadian = new double[coordinates.length][2];
for (int i = 0; i < coordinates.length; i++) {
coordinatesRadian[i][0] = toRadians(coordinates[i][0]);
coordinatesRadian[i][1] = toRadians(coordinates[i][1]);
}
return coordinatesRadian;
}
}
The intersection
method throws this error :
Exception in thread "main" java.lang.
NullPointerException
: Cannot invoke "Object.equals(Object)" because the return value of "org.hipparchus.geometry.partitioning.BSPTree.getAttribute()" is null at org.hipparchus.geometry.partitioning.RegionFactory$VanishingToLeaf.fixNode(RegionFactory.java:381) at org.hipparchus.geometry.partitioning.BSPTree.insertInTree(BSPTree.java:680) at org.hipparchus.geometry.partitioning.RegionFactory$IntersectionMerger.merge(RegionFactory.java:267) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:437) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:455) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:455) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:454) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:454) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:454) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:454) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:454) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:454) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:454) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:454) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:454) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:454) at org.hipparchus.geometry.partitioning.BSPTree.merge(BSPTree.java:415) at org.hipparchus.geometry.partitioning.RegionFactory.intersection(RegionFactory.java:129)
Do you think is an Issue on the BSPTree intersection or it's an error related to my input format ?
Note that I never had issues on the intersection of two SphericalPolygonSet before this one.
Thanks for your help.