예제 #1
0
파일: 11343.cpp 프로젝트: pedrodelyra/uva
	bool intersects(segment& s) {
		auto det1 = det(p, q, s.p);
		auto det2 = det(p, q, s.q);
		auto det3 = det(s.p, s.q, p);
		auto det4 = det(s.p, s.q, q);

		return (equals(det1, 0) && contains(s.p)) || (equals(det2, 0) && contains(s.q)) ||
		       (equals(det3, 0) && s.contains(p)) || (equals(det4, 0) && s.contains(q)) || (det1 * det2 < -EPS && det3 * det4 < -EPS);
	}
예제 #2
0
void deal(double k, double a, segment &ref) {
	if (fabs(k) < eps) {
		if (a <= 0) ref.sset(-INF, INF);
		else ref.sset(INF, -INF);
	} else if (k > 0) {
		ref.sset(a/k, INF);
	} else {
		ref.sset(-INF, a/k);
	}
}
예제 #3
0
파일: program.cpp 프로젝트: metaphysis/Code
bool isIntersected(segment &s1, segment &s2)
{
    double cp1 = cp(s1.p1, s1.p2, s2.p1), cp2 = cp(s1.p1, s1.p2, s2.p2);
    double cp3 = cp(s2.p1, s2.p2, s1.p1), cp4 = cp(s2.p1, s2.p2, s1.p2);

    if ((cp1 * cp2 < 0) && (cp3 * cp4) < 0) return true;
    if (fabs(cp1) <= EPSILON && s1.contains(s2.p1)) return true;
    if (fabs(cp2) <= EPSILON && s1.contains(s2.p2)) return true;
    if (fabs(cp3) <= EPSILON && s2.contains(s1.p1)) return true;
    if (fabs(cp4) <= EPSILON && s2.contains(s1.p2)) return true;

    return false;
}
예제 #4
0
파일: program.cpp 프로젝트: dingswork/Code
bool isIntersected(segment s1, segment s2)
{
    line p = getLine(s1.p1, s1.p2), q = getLine(s2.p1, s2.p2);

    if (fabs(p.a * q.b - q.a * p.b) < EPSILON)
    {
        if (fabs(cp(s1.p1, s1.p2, s2.p1)) < EPSILON)
            return s1.contains(s2.p1) || s1.contains(s2.p2);
        return false;
    }

	point pi = getIntersection(p, q);
	return s1.contains(pi) && s2.contains(pi);
}
예제 #5
0
void test_segment(segment l1, segment l2)
{
    cout << "segments intersection" << endl;
    l1.s_print();
    l2.s_print();
    int ans = segments_intersection(l1, l2);
    if(ans == 0)
        cout << "no intersection" << endl;
    else if(ans == 2)
        cout << "one segment is 'on' another" << endl;
    else if(ans == 1)
        cout << "two segments intersection" << endl;
    cout << endl;
}
예제 #6
0
파일: manyarc.cpp 프로젝트: phma/bezitopo
vector<segment> manyQuad(segment cubic,int narcs)
/* Approximates cubic with narcs quadratics, where the first and last
 * are trimmed by the manyArcTrim function.
 */
{
  int i;
  double piecelength,thispiecelength,abscissa[5],overhang;
  double ordinate,lastordinate,startx;
  double startslope,midslope,endslope;
  double p,q,accel;
  vector<segment> ret;
  p=manyArcTrim(narcs);
  q=p*p-p+0.25;
  piecelength=cubic.length()/(narcs-2*p);
  overhang=piecelength*p;
  lastordinate=cubic.getstart().getz();
  startx=cubic.getstart().getx();
  for (i=0;i<narcs;i++)
  {
    abscissa[1]=i*piecelength+cubic.getstart().getx();
    abscissa[0]=abscissa[1]-overhang;
    abscissa[2]=abscissa[0]+piecelength/2;
    abscissa[4]=abscissa[0]+piecelength;
    abscissa[3]=abscissa[4]-overhang;
    midslope=(cubic.slope(abscissa[3]-startx)+cubic.slope(abscissa[1]-startx))/2;
    accel=(cubic.slope(abscissa[3]-startx)-cubic.slope(abscissa[1]-startx))/(abscissa[3]-abscissa[1]);
    thispiecelength=piecelength;
    if (i)
      startslope=midslope-accel*piecelength/2;
    else
    {
      startslope=midslope-accel*(abscissa[2]-abscissa[1]);
      //cout<<"startslope="<<startslope<<", should be "<<cubic.startslope()<<endl;
      thispiecelength-=overhang;
    }
    if (i<narcs-1)
      endslope=midslope+accel*piecelength/2;
    else
    {
      endslope=midslope+accel*(abscissa[3]-abscissa[2]);
      //cout<<"endslope="<<endslope<<", should be "<<cubic.endslope()<<endl;
      thispiecelength-=overhang;
    }
    ordinate=lastordinate+thispiecelength*(startslope+endslope)/2;
    ret.push_back(segment(xyz(abscissa[i==0]          ,0,lastordinate),
			  xyz(abscissa[4-(i==narcs-1)],0,    ordinate)));
    ret[i].setslope(START,startslope);
    ret[i].setslope(END,endslope);
    lastordinate=ordinate;
  }
  return ret;
}
예제 #7
0
void file_storage::read (record& _record, const segment _segment) const throw (storage_exception&) {
	std::fstream file;
	file.open(__fileName.c_str(), std::ios::binary|std::ios::in|std::ios::out);
	if(!file.is_open())
		throw file_open("Error: '" + __fileName + "' can not be opened!");
	file.seekg(_segment.begin);
	_record.read(file);
	if ((_record.size() != _segment.size()) | (file.tellg() != _segment.end + (std::streamoff)1))
		throw io_error("I/O error during read: '" + __fileName + "' may be corrupt or there may be a bug in the program!");
	file.close();
}
예제 #8
0
    void preProcess(Mat &image)
    {

        Mat im1;
        cv::resize(image,im1,Size(640,480));

        image=p.run(im1,20);
        imshow("original1",image);
        image=s.proces(image,1,300,20);
        imshow("r",image);
    }
예제 #9
0
void file_storage::append (const record& _record, segment& _segment) throw (storage_exception&) {
	std::fstream file;
	file.open(__fileName.c_str(), std::ios::binary|std::ios::in|std::ios::out|std::ios::ate);
	if(!file.is_open())
		throw file_open("Error: '" + __fileName + "' can not be opened!");
	_segment.begin = file.tellp();
	_record.write(file);
	_segment.end = file.tellp() - (std::streamoff)1;
	if (_record.size() != _segment.size())
		throw io_error("I/O error during append: '" + __fileName + "' may be corrupt or there may be a bug in the program!");
	file.close();
}
예제 #10
0
파일: manyarc.cpp 프로젝트: phma/bezitopo
vector<double> offsets(segment &a,vector<segment> &q)
/* q is the piecewise quadratic approximation to a, the cubic corresponding
 * to a spiralarc. Returns the offsets of the endpoints of the elements of q
 * from a. These are used to offset points from the spiralarc along crossLines;
 * the points must then be adjusted. The 0th and last numbers returned are 0.
 */
{
  int i;
  double along;
  vector<double> ret;
  for (i=0;i<q.size();i++)
  {
    along=q[i].getstart().getx()-q[0].getstart().getx();
    ret.push_back(q[i].getstart().getz()-a.station(along).getz());
  }
  ret.push_back(0);
  return ret;
}
예제 #11
0
bool operator<(const segment & a, const segment & b) {
	double x = max(min(a.p.x, a.q.x), min(b.p.x, b.q.x));
	return a.get_y(x) < b.get_y(x) - eps;
}
예제 #12
0
파일: geo.cpp 프로젝트: chyyuu/ACM
bool equalSegment(segment a, segment b) {
    return zero(a.angle() - b.angle());
}
예제 #13
0
파일: geo.cpp 프로젝트: chyyuu/ACM
bool cmpSegment(segment a, segment b) {
	if (!zero(a.angle() - b.angle())) return a.angle() < b.angle();
	return (a.b - a.a) / (b.a - a.a) < 0;
}
예제 #14
0
파일: draw.cpp 프로젝트: shsty/Geometry
void drawSegment(segment s) {
    if (s.isDiameter()) {
        glBegin(GL_LINE_STRIP);
        glVertex2d(s.getStart().getX(), s.getStart().getY());
        glVertex2d(s.getEnd().getX(), s.getEnd().getY());
        glEnd();
        return;
    }
    double middle = s.getCenter().arg() + M_PI;
    complex startdef = (s.getStart() - s.getCenter())*unit(-middle);
    complex enddef = (s.getEnd() - s.getCenter())*unit(-middle);
    drawArc(s.getCenter(), s.getRadius(), middle + startdef.arg(), middle + enddef.arg());
}
예제 #15
0
segment transform::operator ()(segment s){
    return s.mobius(c).rotate(th);
}
예제 #16
0
 bool operator>(const segment& cur) {
     double x = max(min(pointOne.x, pointTwo.x), min(cur.pointOne.x, cur.pointTwo.x));
     return (gety(x) - eps) > cur.gety(x);
 }