コード例 #1
0
 void checkTransformation(AffineTransformation trans0, AffineTransformation trans1) {
   double[] m0 = trans0.getMatrixEntries();
   double[] m1 = trans1.getMatrixEntries();
   for (int i = 0; i < m0.length; i++) {
     assertEquals(m0[i], m1[i], 0.000005);
   }
 }
コード例 #2
0
  public void testCompose2() {
    AffineTransformation t0 = AffineTransformation.reflectionInstance(0, 0, 1, 0);
    t0.reflect(0, 0, 0, -1);

    AffineTransformation t1 = AffineTransformation.rotationInstance(Math.PI);

    checkTransformation(t0, t1);
  }
コード例 #3
0
  public void testCompose3() {
    AffineTransformation t0 = AffineTransformation.reflectionInstance(0, 10, 10, 0);
    t0.translate(-10, -10);

    AffineTransformation t1 = AffineTransformation.reflectionInstance(0, 0, -1, 1);

    checkTransformation(t0, t1);
  }
コード例 #4
0
  public void testComposeRotation1() {
    AffineTransformation t0 = AffineTransformation.rotationInstance(1, 10, 10);

    AffineTransformation t1 = AffineTransformation.translationInstance(-10, -10);
    t1.rotate(1);
    t1.translate(10, 10);

    checkTransformation(t0, t1);
  }
コード例 #5
0
 void checkTransformation(String geomStr)
     throws IOException, ParseException, NoninvertibleTransformationException {
   Geometry geom = rdr.read(geomStr);
   AffineTransformation trans = AffineTransformation.rotationInstance(Math.PI / 2);
   AffineTransformation inv = trans.getInverse();
   Geometry transGeom = (Geometry) geom.clone();
   transGeom.apply(trans);
   // System.out.println(transGeom);
   transGeom.apply(inv);
   // check if transformed geometry is equal to original
   boolean isEqual = geom.equalsExact(transGeom, 0.0005);
   assertTrue(isEqual);
 }
コード例 #6
0
 public void testReflectXY2() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.reflectionInstance(1, -1);
   checkTransformation(10, 0, t, 0, -10);
   checkTransformation(0, 10, t, -10, 0);
   checkTransformation(-10, -10, t, 10, 10);
   checkTransformation(-3, -4, t, 4, 3);
 }
コード例 #7
0
 public void testRotateAroundPoint1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.rotationInstance(Math.PI / 2, 1, 1);
   checkTransformation(1, 1, t, 1, 1);
   checkTransformation(10, 0, t, 2, 10);
   checkTransformation(0, 10, t, -8, 0);
   checkTransformation(-10, -10, t, 12, -10);
 }
コード例 #8
0
  public void testCompose1() {
    AffineTransformation t0 = AffineTransformation.translationInstance(10, 0);
    t0.rotate(Math.PI / 2);
    t0.translate(0, -10);

    AffineTransformation t1 = AffineTransformation.translationInstance(0, 0);
    t1.rotate(Math.PI / 2);

    checkTransformation(t0, t1);
  }
コード例 #9
0
  /**
   * Checks that a transformation produces the expected result
   *
   * @param x the input pt x
   * @param y the input pt y
   * @param trans the transformation
   * @param xp the expected output x
   * @param yp the expected output y
   */
  void checkTransformation(double x, double y, AffineTransformation trans, double xp, double yp) {
    Coordinate p = new Coordinate(x, y);
    Coordinate p2 = new Coordinate();
    trans.transform(p, p2);
    assertEquals(xp, p2.x, .00005);
    assertEquals(yp, p2.y, .00005);

    // if the transformation is invertible, test the inverse
    try {
      AffineTransformation invTrans = trans.getInverse();
      Coordinate pInv = new Coordinate();
      invTrans.transform(p2, pInv);
      assertEquals(x, pInv.x, .00005);
      assertEquals(y, pInv.y, .00005);

      double det = trans.getDeterminant();
      double detInv = invTrans.getDeterminant();
      assertEquals(det, 1.0 / detInv, .00005);

    } catch (NoninvertibleTransformationException ex) {
    }
  }
コード例 #10
0
 public void testTranslateRotate1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.translationInstance(3, 3).rotate(Math.PI / 2);
   checkTransformation(10, 0, t, -3, 13);
   checkTransformation(-10, -10, t, 7, -7);
 }
コード例 #11
0
 public void testTranslate1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.translationInstance(2, 3);
   checkTransformation(1, 0, t, 3, 3);
   checkTransformation(0, 0, t, 2, 3);
   checkTransformation(-10, -5, t, -8, -2);
 }
コード例 #12
0
 public void testShear1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.shearInstance(2, 3);
   checkTransformation(10, 0, t, 10, 30);
 }
コード例 #13
0
 public void testReflectXYXY1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.reflectionInstance(0, 5, 5, 0);
   checkTransformation(5, 0, t, 5, 0);
   checkTransformation(0, 0, t, 5, 5);
   checkTransformation(-10, -10, t, 15, 15);
 }
コード例 #14
0
ファイル: StraightLeg.java プロジェクト: waqas64/debrief
  /**
   * create a straight leg.
   *
   * @param name what to call the leg
   * @param states the set of bounded states that comprise the leg
   */
  void decideScaledPolygons(StraightRoute theRoute) {
    // do we already know this isn't possible?
    if (!theRoute.isPossible()) return;

    // bugger, we'll have to get on with our hard sums then

    // sort out the origin.
    State startState = theRoute.getStates().get(0);
    Coordinate startCoord = startState.getLocation().getCoordinate();

    // also sort out the end state
    State endState = theRoute.getStates().get(theRoute.getStates().size() - 1);
    Point endPt = endState.getLocation();

    // remeber the start time
    long tZero = startState.getTime().getTime();

    // how long is the total run?
    double elapsed = theRoute.getElapsedTime();

    // allow for multiple fidelity processing
    int ctr = 0;

    // how frequently shall we process the polygons?
    // calculating the scaled polygons is really expensive. this
    // give us most of the benefits, at a third of the speed (well,
    // with a freq of '3' it does)
    final int freq = 3;

    // loop through our states
    Iterator<BoundedState> iter = _states.iterator();
    while (iter.hasNext()) {
      BoundedState thisB = iter.next();

      LocationRange thisL = thisB.getLocation();
      if (thisL != null) {
        // ok, what's the time difference
        long thisDelta = thisB.getTime().getTime() - tZero;

        // convert to secs
        long tDelta = thisDelta / 1000;

        // is this our first state
        if (tDelta > 0) {
          // ok, we've got a location - increment the counter
          ctr++;

          // is this one we're going to process?
          if (((ctr % freq) == 0) || ctr == _states.size() - 1) {
            double scale = elapsed / tDelta;

            // ok, project the shape forwards
            AffineTransformation st =
                AffineTransformation.scaleInstance(scale, scale, startCoord.x, startCoord.y);

            // ok, apply the transform to the location
            /*Geometry originalGeom = thisL.getGeometry();
            Geometry newGeom = st.transform(originalGeom);

            // see if the end point is in the new geometry
            if (endPt.coveredBy(newGeom))
            {
            	// cool, this route works
            }
            else
            {
            	// bugger, can't do this one
            	theRoute.setImpossible();
            	break;
            }*/
            if (!MathUtils.rayTracing(endPt, thisL.getGeometry(), st)) {
              theRoute.setImpossible();
              break;
            }
          }
        }
      }
    }
  }
コード例 #15
0
 public void testScale1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.scaleInstance(2, 3);
   checkTransformation(10, 0, t, 20, 0);
   checkTransformation(0, 10, t, 0, 30);
   checkTransformation(-10, -10, t, -20, -30);
 }
コード例 #16
0
  /**
   * Create device locations in a path near the main zone.
   *
   * @param assignment
   * @param start
   * @return
   * @throws SiteWhereException
   */
  protected List<IDeviceLocation> createDeviceLocations(IDeviceAssignment assignment, Date date)
      throws SiteWhereException {
    long current = date.getTime();
    Polygon zone = GeoUtils.createPolygonForLocations(zoneLocations);
    Point centroid = zone.getCentroid();

    // Calculate length of steps between locations based on bounding circle.
    MinimumBoundingCircle circle = new MinimumBoundingCircle(zone);
    double step = circle.getRadius() / 10;

    double cx = centroid.getX();
    double cy = centroid.getY();
    double deltaX = (Math.sqrt(Math.random()) * step * 2) - step;
    double deltaY = (Math.sqrt(Math.random()) * step * 2) - step;

    // Used to rotate deltas to turn path and stay inside polygon.
    AffineTransformation xform = new AffineTransformation();
    xform.rotate(Math.toRadians(22.5));

    List<IDeviceLocation> results = new ArrayList<IDeviceLocation>();
    GeometryFactory factory = new GeometryFactory();
    for (int x = 0; x < LOCATIONS_PER_ASSIGNMENT; x++) {
      boolean foundNext = false;

      // Add a little randomness to path.
      double waver = ((Math.random() * 20) - 10.0);
      AffineTransformation waverXform = new AffineTransformation();
      waverXform.rotate(Math.toRadians(waver));
      Coordinate waverDelta = new Coordinate(deltaX, deltaY);
      waverXform.transform(waverDelta, waverDelta);
      deltaX = waverDelta.x;
      deltaY = waverDelta.y;

      while (!foundNext) {
        Coordinate start = new Coordinate(cx, cy);
        Coordinate end = new Coordinate(cx + deltaX, cy + deltaY);
        Coordinate[] lineCoords = {start, end};
        LineString line = factory.createLineString(lineCoords);
        if (zone.contains(line)) {
          DeviceLocationCreateRequest request = new DeviceLocationCreateRequest();
          request.setLatitude(end.y);
          request.setLongitude(end.x);
          request.setElevation(0.0);
          request.setEventDate(new Date(current));
          IDeviceLocation created =
              getDeviceManagement().addDeviceLocation(assignment.getToken(), request);
          results.add(created);

          cx = cx + deltaX;
          cy = cy + deltaY;
          foundNext = true;
        } else {
          // Rotate deltas and try again.
          Coordinate delta = new Coordinate(deltaX, deltaY);
          xform.transform(delta, delta);
          deltaX = delta.x;
          deltaY = delta.y;
        }
      }
      current += 30000;
    }
    LOGGER.info(PREFIX_CREATE_EVENTS + " " + results.size() + " locations. ");
    return results;
  }
コード例 #17
0
 public void testRotate1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.rotationInstance(Math.PI / 2);
   checkTransformation(10, 0, t, 0, 10);
   checkTransformation(0, 10, t, -10, 0);
   checkTransformation(-10, -10, t, 10, -10);
 }