Пример #1
0
  public TraversePointInfo startTraverse(Point hitPoint, float maxDistance) {
    float distance = 9999, smallestDistance = 9999;
    nodes = renderNodes;
    PathNode t = null;
    for (int i = 0; i < nodes.size(); i++) {
      distance = nodes.get(i).getLocation().distancePoint2Point(hitPoint);
      //			Helper.printKeyVal("PathNode: ", nodes.get(i).getLocation().toString());
      //			Helper.printKeyVal("Distance", distance);
      if (distance < smallestDistance) {
        //				Helper.printKeyVal("New smallest point: ", nodes.get(i).getLocation().toString());
        //				Helper.printKeyVal("New smallest Distance", distance);
        smallestDistance = distance;
        t = nodes.get(i);
      }
    }

    if (smallestDistance > maxDistance) return null;

    TraversePointInfo info = new TraversePointInfo();
    info.setPathNode(t);
    info.setTraverseLocation(t.getLocation());
    info.setDistance(0);

    distance = 0;
    for (int i = 0; i < nodes.size(); i++) {
      if (nodes.get(i).equals(t)) break;
      distance += nodes.get(i).getRightDistance();
    }
    info.setTotalDistanceInPath(distance);
    //		Helper.printKeyVal("Total Distance Set: ", info.getTotalDistanceInPath());
    info.setPath(this);

    return info;
  }
Пример #2
0
  /**
   * Starts traversing from the starting point of the path
   *
   * @return returns TraversePointInfo for the landing point on the Path
   */
  public TraversePointInfo startTraverse() {
    TraversePointInfo info = new TraversePointInfo();

    if (nodes == null) return null;
    if (nodes.size() == 0) return null;

    info.setPathNode(nodes.get(0));
    info.setTraverseLocation(nodes.get(0).getLocation());
    info.setDistance(0);
    info.setTotalDistanceInPath(0);
    info.setPath(this);
    return info;
  }
Пример #3
0
  /**
   * Starts traversing with given hit point and maxDistance from the hit. It returns closest point
   * on the closest segment.
   *
   * @param hitPoint Any point on the screen.
   * @param maxDistance Maximum distance from the hit-point to the landing point on the comparing
   *     path segment. Needed for detection.
   * @return Using the given hit-point, returns TraversePointInfo for the landing point on the Path
   */
  public TraversePointInfo startTraverse0(Point hitPoint, float maxDistance) {
    Helper.println("\n\n\nStarting: ");
    float distance, d;
    for (int i = 0; i < nodes.size() - 1; i++) {
      //			if(!insideCheck(nodes.get(i).getLocation(), nodes.get(i+1).getLocation(), hitPoint))
      //				continue;
      distance =
          (float)
              Helper.pointToLineDistance(
                  nodes.get(i).getLocation(), nodes.get(i + 1).getLocation(), hitPoint);
      //			Helper.printKeyVal("node: " + nodes.get(i)+ "  to  " + nodes.get(i+1), distance);

      if (distance <= maxDistance) {
        //				Helper.printKeyVal("Node selected: ", nodes.get(i).getLocation().toString());

        TraversePointInfo info = new TraversePointInfo();
        info.setPathNode(nodes.get(i));

        d = (float) Math.pow(info.getPathNode().getLocation().distancePoint2Point(hitPoint), 2);
        distance = distance * distance;
        //				Helper.printKeyVal("Distance measured: ", Math.sqrt(d-distance));
        distance = (float) Math.sqrt(d - distance);

        info.setTraverseLocation(info.getPathNode().getPointAtDistance(distance));
        //				Helper.printKeyVal("Point Set: ", info.getTraverseLocation().toString());

        info.setDistance(distance);
        //				Helper.printKeyVal("Distance Set: ", info.getDistance());

        for (int j = 0; j <= i; j++) {
          distance += nodes.get(j).getLeftDistance();
        }

        info.setTotalDistanceInPath(distance);
        //				Helper.printKeyVal("Total Distance Set: ", info.getTotalDistanceInPath());
        info.setPath(this);

        return info;
      }
    }
    return null;
  }