Ejemplo n.º 1
0
  public static double getHighestAngle(DCHalfEdge edge, Point focus) {
    Point target;

    if (edge.start.compareTo(focus) == 0) {

      target = edge.end;
    } else {

      target = edge.start;
    }
    // reset edge with higher point as start;

    // return angle of edge from start to end
    return Geom.cartToPolar(target.getX() - focus.getX(), target.getY() - focus.getY())[1];
  }
Ejemplo n.º 2
0
 // find centroid of a polygon
 public static Point findCentroid(Polygon polygon) {
   DoublyConnectedEdgeList dc = Geom.linesToDCEdgeList(polygon);
   return Geom.findCentroid(dc);
 }
Ejemplo n.º 3
0
  public static char rayTypePointInPolygon(Point q, DoublyConnectedEdgeList p) {
    double width = 5000;
    int i, i1; // point index; i1 = 1-1 mod n;
    int n = p.edges.size();
    int d = 2; // dimension index
    int Rcross = 0; // number of right edge/ray crossings
    int Lcross = 0; // number of left edge/ray crossings
    boolean Rstrad, Lstrad; // flags that indicate the edge straddles the x axis
    // Vector<CompPoint> p = new Vector<CompPoint>();

    // for each edge in poly, see if crosses rays
    /*for(i=0;i<n;i++){
    	DCHalfEdge edge = p.edge.get(i);
    	CompPoint newPoint = new CompPoint(edge.start.getX()-q.getX(),edge.start.getY()-q.getY());

    }*/

    // check if p is a vertex of the polygon
    for (i = 0; i < n; i++) {
      i1 = (i + n - 1) % n;
      DCHalfEdge edge = p.edges.get(i);
      if (q.compareTo(edge.start) == 0 || q.compareTo(edge.end) == 0) {
        return 'v';
      }
    }

    DCHalfEdge rEdge = new DCHalfEdge(q, new Point(width, q.getY()));
    DCHalfEdge lEdge = new DCHalfEdge(q, new Point(0, q.getY()));

    Rcross = Geom.edgeIntersectsPolygon(rEdge, p).size();
    Lcross = Geom.edgeIntersectsPolygon(lEdge, p).size();
    // System.out.println("Rcross = "+Rcross+",Lcross="+Lcross);
    /*i1=(i+n-1)%n;
    	DCHalfEdge edge1 = p.edges.get(i1);
    	Rstrad = (edge.start.getY()>q.getY())!=(edge1.start.getY()>q.getY());
    	Lstrad = (edge.start.getY()<q.getY())!=(edge1.start.getY()<q.getY());

    	if(Rstrad|| Lstrad){
    		double x = (edge.start.getX()*edge1.start.getY()-edge1.start.getX()*edge.start.getY())/(edge1.start.getY()-edge.start.getY());

    		if(Rstrad && x> q.getX()){
    			Rcross++;
    		}
    		if(Lstrad && x> q.getX()){
    			Lcross++;
    		}

    	}
    }
    */
    // q is on an edge if L/Rcross counts are not the same parity
    if ((Rcross % 2) != (Lcross % 2)) {
      return 'e';
    }

    if ((Rcross % 2) == 1) {
      return 'i';
    } else {
      return 'o';
    }
  }
Ejemplo n.º 4
0
  public static DCHalfEdge getIntersectedEdge(
      Point focus, Point direction, DCHalfEdge parentEdge, DoublyConnectedEdgeList border) {

    DCHalfEdge edge = new DCHalfEdge(focus, direction);

    double dx = direction.getX() - focus.getX(); // direction x
    double dy = direction.getY() - focus.getY(); // direction y

    DCHalfEdge borderEdge = null; // selected border edge for intersection;

    double[] thetas = border.getBorderPoints(focus); // degrees of all points along the border

    double edgeTheta = Geom.cartToPolar(dx, dy)[1]; // degree of edge
    double selectedTheta = -1;
    // myParent.println("\n\n\n edgeTheta="+edgeTheta+"\n\n\n");

    for (int i = 0;
        i < thetas.length;
        i++) { // iterate through all edges and look for correct point of intersection
      // myParent.println("edge "+i+" theta="+thetas[i]+" x="+border.edges.get(i).start.getX()+"
      // y="+border.edges.get(i).start.getY());
      int after = i + 1;
      if (i == thetas.length - 1) {
        after = 0;
      }

      if (thetas[after]
          > thetas[
              i]) { // special case where angle of previous edge is greater than angle of current
        // edge
        // myParent.println("call special case");
        if (edgeTheta >= thetas[after]
            || edgeTheta < thetas[i]) { // detects quadrant of intersection for special case

          if (edgeTheta > thetas[i]) {
            borderEdge = border.edges.get(i - 1);

            selectedTheta = thetas[i];
          } else {
            borderEdge = border.edges.get(i);

            selectedTheta = thetas[after];
          }

          /*myParent.println("\n\n\n edgeTheta="+edgeTheta);
          myParent.println("theta i="+thetas[i]);
          myParent.println("theta after="+thetas[after]);
          myParent.println("selected theta="+selectedTheta);
          myParent.println("start x,y,="+focus.getX()+","+focus.getY());
          myParent.println("end x,y,="+direction.getX()+","+direction.getY());
          myParent.println("intersection x,y,="+intersection.getX()+","+intersection.getY()+"\n\n\n");*/

          parentEdge.infiniteEdge = 1;
          break;
        }
      } else { // otherwise all thetas should be greater than the preceeding theta

        if (edgeTheta <= thetas[i]
            && edgeTheta > thetas[after]) { // detects quadrant of intersection

          borderEdge = border.edges.get(i);
          selectedTheta = thetas[i];
          break;
        }
      }
    }

    return borderEdge;
  }