Search in sources :

Example 1 with S2Point

use of org.hipparchus.geometry.spherical.twod.S2Point in project Orekit by CS-SI.

the class FootprintOverlapDetector method g.

/**
 * {@inheritDoc}
 * <p>
 * The g function value is the minimum offset among the region points
 * with respect to the Field Of View boundary. It is positive if all region
 * points are outside of the Field Of View, and negative if at least some
 * of the region points are inside of the Field Of View. The minimum is
 * computed by sampling the region, considering only the points for which
 * the spacecraft is above the horizon. The accuracy of the detection
 * depends on the linear sampling step set at detector construction. If
 * the spacecraft is below horizon for all region points, an arbitrary
 * positive value is returned.
 * </p>
 * <p>
 * As per the previous definition, when the region enters the Field Of
 * View, a decreasing event is generated, and when the region leaves
 * the Field Of View, an increasing event is generated.
 * </p>
 */
public double g(final SpacecraftState s) throws OrekitException {
    // initial arbitrary positive value
    double value = FastMath.PI;
    // get spacecraft position in body frame
    final Vector3D scBody = s.getPVCoordinates(body.getBodyFrame()).getPosition();
    // map the point to a sphere
    final GeodeticPoint gp = body.transform(scBody, body.getBodyFrame(), s.getDate());
    final S2Point s2p = new S2Point(gp.getLongitude(), 0.5 * FastMath.PI - gp.getLatitude());
    // for faster computation, we start using only the surrounding cap, to filter out
    // far away points (which correspond to most of the points if the zone is small)
    final Vector3D p = s2p.getVector();
    final double dot = Vector3D.dotProduct(p, capCenter);
    if (dot < capCos) {
        // the spacecraft is outside of the cap, look for the closest cap point
        final Vector3D t = p.subtract(dot, capCenter).normalize();
        final Vector3D close = new Vector3D(capCos, capCenter, capSin, t);
        if (Vector3D.dotProduct(p, close) < -0.01) {
            // we can return the arbitrary initial positive value without performing further computation
            return value;
        }
    }
    // the spacecraft may be visible from some points in the zone, check them all
    final Transform bodyToSc = new Transform(s.getDate(), body.getBodyFrame().getTransformTo(s.getFrame(), s.getDate()), s.toTransform());
    for (final SamplingPoint point : sampledZone) {
        final Vector3D lineOfSightBody = point.getPosition().subtract(scBody);
        if (Vector3D.dotProduct(lineOfSightBody, point.getZenith()) <= 0) {
            // spacecraft is above this sample point local horizon
            // get line of sight in spacecraft frame
            final double offset = fov.offsetFromBoundary(bodyToSc.transformVector(lineOfSightBody));
            value = FastMath.min(value, offset);
        }
    }
    return value;
}
Also used : S2Point(org.hipparchus.geometry.spherical.twod.S2Point) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) GeodeticPoint(org.orekit.bodies.GeodeticPoint) Transform(org.orekit.frames.Transform)

Example 2 with S2Point

use of org.hipparchus.geometry.spherical.twod.S2Point in project Orekit by CS-SI.

the class FootprintOverlapDetector method sample.

/**
 * Sample the region.
 * @param body body on which the geographic zone is defined
 * @param zone geographic zone to consider
 * @param samplingStep  linear step used for sampling the geographic zone (in meters)
 * @return sampling points
 * @throws OrekitException if the region cannot be sampled
 */
private static List<SamplingPoint> sample(final OneAxisEllipsoid body, final SphericalPolygonsSet zone, final double samplingStep) throws OrekitException {
    final List<SamplingPoint> sampledZone = new ArrayList<SamplingPoint>();
    // sample the zone boundary
    final List<Vertex> boundary = zone.getBoundaryLoops();
    for (final Vertex loopStart : boundary) {
        int count = 0;
        for (Vertex v = loopStart; count == 0 || v != loopStart; v = v.getOutgoing().getEnd()) {
            ++count;
            final Edge edge = v.getOutgoing();
            final int n = (int) FastMath.ceil(edge.getLength() * body.getEquatorialRadius() / samplingStep);
            for (int i = 0; i < n; ++i) {
                final S2Point intermediate = new S2Point(edge.getPointAt(i * edge.getLength() / n));
                final GeodeticPoint gp = new GeodeticPoint(0.5 * FastMath.PI - intermediate.getPhi(), intermediate.getTheta(), 0.0);
                sampledZone.add(new SamplingPoint(body.transform(gp), gp.getZenith()));
            }
        }
    }
    // sample the zone interior
    final EllipsoidTessellator tessellator = new EllipsoidTessellator(body, new ConstantAzimuthAiming(body, 0.0), 4);
    final List<List<GeodeticPoint>> gpSample = tessellator.sample(zone, samplingStep, samplingStep);
    for (final List<GeodeticPoint> list : gpSample) {
        for (final GeodeticPoint gp : list) {
            sampledZone.add(new SamplingPoint(body.transform(gp), gp.getZenith()));
        }
    }
    return sampledZone;
}
Also used : Vertex(org.hipparchus.geometry.spherical.twod.Vertex) S2Point(org.hipparchus.geometry.spherical.twod.S2Point) ArrayList(java.util.ArrayList) EllipsoidTessellator(org.orekit.models.earth.tessellation.EllipsoidTessellator) S2Point(org.hipparchus.geometry.spherical.twod.S2Point) GeodeticPoint(org.orekit.bodies.GeodeticPoint) ConstantAzimuthAiming(org.orekit.models.earth.tessellation.ConstantAzimuthAiming) ArrayList(java.util.ArrayList) List(java.util.List) GeodeticPoint(org.orekit.bodies.GeodeticPoint) Edge(org.hipparchus.geometry.spherical.twod.Edge)

Example 3 with S2Point

use of org.hipparchus.geometry.spherical.twod.S2Point in project Orekit by CS-SI.

the class EllipsoidTessellator method extractTiles.

/**
 * Extract tiles from a mesh.
 * @param mesh mesh from which tiles should be extracted
 * @param zone zone covered by the mesh
 * @param lengthOverlap overlap between adjacent tiles
 * @param widthOverlap overlap between adjacent tiles
 * @param truncateLastWidth true if we can reduce last tile width
 * @param truncateLastLength true if we can reduce last tile length
 * @return extracted tiles
 * @exception OrekitException if tile direction cannot be computed
 */
private List<Tile> extractTiles(final Mesh mesh, final SphericalPolygonsSet zone, final double lengthOverlap, final double widthOverlap, final boolean truncateLastWidth, final boolean truncateLastLength) throws OrekitException {
    final List<Tile> tiles = new ArrayList<Tile>();
    final List<RangePair> rangePairs = new ArrayList<RangePair>();
    final int minAcross = mesh.getMinAcrossIndex();
    final int maxAcross = mesh.getMaxAcrossIndex();
    for (Range acrossPair : nodesIndices(minAcross, maxAcross, truncateLastWidth)) {
        int minAlong = mesh.getMaxAlongIndex() + 1;
        int maxAlong = mesh.getMinAlongIndex() - 1;
        for (int c = acrossPair.lower; c <= acrossPair.upper; ++c) {
            minAlong = FastMath.min(minAlong, mesh.getMinAlongIndex(c));
            maxAlong = FastMath.max(maxAlong, mesh.getMaxAlongIndex(c));
        }
        for (Range alongPair : nodesIndices(minAlong, maxAlong, truncateLastLength)) {
            // get the base vertex nodes
            final Mesh.Node node0 = mesh.addNode(alongPair.lower, acrossPair.lower);
            final Mesh.Node node1 = mesh.addNode(alongPair.upper, acrossPair.lower);
            final Mesh.Node node2 = mesh.addNode(alongPair.upper, acrossPair.upper);
            final Mesh.Node node3 = mesh.addNode(alongPair.lower, acrossPair.upper);
            // apply tile overlap
            final S2Point s2p0 = node0.move(new Vector3D(-0.5 * lengthOverlap, node0.getAlong(), -0.5 * widthOverlap, node0.getAcross()));
            final S2Point s2p1 = node1.move(new Vector3D(+0.5 * lengthOverlap, node1.getAlong(), -0.5 * widthOverlap, node1.getAcross()));
            final S2Point s2p2 = node2.move(new Vector3D(+0.5 * lengthOverlap, node2.getAlong(), +0.5 * widthOverlap, node2.getAcross()));
            final S2Point s2p3 = node3.move(new Vector3D(-0.5 * lengthOverlap, node2.getAlong(), +0.5 * widthOverlap, node2.getAcross()));
            // create a quadrilateral region corresponding to the candidate tile
            final SphericalPolygonsSet quadrilateral = new SphericalPolygonsSet(zone.getTolerance(), s2p0, s2p1, s2p2, s2p3);
            if (!new RegionFactory<Sphere2D>().intersection(zone.copySelf(), quadrilateral).isEmpty()) {
                // the tile does cover part of the zone, it contributes to the tessellation
                tiles.add(new Tile(toGeodetic(s2p0), toGeodetic(s2p1), toGeodetic(s2p2), toGeodetic(s2p3)));
                rangePairs.add(new RangePair(acrossPair, alongPair));
            }
        }
    }
    // neighboring tile as they share some nodes that will be enabled here
    for (final RangePair rangePair : rangePairs) {
        for (int c = rangePair.across.lower; c < rangePair.across.upper; ++c) {
            mesh.addNode(rangePair.along.lower, c + 1).setEnabled();
            mesh.addNode(rangePair.along.upper, c).setEnabled();
        }
        for (int l = rangePair.along.lower; l < rangePair.along.upper; ++l) {
            mesh.addNode(l, rangePair.across.lower).setEnabled();
            mesh.addNode(l + 1, rangePair.across.upper).setEnabled();
        }
    }
    return tiles;
}
Also used : S2Point(org.hipparchus.geometry.spherical.twod.S2Point) Sphere2D(org.hipparchus.geometry.spherical.twod.Sphere2D) ArrayList(java.util.ArrayList) SphericalPolygonsSet(org.hipparchus.geometry.spherical.twod.SphericalPolygonsSet) S2Point(org.hipparchus.geometry.spherical.twod.S2Point) GeodeticPoint(org.orekit.bodies.GeodeticPoint) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D)

Example 4 with S2Point

use of org.hipparchus.geometry.spherical.twod.S2Point in project Orekit by CS-SI.

the class EllipsoidTessellator method tessellate.

/**
 * Tessellate a zone of interest into tiles.
 * <p>
 * The created tiles will completely cover the zone of interest.
 * </p>
 * <p>
 * The distance between a vertex at a tile corner and the vertex at the same corner
 * in the next vertex are computed by subtracting the overlap width (resp. overlap length)
 * from the full width (resp. full length). If for example the full width is specified to
 * be 55 km and the overlap in width is specified to be +5 km, successive tiles would span
 * as follows:
 * </p>
 * <ul>
 *   <li>tile 1 covering from   0 km to  55 km</li>
 *   <li>tile 2 covering from  50 km to 105 km</li>
 *   <li>tile 3 covering from 100 km to 155 km</li>
 *   <li>...</li>
 * </ul>
 * <p>
 * In order to achieve the same 50 km step but using a 5 km gap instead of an overlap, one would
 * need to specify the full width to be 45 km and the overlap to be -5 km. With these settings,
 * successive tiles would span as follows:
 * </p>
 * <ul>
 *   <li>tile 1 covering from   0 km to  45 km</li>
 *   <li>tile 2 covering from  50 km to  95 km</li>
 *   <li>tile 3 covering from 100 km to 155 km</li>
 *   <li>...</li>
 * </ul>
 * @param zone zone of interest to tessellate
 * @param fullWidth full tiles width as a distance on surface, including overlap (in meters)
 * @param fullLength full tiles length as a distance on surface, including overlap (in meters)
 * @param widthOverlap overlap between adjacent tiles (in meters), if negative the tiles
 * will have a gap between each other instead of an overlap
 * @param lengthOverlap overlap between adjacent tiles (in meters), if negative the tiles
 * will have a gap between each other instead of an overlap
 * @param truncateLastWidth if true, the first tiles strip will be started as close as
 * possible to the zone of interest, and the last tiles strip will have its width reduced
 * to also remain close to the zone of interest; if false all tiles strip will have the
 * same {@code fullWidth} and they will be balanced around zone of interest
 * @param truncateLastLength if true, the first tile in each strip will be started as close as
 * possible to the zone of interest, and the last tile in each strip will have its length reduced
 * to also remain close to the zone of interest; if false all tiles in each strip will have the
 * same {@code fullLength} and they will be balanced around zone of interest
 * @return a list of lists of tiles covering the zone of interest,
 * each sub-list corresponding to a part not connected to the other
 * parts (for example for islands)
 * @exception OrekitException if the zone cannot be tessellated
 */
public List<List<Tile>> tessellate(final SphericalPolygonsSet zone, final double fullWidth, final double fullLength, final double widthOverlap, final double lengthOverlap, final boolean truncateLastWidth, final boolean truncateLastLength) throws OrekitException {
    final double splitWidth = (fullWidth - widthOverlap) / quantization;
    final double splitLength = (fullLength - lengthOverlap) / quantization;
    final Map<Mesh, List<Tile>> map = new IdentityHashMap<Mesh, List<Tile>>();
    final RegionFactory<Sphere2D> factory = new RegionFactory<Sphere2D>();
    SphericalPolygonsSet remaining = (SphericalPolygonsSet) zone.copySelf();
    S2Point inside = getInsidePoint(remaining);
    while (inside != null) {
        // find a mesh covering at least one connected part of the zone
        final List<Mesh.Node> mergingSeeds = new ArrayList<Mesh.Node>();
        Mesh mesh = new Mesh(ellipsoid, zone, aiming, splitLength, splitWidth, inside);
        mergingSeeds.add(mesh.getNode(0, 0));
        List<Tile> tiles = null;
        while (!mergingSeeds.isEmpty()) {
            // expand the mesh around the seed
            neighborExpandMesh(mesh, mergingSeeds, zone);
            // extract the tiles from the mesh
            // this further expands the mesh so tiles dimensions are multiples of quantization,
            // hence it must be performed here before checking meshes independence
            tiles = extractTiles(mesh, zone, lengthOverlap, widthOverlap, truncateLastWidth, truncateLastLength);
            // check the mesh is independent from existing meshes
            mergingSeeds.clear();
            for (final Map.Entry<Mesh, List<Tile>> entry : map.entrySet()) {
                if (!factory.intersection(mesh.getCoverage(), entry.getKey().getCoverage()).isEmpty()) {
                    // the meshes are not independent, they intersect each other!
                    // merge the two meshes together
                    mesh = mergeMeshes(mesh, entry.getKey(), mergingSeeds);
                    map.remove(entry.getKey());
                    break;
                }
            }
        }
        // remove the part of the zone covered by the mesh
        remaining = (SphericalPolygonsSet) factory.difference(remaining, mesh.getCoverage());
        inside = getInsidePoint(remaining);
        map.put(mesh, tiles);
    }
    // concatenate the lists from the independent meshes
    final List<List<Tile>> tilesLists = new ArrayList<List<Tile>>(map.size());
    for (final Map.Entry<Mesh, List<Tile>> entry : map.entrySet()) {
        tilesLists.add(entry.getValue());
    }
    return tilesLists;
}
Also used : S2Point(org.hipparchus.geometry.spherical.twod.S2Point) IdentityHashMap(java.util.IdentityHashMap) Sphere2D(org.hipparchus.geometry.spherical.twod.Sphere2D) ArrayList(java.util.ArrayList) SphericalPolygonsSet(org.hipparchus.geometry.spherical.twod.SphericalPolygonsSet) RegionFactory(org.hipparchus.geometry.partitioning.RegionFactory) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Example 5 with S2Point

use of org.hipparchus.geometry.spherical.twod.S2Point in project Orekit by CS-SI.

the class EllipsoidTessellator method sample.

/**
 * Sample a zone of interest into a grid sample of {@link GeodeticPoint geodetic points}.
 * <p>
 * The created points will be entirely within the zone of interest.
 * </p>
 * @param zone zone of interest to sample
 * @param width grid sample cells width as a distance on surface (in meters)
 * @param length grid sample cells length as a distance on surface (in meters)
 * @return a list of lists of points sampling the zone of interest,
 * each sub-list corresponding to a part not connected to the other
 * parts (for example for islands)
 * @exception OrekitException if the zone cannot be sampled
 */
public List<List<GeodeticPoint>> sample(final SphericalPolygonsSet zone, final double width, final double length) throws OrekitException {
    final double splitWidth = width / quantization;
    final double splitLength = length / quantization;
    final Map<Mesh, List<GeodeticPoint>> map = new IdentityHashMap<Mesh, List<GeodeticPoint>>();
    final RegionFactory<Sphere2D> factory = new RegionFactory<Sphere2D>();
    SphericalPolygonsSet remaining = (SphericalPolygonsSet) zone.copySelf();
    S2Point inside = getInsidePoint(remaining);
    while (inside != null) {
        // find a mesh covering at least one connected part of the zone
        final List<Mesh.Node> mergingSeeds = new ArrayList<Mesh.Node>();
        Mesh mesh = new Mesh(ellipsoid, zone, aiming, splitLength, splitWidth, inside);
        mergingSeeds.add(mesh.getNode(0, 0));
        List<GeodeticPoint> sample = null;
        while (!mergingSeeds.isEmpty()) {
            // expand the mesh around the seed
            neighborExpandMesh(mesh, mergingSeeds, zone);
            // extract the sample from the mesh
            // this further expands the mesh so sample cells dimensions are multiples of quantization,
            // hence it must be performed here before checking meshes independence
            sample = extractSample(mesh, zone);
            // check the mesh is independent from existing meshes
            mergingSeeds.clear();
            for (final Map.Entry<Mesh, List<GeodeticPoint>> entry : map.entrySet()) {
                if (!factory.intersection(mesh.getCoverage(), entry.getKey().getCoverage()).isEmpty()) {
                    // the meshes are not independent, they intersect each other!
                    // merge the two meshes together
                    mesh = mergeMeshes(mesh, entry.getKey(), mergingSeeds);
                    map.remove(entry.getKey());
                    break;
                }
            }
        }
        // remove the part of the zone covered by the mesh
        remaining = (SphericalPolygonsSet) factory.difference(remaining, mesh.getCoverage());
        inside = getInsidePoint(remaining);
        map.put(mesh, sample);
    }
    // concatenate the lists from the independent meshes
    final List<List<GeodeticPoint>> sampleLists = new ArrayList<List<GeodeticPoint>>(map.size());
    for (final Map.Entry<Mesh, List<GeodeticPoint>> entry : map.entrySet()) {
        sampleLists.add(entry.getValue());
    }
    return sampleLists;
}
Also used : S2Point(org.hipparchus.geometry.spherical.twod.S2Point) IdentityHashMap(java.util.IdentityHashMap) Sphere2D(org.hipparchus.geometry.spherical.twod.Sphere2D) ArrayList(java.util.ArrayList) SphericalPolygonsSet(org.hipparchus.geometry.spherical.twod.SphericalPolygonsSet) RegionFactory(org.hipparchus.geometry.partitioning.RegionFactory) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) GeodeticPoint(org.orekit.bodies.GeodeticPoint) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Aggregations

S2Point (org.hipparchus.geometry.spherical.twod.S2Point)13 GeodeticPoint (org.orekit.bodies.GeodeticPoint)8 SphericalPolygonsSet (org.hipparchus.geometry.spherical.twod.SphericalPolygonsSet)7 ArrayList (java.util.ArrayList)5 List (java.util.List)4 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)4 Edge (org.hipparchus.geometry.spherical.twod.Edge)3 Sphere2D (org.hipparchus.geometry.spherical.twod.Sphere2D)3 Vertex (org.hipparchus.geometry.spherical.twod.Vertex)3 IdentityHashMap (java.util.IdentityHashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 RegionFactory (org.hipparchus.geometry.partitioning.RegionFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Line (org.hipparchus.geometry.euclidean.threed.Line)1 Test (org.junit.Test)1 OrekitException (org.orekit.errors.OrekitException)1