示例#1
0
void Infill::addInfillPoly(Poly p)
{
  // Poly *zigzagpoly = NULL;
  switch (type) {
  // case ZigzagInfill: // take parallel lines and connect ends
  //   zigzagpoly = new Poly(p.getZ(),extrusionfactor);
  case BridgeInfill:
  case ParallelInfill:
    { // make lines instead of closed polygons
      Vector2d l,rotl;
      double sina = sin(-angle);
      double cosa = cos(-angle);
      // use the lines that have the angle of this Infill
      for (uint i=0; i < p.size() ; i+=1 )
  	{
  	  l = (p.getVertexCircular(i+1) - p.getVertexCircular(i));     
	  // rotate with neg. infill angle and see whether it's 90° as infill lines
	  rotl = Vector2d(l.x*cosa-l.y*sina, 
			  l.y*cosa+l.x*sina);
	  if (abs(rotl.x) < 0.1 && abs(rotl.y) > 0.1)
  	    {
	      // if (zigzagpoly) {
	      // 	zigzagpoly->addVertex(p.getVertexCircular(i+i%2));
	      // 	zigzagpoly->addVertex(p.getVertexCircular(i+1+i%2));
	      // } else
	      {
		Poly newpoly(p.getZ(), extrusionfactor);
		newpoly.vertices.push_back(p.getVertexCircular(i));
		newpoly.vertices.push_back(p.getVertexCircular(i+1));
		infillpolys.push_back(newpoly);
	      }
  	    }
	  // else
	  //   if (zigzagpoly) {
	  //     zigzagpoly->addVertex(p.getVertexCircular(i));	      
	  //   }
  	}
      // if (zigzagpoly) {
      // 	cerr << zigzagpoly->size()<< endl;
      // 	if (zigzagpoly->size()>0)
      // 	  infillpolys.push_back(*zigzagpoly);
      // 	else delete zigzagpoly;
      // 	cerr << infillpolys.size()<< endl;
      // }
    } 
    break;
  default:
    {
      p.setExtrusionFactor(extrusionfactor);
      infillpolys.push_back(p);
    }
  }
}
示例#2
0
// returns length and two points
double Poly::shortestConnectionSq(const Poly &p2, Vector2d &start, Vector2d &end) const
{
    double min1 = 100000000, min2 = 100000000;
    int minindex1=0, minindex2=0;
    Vector2d onpoint1, onpoint2;
    // test this vertices
    for (uint i = 0; i < vertices.size(); i++) {
        for (uint j = 0; j < p2.vertices.size(); j++) {
            Vector2d onpoint; // on p2
            // dist from point i to lines on p2
            const double mindist =
                point_segment_distance_Sq(p2.vertices[j], p2.getVertexCircular(j+1),
                                          vertices[i], onpoint);
            if (mindist < min1) {
                min1 = mindist;
                onpoint1 = onpoint;
                minindex1 = i;
            }
        }
    }
    // test p2 vertices
    for (uint i = 0; i < p2.vertices.size(); i++) {
        for (uint j = 0; j < vertices.size(); j++) {
            Vector2d onpoint; // on this
            // dist from p2 point i to lines on this
            const double mindist =
                point_segment_distance_Sq(vertices[j], getVertexCircular(j+1),
                                          p2.vertices[i], onpoint);
            if (mindist < min2) {
                min2 = mindist;
                onpoint2 = onpoint;
                minindex2 = i;
            }
        }
    }
    if (min1 < min2) { // this vertex, some point on p2 lines
        start = getVertexCircular(minindex1);
        end = onpoint1;
    } else { // p2 vertex, some point of this lines
        start = p2.getVertexCircular(minindex2);
        end = onpoint2;
    }
    return (end-start).squared_length();
}
示例#3
0
CL::Polygon Clipping::getClipperPolygon(const Poly &poly)
{
  CL::Polygon cpoly(poly.vertices.size());
  for(size_t i=0; i<poly.vertices.size();i++){
    Vector2d P1;
    // if (reverse)
      P1 = poly.getVertexCircular(-i); // have to reverse from/to clipper
    // else
    //   P1 = poly.getVertexCircular(i);
    cpoly[i]=(ClipperPoint(P1));
  }
  // doesn't work...:
  // cerr<< "poly is hole? "<< hole;
  // cerr<< " -- orient=" <<ClipperLib::Orientation(cpoly) << endl;
  // if (ClipperLib::Orientation(cpoly) == hole)
  //   std::reverse(cpoly.begin(),cpoly.end());
  return cpoly;
}