0

I have rather simple task and I would like to ask you for recommendation. I hope there is a Java library which can help me.

Description

Given

  1. GSM cell with longitude, latitude, azimuth, max and min distance. With the help of these parameters I can describe a sector (a part of circle)
  2. longitude, latitude and a radious of an object.

Meaning

Each GSM cell consists of several sectors (they start from one point). Each object is represented as a circle (longitude, latitude, radius). A circle can

  1. touch one sector
  2. intercept one sector
  3. intercept several sectors of a given GSM cell

Task: I get a list of GSM cells and an object. I need to find all iterceptions/touches of an object with some sectors. I need to order by resulting list of interceptions by square of interception.

Look like typical math/geometry task. Is there any library in Java which can help me?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Capacytron
  • 3,425
  • 6
  • 47
  • 80
  • Looks like pure domain related use-case you want to implement. I don't think, you'll get a fairly free to use library for this. – R Kaja Mohideen Feb 04 '13 at 06:52
  • It can be generalized to: find intersection of some sectors with geographical coordinates and circle with geographical coordinates. It doesn't look like something domain-related. – Capacytron Feb 04 '13 at 06:59
  • after transform lat lon to x,y itbis simple school mathematics – AlexWien Feb 04 '13 at 12:35

2 Answers2

0

1) tranform all latitude, lomgitude coordinates to cartesian x,y in meters. ( you can use the simple EuqiDistant Projection) serach here or on wiki, google

2) once all are in x,y coords, it is school mathematics:
point is inside circle? : distance between point and circle center < radius
point in circle segment? point is inside circle and angle from point to center point is within sector azimut range.

Calculate the angle from point1 to point2 using

angleRad = atan2(dy/dx);

where dy = p2.y - p1.y
dx analog

AlexWien
  • 28,470
  • 6
  • 53
  • 83
0

So here is my solution. We deciced that "center" of 2D projection should be relative. It does fit our task. Here are some code samples:

public final class GeometryUtil {
    /**
        https://www.cfa.harvard.edu/~dfabricant/huchra/ay145/constants.html
        1 Earth Radius = 6.37814x108 cm = 6.37814x10^6 m (Equatorial)
     */
    public static final double EARTH_RADIUS_IN_METERS = 6.37814e+6;

    private GeometryUtil(){}

    /**
     * @param geoPoint is a point of some object you want to translate to Cartesian.
     * @param geoPointRelative is a point of relative center.
     *                         We suppose that this relative GeoPoint is a center for the first parameter.
     * */
    public static Coordinate toCoordinate(GeoPoint geoPoint, GeoPoint geoPointRelative){
        return new Coordinate(toX(geoPoint, geoPointRelative.getLongitude()),
                              toY(geoPoint, geoPointRelative.getLatitude()));
    }

    public static double toX(GeoPoint geoPoint, double relativeLongitude){
        return  EARTH_RADIUS_IN_METERS *
                cos(toRadians(geoPoint.getLatitude()))  *
                toRadians(geoPoint.getLongitude()- relativeLongitude);
    }

    public static double toY(GeoPoint geoPoint, double relativeLatitude){
        return  EARTH_RADIUS_IN_METERS * toRadians(geoPoint.getLatitude() - relativeLatitude);
    }

}

Here is a builder for Geometry figures:

public final class GeometryBuilder {

    private static final int DIAMETER_MULTIPLIER = 2;
    private static final int TURN_LEFT = 90;    //We should start to roll to the right from "North"/"Up"/12 o'clock

    private GeometryBuilder(){}


    public static Circle buildCirlce(GeoPoint centerOfCircle, GeoPoint relativeCenter, Distance radiusDistance){
        GeometricShapeFactory geometricShapeFactory = new GeometricShapeFactory();
        geometricShapeFactory.setCentre(GeometryUtil.toCoordinate(centerOfCircle, relativeCenter));
        geometricShapeFactory.setSize(radiusDistance.getMeters() * DIAMETER_MULTIPLIER);
        return new Circle(geometricShapeFactory.createEllipse());
    }


     public static Sector buildGSMCellSector(GSMCellLocation gsmCellLocation, GeoPoint relativeCenter){
        GeometricShapeFactory geometricShapeFactory = new GeometricShapeFactory();
        geometricShapeFactory.setCentre(GeometryUtil.toCoordinate(gsmCellLocation.getGeoPoint(), relativeCenter));
        geometricShapeFactory.setSize(gsmCellLocation.getMidDist() * DIAMETER_MULTIPLIER);
        return new Sector(geometricShapeFactory.createArcPolygon(-toRadians(gsmCellLocation.getEndAngle()- TURN_LEFT),
                                                                  toRadians(gsmCellLocation.getAngleWidth())));
    }
}

I should mention that TURN_LEFT is specific. Angles of my object starts at 12 o'clock. Geometry library starts to count from 3 o'clock. That it why I have to turn it 3 hours (90 degrees) back.

The problem is solved. I've also used LiteShape to draw some images to PNG file. Everythng is ok.

Capacytron
  • 3,425
  • 6
  • 47
  • 80