示例#1
0
void draw_sec(CHpoints *p) {
  dpoint c;
  CHpoints *p1,*p2,*p3;
  double radius;
  
  if ((length2(before(p)->node,p->node) > 
       length2(p->node,next(p)->node)) &&
      (length2(before(p)->node,p->node) > 
       length2(before(p)->node,next(p)->node)))
    p2=next(p);  /* the angle at next(p) is the biggest */
  else if ((length2(p->node,next(p)->node) > 
	    length2(before(p)->node,next(p)->node)) &&
	   (length2(p->node,next(p)->node) > 
	    length2(p->node,before(p)->node)))
    p2=before(p); /* the angle at before(p) is the biggest */
  else
    p2=p; /* the angle at p is the biggest */
  p1=before(p2);
  p3=next(p2);

  if (angle(p1,p2,p3)<0) {
    c.x=(midpoint(p1->node,p3->node)).x;      /* center is midpoint of */
    c.y=(midpoint(p1->node,p3->node)).y;      /* p1 and p3             */
    radius=sqrt((double)length2(p1->node,p3->node))/2.00;    
  }
  else {
    c=centre(p1->node,p2->node,p3->node);
    radius=sqrt((double)radius2(p->node,c));
  }
  printf("The center is (%d,%d)\n",(int)c.x,(int)c.y);
  printf("The radius is %9.2f\n",radius);
}	
inline void find_intersect(int i1, int i2, int i3, int i4, const Atom *atoms, const double *prd, const double *n1, const double *n2, double *x, double *x0=NULL)
{
	int i;
	double *n3, *xm1, *xm2, xc[3], p1, p2, p3, d, **xa;
	n3 = cross(n1, n2); // n3 = [n1 x n2]
	normalize(n3); // n3/|n3|

	xa = new double*[4];
	for (i=0;i<4;i++) xa[i] = new double[3];

	prd_gather(atoms[i1].x, atoms[i2].x, atoms[i3].x, atoms[i4].x, prd, xa);

	xm1 = midpoint(xa[0], xa[1], prd); // xm1 = (x1+x2)/2
	xm2 = midpoint(xa[2], xa[3], prd); // xm2 = (x3+x4)/2

	p1 = dot(n1, xm1, -1.0); // p1 = -(n1.xm1)
	p2 = dot(n2, xm2, -1.0); // p2 = -(n2.xm2)
	p3 = dot(n3, xa[0], -1.0); // p3 = -(n3.x1)

	d = (n1[2]*n2[1]-n1[1]*n2[2])*n3[0]+(n1[0]*n2[2]-n1[2]*n2[0])*n3[1]+(n1[1]*n2[0]-n1[0]*n2[1])*n3[2];
	xc[0] = -(p1*(n2[2]*n3[1]-n2[1]*n3[2])+p2*(n1[1]*n3[2]-n1[2]*n3[1])+p3*(n1[2]*n2[1]-n1[1]*n2[2]))/d;
	xc[1] = -(p1*(n2[0]*n3[2]-n2[2]*n3[0])+p2*(n1[2]*n3[0]-n1[0]*n3[2])+p3*(n1[0]*n2[2]-n1[2]*n2[0]))/d;
	xc[2] = -(p1*(n2[1]*n3[0]-n2[0]*n3[1])+p2*(n1[0]*n3[1]-n1[1]*n3[0])+p3*(n1[1]*n2[0]-n1[0]*n2[1]))/d;
	
	if (x0==NULL) {
		x[0] = xc[0];
		x[1] = xc[1];
		x[2] = xc[2];
	} else {
		prd_coord_add(x, xc, x0, prd);
	}

	for (i=0;i<4;i++) delete [] xa[i];
	delete [] xa;
}
示例#3
0
int main()
{
	FILE *fp,*fp_circle,*fp_points;
	clock_t  start,end;
	int i,j,k;
	int input_size;
	leda::circle C,C_j;
	fp=fopen("input.dat","r");
	fp_points=fopen("points.dat","w");
	fp_circle=fopen("circle.dat","w");
	fscanf(fp,"%d",&input_size);
	for(i=0;i<input_size;i++)
	{
		double x,y;
		fscanf(fp," %lf %lf",&x,&y);
		fprintf(fp_points,"%lf\t%lf\n",x,y);
		leda::point p(x,y);
		points[i]=p;
	}
	start=clock();
	leda::point center;
	center=midpoint( points[0], points[1]);
	leda::circle c_2(center,points[0]);
	C=c_2;
	for(i=2;i<input_size;i++)
	{
		if(C.outside(points[i]))
		{
			center=midpoint( points[0], points[i]);
			leda::circle c_1(center,points[0]);
			C_j=c_1;
			for(j=1;j<i;j++)
			{
				if(C_j.outside(points[j]))
				{
					center=midpoint( points[i], points[j]);
					leda::circle c_ij(center,points[i]);
					for(k=0;k<j;k++)
					{
						if(c_ij.outside(points[k]))
						{
							leda::circle c_ijk(points[i],points[j],points[k]);
							c_ij=c_ijk;
						}
					}
					C_j=c_ij;
				}													
			}
			C=C_j;	
		}
	}
	end=clock();
	printf("%d %6.6lf\n",input_size,((double)(end-start)/CLOCKS_PER_SEC));
	center=C.center();
	fprintf(fp_circle,"%lf %lf %lf",center.xcoord(),center.ycoord(),C.radius());
	//printf("(radius,center)=(%lf,(%lf,%lf))\n",C.radius(),center.xcoord(),center.ycoord());
}
示例#4
0
dpoint centre(Point p1, Point p2, Point p3) {
  Point n1,n2;
  double c1,c2;

  n1=vector(p1,p2);
  n2=vector(p2,p3);
  c1=calculate_c(n1,midpoint(p1,p2));
  c2=calculate_c(n2,midpoint(p2,p3));
  return intersect(n1,n2,c1,c2);
}		   
示例#5
0
double medianof(double *times, int n, int type) {
  switch(type) {
  case 1:
    return midpoint(times,n/4,n);
  case 2:
    return midpoint(times,n/2,n);
  case 3:
    return midpoint(times,(n/2)+(n/4),n);
  }
  return -1;
}
示例#6
0
    void callback(const vicon_bridge::Markers::ConstPtr& markers_msg)
    {   
        std::cout << "\nConstructor Called"  << std::endl;
        std::cout << "Header stamp: "<< markers_msg -> header.stamp <<  "   | Frame Number: " <<
                       markers_msg -> frame_number << std::endl;
    
        //Retrieve geometry_msgs translation for four markers on superchicko    
        forehead            = markers_msg -> markers[0].translation;
        leftcheek           = markers_msg -> markers[1].translation;
        rightcheek          = markers_msg -> markers[2].translation;
        chin                = markers_msg -> markers[3].translation;

        foreheadname        = markers_msg -> markers[0].marker_name;
        leftcheekname       = markers_msg -> markers[1].marker_name;
        rightcheekname      = markers_msg -> markers[2].marker_name;
        chinname            = markers_msg -> markers[3].marker_name;

        //Print a bunch'o'stuff to assert correctness of the above
        std::cout << "\n" << std::endl;
        std::cout << foreheadname   <<  ": "    << forehead     << std::endl;
        std::cout << leftcheekname  <<  ": "    << leftcheek    << std::endl;
        std::cout << rightcheekname <<  ": "    << rightcheek   << std::endl;
        std::cout << chinname       <<  ": "    << chin         << std::endl;

        headmarkers markers = {forehead, leftcheek, rightcheek, chin};
        facemidpts midFacePoints_       = midpoint(markers);
    }
示例#7
0
// draw the geometry marker in the given Displayable's drawing list
void GeometryBond::create_cmd_list() {
  char valbuf[32];

  // get the transformed positions, and draw a line between them
  float pos1[3], pos2[3];

  reset_disp_list();
  if(!transformed_atom_coord(0, pos1))
    return;
  if(!transformed_atom_coord(1, pos2))
    return;

  append(DMATERIALOFF);
  DispCmdColorIndex cmdColor;
  cmdColor.putdata(my_color, cmdList);

  DispCmdLineType cmdLineType;
  DispCmdLineWidth cmdLineWidth;
  cmdLineType.putdata(DASHEDLINE, cmdList);
  cmdLineWidth.putdata(4, cmdList);

  // print value of distance at midpoint
  midpoint(valuePos, pos1, pos2);
  // left-align the value so that it doesn't appear to shift its position
  // when the label text size changes.  Shift it to the right by a constant
  // amount so that it doesn't intersect the line.
  valuePos[0] += 0.05f;
  sprintf(valbuf, "%-7.2f", geomValue);
  display_string(valbuf, cmdList);

  // draw a line into the given Displayable
  display_line(pos1, pos2, cmdList);
  
}
示例#8
0
//���������������������������������������������������������������������������
// A local function to perform the De CastleJau algorithm.
//���������������������������������������������������������������������������
static void bezier_recurse (BezierClosure &func, POINT pt0, POINT pt1, POINT pt2)
{
        if (pt0 == pt1 && pt1 == pt2)
        {
                func (pt0.x, pt0.y);
        }
        // Otherwise, draw curve segs
        else
        {
        // Calculate midpoints
                POINT m1 = midpoint (pt0, pt1);
                POINT m3 = midpoint (pt1, pt2);
                POINT m2 = midpoint (m1, m3);

                bezier_recurse (func, pt0, m1, m2);
                bezier_recurse (func, m2, m3, pt2);
        }
}
示例#9
0
point2_t Map::l_getmidpoint(int l)
{
    point2_t tl(map.verts[map.lines[l]->vertex1]->x,
                map.verts[map.lines[l]->vertex1]->y);
    point2_t br(map.verts[map.lines[l]->vertex2]->x,
                map.verts[map.lines[l]->vertex2]->y);

    return midpoint(tl, br);
}
示例#10
0
文件: kdtree.cpp 项目: wangzs/cgray
std::shared_ptr<cgray::rt::KdNode> cgray::rt::KdNode::build(std::vector<std::shared_ptr<Triangle>> trias, int depth)
{
	std::shared_ptr<KdNode> root(new KdNode());
	root->triangles = trias;
	root->left = std::make_shared<KdNode>();
	root->right = std::make_shared<KdNode>();

	if (trias.size() == 0)
		return root;

	trias[0]->getAABB(root->bbox);

	if (trias.size() == 1) {
		return root;
	}

	AABB tmp;
	for (auto iter : trias) {
		(*iter).getAABB(tmp);
		root->bbox += tmp;
	}
	// kd-tree的深度超多10,不再划分
	if (depth > KDTREE_DEPTH) {
		return root;
	}

	Vector3f midpoint(0.0f,0.0f,0.0f);
	for (auto iter : trias) {
		midpoint = midpoint + (iter->getMidPoint() / trias.size());
	}

	std::vector<std::shared_ptr<Triangle>> left_triangles;
	std::vector<std::shared_ptr<Triangle>> right_triangles;
	AxisType axis = root->bbox.getLongestAxis();
	for (auto iter : trias) {
		switch (axis)
		{
		case cgray::rt::AxisType::XAxis:
			midpoint[0] >= iter->getMidPoint()[0] ? left_triangles.push_back(iter) : right_triangles.push_back(iter);
			break;
		case cgray::rt::AxisType::YAxis:
			midpoint[1] >= iter->getMidPoint()[1] ? left_triangles.push_back(iter) : right_triangles.push_back(iter);
			break;
		case cgray::rt::AxisType::ZAxis:
			midpoint[2] >= iter->getMidPoint()[2] ? left_triangles.push_back(iter) : right_triangles.push_back(iter);
			break;
		default:
			break;
		}
	}

	root->left = build(left_triangles, depth + 1);
	root->right = build(right_triangles, depth + 1);

	return root;
}
示例#11
0
	void Run(){
		gp_Pnt midpoint((line_for_tool->A->m_p.XYZ() + line_for_tool->B->m_p.XYZ()) /2);

		wxGetApp().m_digitizing->digitized_point = DigitizedPoint(midpoint, DigitizeInputType);
		Drawing *pDrawingMode = dynamic_cast<Drawing *>(wxGetApp().input_mode_object);
		if (pDrawingMode != NULL)
		{
			pDrawingMode->AddPoint();
		}
	}
示例#12
0
/*
 * procedure draw_curve(P1, P2, P3, P4, level)
 * 	if (curve is flat)	# or if curve is flat
 * 		draw_line(P1, P4)
 * 	else
 * 		L1 = P1
 * 		L2 = midpoint(P1, P2)
 * 		H  = midpoint(P2, P3)
 * 		R3 = midpoint(P3, P4)
 * 		R4 = P4
 * 		L3 = midpoint(L2, H)
 * 		R2 = midpoint(R3, H)
 * 		L4 = midpoint(L3, R2)
 * 		R1 = L4
 * 		draw_curve(L1, L2, L3, L4, level + 1)
 * 		draw_curve(R1, R2, R3, R4, level + 1)
 * 	end procedure draw_curve
 */
void CubicBezierCurve::GenerateBezierCurveVertices(const glm::vec2& p1,
                                                   const glm::vec2& p2,
                                                   const glm::vec2& p3,
                                                   const glm::vec2& p4,
                                                   unsigned int level,
                                                   size_t* index,
                                                   std::vector<GLfloat>& vertices)
{
  if(level > (max_subdiv_count - 1)) {

    // draw line from p1 to p4
    vertices[(*index) * 3 + 0] = p1.x;
    vertices[(*index) * 3 + 1] = p1.y;
    vertices[(*index + 1) * 3 + 0] = p4.x;
    vertices[(*index + 1) * 3 + 1] = p4.y;

    (*index)++;

    return;
  }

  // calculate all the mid-points of the line segments
  // L1 = p1
  glm::vec2 p12 = midpoint(p1, p2);	// L2
  glm::vec2 p23 = midpoint(p2, p3);	// H
  glm::vec2 p34 = midpoint(p3, p4);	// R3
  // R4 = p4
  glm::vec2 p1223 = midpoint(p12, p23);	// L3
  glm::vec2 p2334 = midpoint(p23, p34);	// R2
  glm::vec2 p = midpoint(p1223, p2334);	// L4
  // R1 = L4

  GenerateBezierCurveVertices(p1, p12, p1223, p, level + 1, index, vertices);
  GenerateBezierCurveVertices(p, p2334, p34, p4, level + 1, index, vertices);
}
示例#13
0
void BicubicPatch::bezier_split_left_right(const ControlPoints *Patch, ControlPoints *Left_Patch, ControlPoints *Right_Patch)
{
    int i, j;
    Vector3d Half;
    Vector3d Temp1[4], Temp2[4];

    for (i = 0; i < 4; i++)
    {
        Temp1[0] = (*Patch)[0][i];

        Temp1[1] = midpoint( (*Patch)[0][i], (*Patch)[1][i] );
        Half     = midpoint( (*Patch)[1][i], (*Patch)[2][i] );
        Temp1[2] = midpoint( Temp1[1],       Half );
        Temp2[2] = midpoint( (*Patch)[2][i], (*Patch)[3][i] );
        Temp2[1] = midpoint( Half,           Temp2[2] );
        Temp1[3] = midpoint( Temp1[2],       Temp2[1] );

        Temp2[0] = Temp1[3];
        Temp2[3] = (*Patch)[3][i];

        for (j = 0; j < 4; j++)
        {
            (*Left_Patch)[j][i]  = Temp1[j];
            (*Right_Patch)[j][i] = Temp2[j];
        }
    }
}
示例#14
0
void BicubicPatch::bezier_split_up_down(const ControlPoints *Patch, ControlPoints *Bottom_Patch, ControlPoints *Top_Patch)
{
    int i, j;
    Vector3d Temp1[4], Temp2[4];
    Vector3d Half;

    for (i = 0; i < 4; i++)
    {
        Temp1[0] = (*Patch)[i][0];

        Temp1[1] = midpoint( (*Patch)[i][0], (*Patch)[i][1] );
        Half     = midpoint( (*Patch)[i][1], (*Patch)[i][2] );
        Temp1[2] = midpoint( Temp1[1],       Half );
        Temp2[2] = midpoint( (*Patch)[i][2], (*Patch)[i][3] );
        Temp2[1] = midpoint( Half,           Temp2[2] );
        Temp1[3] = midpoint( Temp1[2],       Temp2[1] );

        Temp2[0] = Temp1[3];
        Temp2[3] = (*Patch)[i][3];

        for (j = 0; j < 4; j++)
        {
            (*Bottom_Patch)[i][j] = Temp1[j];
            (*Top_Patch)[i][j]    = Temp2[j];
        }
    }
}
示例#15
0
	void parabola(double a, const point2d &begin, const point2d &end){
		glVertex2d(begin[0], begin[1]);

		point2d delta = end-begin;
		if(norm1(delta) <= 1.0/pointsize) return;

		point2d midpoint(2);
		midpoint[0] = begin[0]+delta[0]/2;
		midpoint[1] = a*square(midpoint[0]);

		parabola(a, begin, midpoint);
		parabola(a, midpoint, end);
	}
示例#16
0
int main()
{

    double lim = 544000;
    double olim = 764000;
    double vmin;
    double n = 50;
    double q;


    // printf(" %.14f %f\n", midpoint(func, -lim, lim, -lim, lim, -lim, lim, n));

    clock_t starttime, endtime, starttimeinner, endtimeinner;

    FILE *outfile;
    outfile = fopen("integral-beforev.txt", "w");

    starttime = clock();

    for (vmin = 0; vmin <= 764000; vmin+=5000)
        // for (vmin = 100000; vmin <= 120000; vmin+=5000)
    {
        starttimeinner = clock();

        q =  midpoint(func,-lim,-vmin,-olim,-vmin,-olim,-vmin,n);
        q += midpoint(func, vmin, lim,-olim,-vmin,-olim,-vmin,n);
        q += midpoint(func,-lim,-vmin, vmin, olim,-olim,-vmin,n);
        q += midpoint(func,-lim,-vmin,-olim,-vmin, vmin, olim,n);
        q += midpoint(func, vmin, lim, vmin, olim,-olim,-vmin,n);
        q += midpoint(func,-lim,-vmin, vmin, olim, vmin, olim,n);
        q += midpoint(func, vmin, lim,-olim,-vmin, vmin, olim,n);
        q += midpoint(func, vmin, lim, vmin, olim, vmin, olim,n);

        endtimeinner = clock();

        printf("%f %.14f %f\n",vmin,q,(double)(endtimeinner-starttimeinner) / CLOCKS_PER_SEC);
        fprintf(outfile, "%f %.14f\n",vmin,q);

    }

    endtime = clock();
    printf("\n %f s\n", (double)(endtime-starttime) / CLOCKS_PER_SEC);

    fclose(outfile);

    return 0;

}
示例#17
0
void Square::updateAttributes()
{
	for (int i = 0; i < 4; i++)
	{
		vertices[i] += sgLevel.origin;
	}

	mid = midpoint(vertices);

	float area1 = area3Points(vertices[0], vertices[1], vertices[3]);
	float area2 = area3Points(vertices[2], vertices[1], vertices[3]);

	area = area1 + area2;
}
示例#18
0
bool AGILEFilter::binary_search(double time, uint32_t &index, bool lowerbound, uint32_t iminstart, uint32_t imaxstart) {
	uint32_t imin = 1;
	if(iminstart != 0)
		imin = iminstart;
	
	uint32_t imax;
	
	if(prequery_ok) {
		imax = this->pre_time.size()-1;
	} else {
		imax = numberofpackets-1;
	}
	if(imaxstart != 0)
		imax = imaxstart;
	long count = 0;
	if(time < 0)
		return false;
	while(imax >= imin) {
		count++;
		// calculate the midpoint for roughly equal partition
      	uint32_t imid = midpoint(imin, imax);
      	double timestart;
      	double timeend;
      	readTimeInterval(imid, timestart, timeend);
      	if(timestart <= time && timeend >= time) {
      		//cout << count << endl;
      		// key found at index imid
      		if(lowerbound)
      			index = imid;
      		else {//upperbound
      			if(time == timeend)
      				index = imid;
      			else
      				index = imid-1;
      		}
      		//cout << "I"<< bound <<": [" << setprecision(15) <<  timestart << ", " << timeend << "] -> " << log->getTime() << " -> " << index << endl;
        	return true;
        }
        else if (time > timeend)
        	// change min index to search upper subarray
        	imin = imid + 1;
      	else         
        	// change max index to search lower subarray
        	imax = imid - 1;
	}
	//cout << count << endl;
	return false;
	
}
示例#19
0
/// Returns true if the segment crosses a boundary line of the polygon.
/// It is not enough for the segment to simply intersect the boundary
/// line -- it must cross it such that the segment extends to both inside
/// and outside of the boundary of the polygon.
bool intersects_proper(const Segment_2& segment, const Polygon_2& polygon)
{
  static log4cplus::Logger logger = log4cplus::Logger::getInstance("tiler.intersects_proper");

  Point_2 seg_pts[] = { segment.source(), segment.target() };

  // Get intersection points between segment and polygon
  LOG4CPLUS_TRACE(logger, "Doing a line sweep: " << pp(segment));
  list<Segment_2> segments(polygon.edges_begin(), polygon.edges_end());
  segments.push_back(segment);
  list<Point_2> points;
  get_intersection_points(segments.begin(), segments.end(), back_inserter(points), true, false);

  CGAL::Bounded_side side1 = polygon.bounded_side(seg_pts[0]);
  CGAL::Bounded_side side2 = polygon.bounded_side(seg_pts[1]);

  LOG4CPLUS_TRACE(logger, "Checking with cross checker");
  if (points.size() == 0)
    return false;
  Cross_checker checker;
  checker.add(side1);
  checker.add(side2);
  if (checker.crosses())
    return true;
  if (points.size() == 1)
    return false;

  points.push_back(seg_pts[0]);
  points.push_back(seg_pts[1]);
  points.sort();
  list<Point_2>::iterator it0 = points.begin();
  list<Point_2>::iterator it1 = it0;
  ++it1;
  while (it1 != points.end())
  {
    const Point_2& p0 = *it0;
    const Point_2& p1 = *it1;
    
    // find an intermediate point and test for where it is
    Point_2 midpoint((p0.x()+p1.x())/2.0, (p0.y()+p1.y())/2.0);
    checker.add(polygon.bounded_side(midpoint));
    if (checker.crosses())
      return true;

    ++it0;
    ++it1;
  }
  return false;
}
示例#20
0
void calcBoundingSphere(double *center, double *radius, FaceList *fl){
  double maxDistance = 0.0;
  for( int i = 0; i < fl->vc-1; i++ ){
    for(int j = i + 1; j < fl->vc; j++){
      double *a = fl->vertices[i];
      double *b = fl->vertices[j];
      double distance = vecSquaredDistanceBetween3d(a, b);
      if( distance > maxDistance){
        midpoint(center, a, b);
        *radius = sqrt(distance) * 0.5;
        maxDistance = distance;
      }
    }
  }
}
示例#21
0
/* This will only work with solids composed entirely of
 * triangular faces. It first add a vertex to the middle
 * of each edge, then walks the faces, connecting the
 * dots.
 * I'm abusing the fact that new faces and edges are always
 * added at the head of the list. If that ever changes,
 * this is borked.
 */
static void solid_tesselate(solid *s)
{
    edge *e = s->edges;
    face *f = s->faces;

    while(e) {
        vector v;
        midpoint(e->left->vtx->v, e->right->vtx->v, v);
        vertex_split(e->left, v);
        e = e->next;
    }
    while(f) {
        face_tessel2(f);
        f=f->next;
    }
}
示例#22
0
Foam::searchableBox::searchableBox
(
    const IOobject& io,
    const dictionary& dict
)
    :
    searchableSurface(io),
    treeBoundBox(dict.lookup("min"), dict.lookup("max"))
{
    if (!contains(midpoint()))
    {
        FatalErrorInFunction
                << "Illegal bounding box specification : "
                << static_cast<const treeBoundBox>(*this) << exit(FatalError);
    }

    bounds() = static_cast<boundBox>(*this);
}
示例#23
0
int main()
{
  double r,l,s,ave,var;
  double data[] = {1.54,0.53,0.93,1.60,2.94,0.52,2.11,0.68,1.48,0.37};
  double a[]={2,3},b[]={3,-4},c[2];

  r = 10.0;

  /* 計算 */
  circle(r,&l,&s);
  ave_var(data,&ave,&var);
  midpoint(a,b,c);

  printf("(2) r = %f, l = %f, s = %f\n", r,l,s);
  printf("(3) ave = %f, var = %f\n", ave, var);
  printf("(4) c(%.3f,%.3f)\n",c[0],c[1]);

  return 0;
}
示例#24
0
float ViewVolume::getDistToBboxFromNear(const float min[3], const float max[3]) {
    float center[3];
    float d, radius;

    midpoint(min, max, center);

    // 5 should be near plane
    d = (mFrustum[5][0] * center[0] +
            mFrustum[5][1] * center[1] +
            mFrustum[5][2] * center[2] +
            mFrustum[5][3]);

    radius = distance(max, center);

    if (d <= -radius)
        return 0;

    return d + radius;
}
示例#25
0
point entity::pivot(const std::string& name, bool reverse_facing) const
{
	const frame& f = current_frame();
	if(name == "") {
		return midpoint();
	}

	bool facing_right = face_right();
	if(reverse_facing) {
		facing_right = !facing_right;
	}

	const point pos = f.pivot(name, time_in_frame());
	if(facing_right) {
		return point(x() + pos.x, y() + pos.y);
	} else {
		return point(x() + f.width() - pos.x, y() + pos.y);
	}
}
示例#26
0
Point Line::intercept(Line l) const
{
	ASSERT(could_intercept(l), "Lines must intercept");
	double m = slope(), lm = l.slope();

	bool vert = vertical(), lvert = l.vertical();
	if ((vert && lvert) || (horizontal() && l.horizontal()))
		return midpoint(center(), l.center());
	else if (vert)
		return {x1, (int) l.y_at(x1)};
	else if (lvert)
		return {l.x1, (int) y_at(l.x1)};
	else
	{
		// Derived from y-y1=m(x-x1), y = m(x-x1)+y1, ma(x-xa)+ya=mb(x-xb)+yb...
		double x = (x1*m - l.x1*lm + l.y1 - y1)/(m - lm);
		return {(int) x, (int) y_at(x)};
	}
}
示例#27
0
int main()
{
	point_t *p1, *p2, *mid_p;
	double dist;

	p1 = new_point(1,2);
	p2 = new_point(3,4);

	print_point(p1);
	print_point(p2);

	dist = distance_between(p1, p2);
	printf("Distance between p1 and p2: %f\n", dist);

	mid_p = midpoint(p1, p2);
	print_point(mid_p);

	free_point(&p1);
	free_point(&p2);
	return 0;
}
void calc_midpoints1(Atom *atoms, int n_atoms, double *prd, Point *mid_points)
{
	int i,j,i1,i2,im;
        int n_dna=2;
        int nbp=n_atoms/(2*n_dna);
        double *xm;

        for (i=0;i<n_dna;i++) {
                for (j=0;j<nbp;j++) {
                        i1 = 2*nbp*i+j;
                        i2 = 2*nbp*i+nbp+j;
			im = i*nbp+j;
			
			xm = midpoint(atoms[i1].x, atoms[i2].x, prd); // xm1 = (x1+x2)/2
			
			mid_points[im].x = xm[0];
                        mid_points[im].y = xm[1];
                        mid_points[im].z = xm[2];
		}
	}			
}
示例#29
0
off_t find_dev_size(int fd, int blk_size)
{
    off_t curr = 0, amount = 0;
    void *buf;
 
    if (blk_size == 0)
	return 0;
  
    buf = malloc(blk_size);
  
    for (;;) {
	ssize_t nread;
    
	lseek(fd, curr, SEEK_SET);
	nread = read(fd, buf, blk_size);
	if (nread < blk_size)     {
	    if (nread <= 0) 	{
		if (curr == amount) 	  {
		    free(buf);
		    lseek(fd, 0, SEEK_SET);
		    return amount;
		}
		curr = midpoint(amount, curr, blk_size);
	    }
	    else 	{ // 0 < nread < blk_size 
		free(buf);
		lseek(fd, 0, SEEK_SET);
		return amount + nread;
	    }
	} 
	else     {
	    amount = curr + blk_size;
	    curr = amount * 2;
	}
    }

    free(buf);
    lseek(fd, 0, SEEK_SET);
    return amount;
}
Foam::searchableBox::searchableBox
(
    const IOobject& io,
    const treeBoundBox& bb
)
:
    searchableSurface(io),
    treeBoundBox(bb)
{
    if (!contains(midpoint()))
    {
        FatalErrorIn
        (
            "Foam::searchableBox::searchableBox\n"
            "(\n"
            "    const IOobject& io,\n"
            "    const treeBoundBox& bb\n"
            ")\n"
        )   << "Illegal bounding box specification : "
            << static_cast<const treeBoundBox>(*this) << exit(FatalError);
    }
}