Esempio n. 1
0
/* ********************************************************** *
 * main                                                       */
int main(int argc, const char * argv[]) {
  int i;
  double x,y;
  int sum;
  double numOfIterations;
  struct timeval start, stop;  
  float elapsedTime;

  if(argc > 1)
    sscanf(argv[1],"%lf",&numOfIterations);
  else
    numOfIterations = NUMOFITERATIONS;
 
  int seed = (time(NULL));
  gettimeofday(&start,NULL);  

  for(i=0;i<numOfIterations;i++) {
    x = park_miller_rand(&seed);
    y = park_miller_rand(&seed);
//   printf("(%f,%f)\n",x,y);
    if(isInCircle(x,y)) {
      sum++;
    }
  }
  gettimeofday(&stop,NULL);
  //printf("Sum: %d \n", sum);
  
  printf("Result: %f\n", 4*((double)sum)/((double)numOfIterations));
  elapsedTime = (float)(stop.tv_usec - start.tv_usec) / 1.0e6 + (stop.tv_sec - start.tv_sec); 
  printf("Elapsed Time: %f\n",elapsedTime);
  return 0;
 }
Esempio n. 2
0
	void lop() {
		//前提条件,三点顺序在所有三角形中都是顺时针
		//提供的两个三角形必须相邻,且index必须已经被赋值
		for (int i = 0; i < 3; i++) {
			if (edgeFaces[i] == 0)
				continue;
			if (!isInCircle(edgeFaces[i]->getOtherPoint()))
				continue;
			//需要进行变换
			Face* b = edgeFaces[i]->face;
			int bo = edgeFaces[i]->otherPointIndex; //b中的外点
			Face* a = this;
			int ao = i - 1 >= 0 ? i - 1 : 2; //a中的外点
			int la1 = i; //a共线端点
			int la2 = i + 1 >= 3 ? 0 : i + 1; //a共线端点
			int lb1 = bo + 1 >= 3 ? 0 : bo + 1; //b共线端点
			int lb2 = lb1 + 1 >= 3 ? 0 : lb1 + 1; //b共线端点
			a->setPoint(la2, b->getPoint(bo));
			b->setPoint(lb2, a->getPoint(ao));
			a->edgeFaces[la1]->set(b->edgeFaces[lb2]);
			a->edgeFaces[la1]->updateOtherFaceForMyEdgeFaceInfo(ao, a);
			b->edgeFaces[lb1]->set(a->edgeFaces[la2]);
			b->edgeFaces[lb1]->updateOtherFaceForMyEdgeFaceInfo(bo, b);
			a->edgeFaces[la2]->face = b;
			a->edgeFaces[la2]->otherPointIndex = lb1;
			b->edgeFaces[lb2]->face = a;
			b->edgeFaces[lb2]->otherPointIndex = la1;
			//变换结束后,原三角形的la1不变
			i = 0; //重新处理,直到所有相邻三角形都满足lop
			b->lop();
		}
	}
Esempio n. 3
0
void OrientationWidget::mouseMoveEvent(QMouseEvent *e)
{
    if(_readOnly) {
        e->ignore();
        return;
    }

    if(isInCircle(e->posF())) {
        moveCursor(e->posF());
    }
}
Esempio n. 4
0
void OrientationWidget::mousePressEvent(QMouseEvent *e)
{
	if(_readOnly) {
		e->ignore();
		return;
	}

	if(isInCircle(e->screenPos())) {
		moveCursor(e->screenPos());
	}
}
Esempio n. 5
0
void OrientationWidget::mouseEvent(QMouseEvent *e)
{
	if(_readOnly) {
		e->ignore();
		return;
	}

#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
	const QPointF &relativePos = e->posF();
#else
	const QPointF &relativePos = e->localPos();
#endif

	if(isInCircle(relativePos)) {
		moveCursor(relativePos);
	}
}
Esempio n. 6
0
void Delaunay::legalize(HHandle hh, VHandle vh)
{
    /*           ________ vh_oppo
     *          /\      /
     *         /  \hh  /
     *        /    \  /
     *    vh /___>__\/
     */

    VHandle vh_oppo = mesh.opposite_he_opposite_vh(hh);
    if (isInCircle(hh, vh, vh_oppo))
    {
        // save vertex handles mapped to the face
        VHandleVec vhs_buffer;
        saveVhs(hh, vhs_buffer);

        // flip edge
        EHandle eh = mesh.edge_handle(hh);
        if (mesh.is_flip_ok(eh))
        {
            mesh.flip(eh);
        }

        // rebucket
        rebucket(eh, vhs_buffer);

        // recursive
        HHandle heh1, heh2;
        heh1 = mesh.halfedge_handle(eh, 0);
        heh2 = mesh.halfedge_handle(eh, 1);
        if (mesh.to_vertex_handle(heh1) == vh)
        {
            heh1 = mesh.prev_halfedge_handle(heh1);
            heh2 = mesh.next_halfedge_handle(heh2);
        }
        else{
            heh1 = mesh.next_halfedge_handle(heh1);
            heh2 = mesh.prev_halfedge_handle(heh2);
        }

        legalize(heh1, vh);
        legalize(heh2, vh);
    }
}
Esempio n. 7
0
	bool isInCircle(float* ps) {
		return isInCircle(ps[0], ps[1]);
	}