Ejemplo n.º 1
0
//
// Calculate the distance between two points.
//
float edge::calc_length( const point& a, const point& b )
{
	int dx = a.get_x() - b.get_x();
	int dy = a.get_y() - b.get_y();
	return static_cast<float>(
			std::sqrt( static_cast<double>( dx * dx + dy * dy ) ) );
}
Ejemplo n.º 2
0
int main() {
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int i,j,k;
	int n,r;
	int CA=0;
	while ( ~scanf ( "%d%d",&n,&r ) ) {
		vector<point>P;
		for ( i=0; i<n; i++ ) {
			point foo;
			foo.in();
			P.PB ( foo );
		}
//		P=ConvexHull(P);
		if ( !P.empty() ) P.PB ( P[0] );
		for(nl=0,i=1;i<P.SZ;i++){
			point s=P[i],e=P[i-1];
			point d=(e-s).rotate().normal()*r;
			L[nl++]=line(s+d,e+d);
		}
		nr=HPI(L,nl,R);
		P.clear();
		for(i=0;i<nr;i++)P.PB(R[i]);
		P=ConvexHull(P);
		ConvecDiameter(P);
		if(sign(au.x-av.x)>0)swap(au,av);
		au.out(" ");
		av.out("\n");
	}
	return 0;
}
Ejemplo n.º 3
0
bool map::contains(point<2> p) const
{
    return p.x() >= min_x
           && p.x() <= max_x
           && p.y() >= min_y
           && p.y() <= max_y;
}
bool cmp(point left, point right) {
    point a = left - points[0], b = right - left;
    if(a.x * b.y > b.x * a.y) return 1;
    if(a.x * b.y == b.x * a.y)
        return left.len() < right.len();
    return 0;
}
Ejemplo n.º 5
0
bool tour(int board[8][8],point posNew,int step){
    int x = posNew.getx();
    int y = posNew.gety();
    
    if (step==64) {
        return true;
    }
    bool result;
    for (int k=0; k<8; k++) {
        point p = move(x,y,k+1);
        int x1,y1;
        x1 = p.getx();
        y1 = p.gety();
        if (x1<8 && x1>=0 && y1<8 && y1>=0 && board[x1][y1]==-1) {
            board[x1][y1] = step;
            result = tour(board, p, step+1);
            if (result) {
                return true;
            }else{
                board[x1][y1]=-1;
            }
        }
    }
    return false;
}
Ejemplo n.º 6
0
/*cubeCol* joueur::getCube()
{
return &collision;
}*/
void joueur::miseAjour(point newPosition, uint16_t newAngleX, uint16_t newAngleY, uint8_t newGaz, uint8_t newAxeX, uint8_t newAxeY, float newVitesse)
{
if(newPosition.getX() > -251 && newPosition.getX() < 251 && newPosition.getY() > -251 && newPosition.getY() < 251 && newPosition.getZ() > -251 && newPosition.getZ() < 251)
{
position = newPosition;
}
if(newAngleX < 361)
{
angleX = newAngleX;
}
if(newAngleY < 361)
{
angleY = newAngleY;
}
if(newGaz == 0 || newGaz == 1)
{
gaz = newGaz;
}
if(newAxeX == 0 || newAxeX == 1 || newAxeX == 2 )
{
axeX = newAxeX;
}
if(newAxeY == 0 || newAxeY == 1 || newAxeY == 2 )
{
axeY = newAxeY;
}
if(newVitesse >= 0 && newVitesse <= vitesseMax)
{
vitesse = newVitesse;
}
}
Ejemplo n.º 7
0
double calc(const point &a, const point &b) {
    point p[2];
    int num = 0;
    int ina = dcmp(a.norm()- r) < 0;
    int inb = dcmp(b.norm() - r) < 0;
    if (ina) {
        if (inb) {
            return fabs(det(a, b)) / 2;
        } else {
            circle_inter_line(a, b, point(0, 0), r, p, num);
            return sector_area(b, p[0]) + fabs(det(a, p[0])) / 2;
        }
    } else {
        if (inb) {
            circle_inter_line(a, b, point(0, 0), r, p, num);
            return sector_area(p[0], a) + fabs(det(p[0], b)) / 2;
        } else {
            circle_inter_line(a, b, point(0, 0), r, p, num);
            if (num == 2) {
                return sector_area(a, p[0]) + sector_area(p[1], b) + fabs(det(p[0], p[1])) / 2;
            } else {
                return sector_area(a, b);
            }
        }
    }
}
Ejemplo n.º 8
0
point minimization::calcGoMin(point p) {
    point g(p.size());
    for (int i = 0; i < (int)p.size()/* && Fcnt < 1e6*/; i++) {
        if (fabs(p[i] - FL->l0[i]) < eps) {
            point p1(p);
            p1[i] += eps1;
            g[i] = -(calcF(p1) - calcF(p)) / eps1;
            if (g[i] < 0) {
                g[i] = 0;       
            }
        } else
        if (fabs(p[i] - FL->r0[i]) < eps) {
            point p1(p);
            p1[i] -= eps1;
            g[i] = -(calcF(p) - calcF(p1)) / eps1;
            if (g[i] > 0) {
                g[i] = 0;       
            }
        } else {
            point p1(p);
            p1[i] += eps1;
            g[i] = -(calcF(p1) - calcF(p)) / eps1;            
        }
    }
    return g;
}
Ejemplo n.º 9
0
void twoLinkArm::ikinAbs(point x, point &q)
{
	x=x-params.x0;
	double S=(std::pow(params.l1+params.l2,2)-(std::pow(x.X(),2)+std::pow(x.Y(),2)))/(std::pow(x.X(),2)+std::pow(x.Y(),2)-std::pow(params.l1-params.l2,2));
	q[1]=-2.0*std::atan(std::sqrt(std::abs(S))); //Negative sign indicates elbow right.
	q[0]=std::atan2(x.Y(),x.X())-std::atan2(params.l2*std::sin(q[1]),params.l1+params.l2*std::cos(q[1]));
}
Ejemplo n.º 10
0
void line::set_point(point p1, point p2) {
	this->p1.set_x(p1.get_x());
	this->p1.set_y(p1.get_y());
	
	this->p2.set_x(p2.get_x());
	this->p2.set_y(p2.get_y());
}
Ejemplo n.º 11
0
Ship::Ship(point originPoint, direction o, int l) 
{
	origin = originPoint;
	orientation = o;
	length = l;	
	lencopy = length;
	hits = 0;

	points.add(originPoint);
	if (orientation == HORIZONTAL)
	{
		while((lencopy - 1) > 0)
		{
			points.add((originPoint.getX() + 1), originPoint.getY)
			lencopy -= 1;
		}
	}
	else
	{
		while((lencopy - 1) > 0)
		{
			points.add(originPoint.getX(), (originPoint.getY()+1))
			lencopy -= 1;
		}
	}
}
Ejemplo n.º 12
0
// Processes mouse movements for skeleton manipulation
void trackMouse(int x, int y)
{
    if(mode == 2 && selected >= joints.size())
    {
        point *s = &xydpoints.at(selected - joints.size());
        if(RM)
        {
            double shift = (clickpos.gety() - y)/50.;
            *s = point(s->getx(), s->gety(), clickpos.getz()+shift);
        }
        else
        {
            *s = point(x, y, s->getz());
        }
        setTargets();
    }
    else if(mode == 1)
    {
        if(LM && selected >= 0 && selected <= joints.size())
        {
            double shift = clickpos.gety() - y;
            joints.at(selected)->settheta(clickpos.getz() + shift);
        }
    }
}
Ejemplo n.º 13
0
scalar arakawaKonorStripesTracerField::tracerAt
(
        const point& p,
        const Time& t
) const
{
    scalar x = p.x() - xOffset;
    if (mag(x) <= wavelength / 2)
    {
        if (p.z() >= z1Start - 1 && p.z() <= z1End - 1)
        {
            return -rho0*Foam::sin(2*M_PI*x/wavelength);
        }
        else if (p.z() >= z2Start - 1 && p.z() <= z2End - 1)
        {
            return rho0*Foam::sin(2*M_PI*x/wavelength);
        }
        else
        {
            return 0;
        }
    }
    else
    {
        return 0;
    }
}
Ejemplo n.º 14
0
std::tuple<float, point> line::distance(const point &p) const {
    float A = p.x() - origin().x();
    float B = p.y() - origin().y();
    float C = target().x() - origin().x();
    float D = target().y() - origin().y();

    float dot = A * C + B * D;
    float len_sq = C * C + D * D;
    float param = dot / len_sq;

    float xx, yy;

    if (param < 0 || (origin().x() == target().x() && origin().y() == origin().x())) {
        xx = origin().x();
        yy = origin().y();
    }
    else if (param > 1) {
        xx = target().x();
        yy = target().y();
    }
    else {
        xx = origin().x() + param * C;
        yy = origin().y() + param * D;
    }

    float dx = p.x() - xx;
    float dy = p.y() - yy;
    return std::make_tuple(sqrt(dx * dx + dy * dy), point(xx, yy));
}
Ejemplo n.º 15
0
bool smaller_angle(const point<2>& first_point, const point<2>& p1, const point<2>& p2) 
{
	if (collinear(first_point, p1, p2))
		return (first_point.square_distance(p1) > first_point.square_distance(p2));

	return (!ccw(first_point, p1, p2));
}
Ejemplo n.º 16
0
Archivo: sol.cpp Proyecto: DrhF/ACM
hash vp(const point& v1, const point& v2, const point& c){
	hash ret;
	ret.a = v1.dist(c);
	ret.b = v2.dist(c);
	ret.c = v1.dist(v2);
	return ret;
}
 inline void distanceTransform::sedMask::query_distance(point &shortest, 
                                                        point &other)const{
   if((other.x >= 0) &&
      ((shortest.x < 0) || (shortest.absSqr() > other.absSqr()))) {
     shortest = other;
   }
 }
Ejemplo n.º 18
0
Archivo: main.cpp Proyecto: he3210/wd
		void printline() //输出提示信息
		{
			p1.printpoint(); //调用对象成员的公共接口
			cout << "  ------->  ";
			p2.printpoint(); //调用对象成员的公共接口
			cout << endl;
		}
bool Foam::octreeDataBoundBox::findTightest
(
    const label index,
    const point& sample,
    treeBoundBox& tightest
) const
{
    // Get furthest away vertex
    point myNear, myFar;
    allBb_[index].calcExtremities(sample, myNear, myFar);

    const point dist = myFar - sample;
    scalar myFarDist = mag(dist);

    point tightestNear, tightestFar;
    tightest.calcExtremities(sample, tightestNear, tightestFar);

    scalar tightestFarDist = mag(tightestFar - sample);

    if (tightestFarDist < myFarDist)
    {
        // Keep current tightest.
        return false;
    }
    else
    {
        // Construct bb around sample and myFar
        const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z()));

        tightest.min() = sample - dist2;
        tightest.max() = sample + dist2;

        return true;
    }
}
Ejemplo n.º 20
0
bool checkNeighbors(point currentPoint, grid * theGrid) {
    int row = currentPoint.getRow();
    int column = currentPoint.getColumn();
    int currentValue = theGrid->getValue(row,column);
    int status;
    
    if (row != 0) { // Neighbor to the north (Canada)
        status = checkPosition(row-1, column, currentValue, theGrid);
        if (status == 99) return true;
        else if (status == 1) pointQueue.enqueue(point(row-1,column));
    }
    if (row < theGrid->getSize() -1) { // Neighbor to the south (Mexico)
        status = checkPosition(row+1, column, currentValue, theGrid);
        if (status == 99) return true;
        else if (status == 1) pointQueue.enqueue(point(row+1,column));
    }
    if (column != 0) { // Neighbor to the west (Pacific)
        status = checkPosition(row, column-1, currentValue, theGrid);
        if (status == 99) return true;
        else if (status == 1) pointQueue.enqueue(point(row,column-1));
    }
    if (column < theGrid->getSize() -1) { // Neighbor to the east (Atlantic)
        status = checkPosition(row, column+1, currentValue, theGrid);
        if (status == 99) return true;
        else if (status == 1) pointQueue.enqueue(point(row,column+1));
    }
    return false;
}
Ejemplo n.º 21
0
/**
 * @brief scChunkManager::boundingRect
 * @param Center
 * @param width
 * @return imaginary rectangle containing the set of chunks that matter
 *
 * Creates a rectangle whose attributes describe which chunks need to be
 * paid attention to (i.e. top left is the top left most chunk, bottom right
 * is the bottom right most chunk)
 */
QRect scChunkManager::boundingRect(point Center, measure_type width) const {
    coord_type xTileMin = std::floor((Center.x() - width) / chunkWidth);
    coord_type xTileMax = std::ceil((Center.x() + width) / chunkWidth);
    coord_type yTileMin = std::floor((Center.y() - width) / chunkWidth);
    coord_type yTileMax = std::ceil((Center.y() + width) / chunkWidth);

    return QRect(QPoint(xTileMin, yTileMax), QPoint(xTileMax, yTileMin));
}
Ejemplo n.º 22
0
void drawPoint(point p, double size) {
    glBegin(GL_POLYGON);
    glVertex2d(p.getX()-size, p.getY()-size);
    glVertex2d(p.getX()-size, p.getY()+size);
    glVertex2d(p.getX()+size, p.getY()+size);
    glVertex2d(p.getX()+size, p.getY()-size);
    glEnd();
}
Ejemplo n.º 23
0
// compute intersection of line passing through a and b
// with line passing through c and d, assuming that unique
// intersection exists; for segment intersection, check if
// segments intersect first
// **use LinesParallel and LinesColliner to detect wether they intersect
point ComputeLineIntersection(point a, point b, point c, point d)
{
    b = b - a ;
    d = c - d ;
    c = c - a ;
    assert( b.dot(b) > EPS && d.dot(d) > EPS);
    return a + b* c.cross(d) / b.cross(d) ;
}
Ejemplo n.º 24
0
	// same with vtmp
	void addDampingTMP()
	{
		XMVECTOR dampPoint1 = XMVectorScale(point1->vtmp, -g_fDamping);
		XMVECTOR dampPoint2 = XMVectorScale(point2->vtmp, -g_fDamping);

		point1->addIntF(dampPoint1);
		point2->addIntF(dampPoint2);
	}
Ejemplo n.º 25
0
	void addDamping()
	{
		XMVECTOR dampPoint1 = XMVectorScale(point1->curr_v, -g_fDamping);
		XMVECTOR dampPoint2 = XMVectorScale(point2->curr_v, -g_fDamping);

		point1->addIntF(dampPoint1);
		point2->addIntF(dampPoint2);
	}
Ejemplo n.º 26
0
    double angle(point p) {
#ifdef DBGANGLE
        printf("(%d, %d).(%d, %d) = ", x, y, p.x, p.y);
        double dotmod = (*this ^ p) / mod() / p.mod();
        printf(" %.3lf --> %.3lf\n", dotmod, acos(dotmod));
#endif
        return acos((*this ^ p) / mod() / p.mod());
    }
Ejemplo n.º 27
0
QRect scChunkManager::tileIndexToBounds(point loc, measure_type chunkWidth) {
    coord_type left = loc.x() * chunkWidth;
    coord_type up = (loc.y()) * chunkWidth;

    //+1 is b/c QRect assums boundries don't overlap when they do. Causes issues w/
    //deposit placement.
    return QRect(left, up, chunkWidth + 1, chunkWidth + 1);
}
		void drawFace(point p1,point p2,point p3)
		{
			glColor3f(1,0,0);
			p1.drawPoint();
			glColor3f(0,1,0);
	        	p2.drawPoint();
			glColor3f(0,0,1);
	        	p3.drawPoint();
		}
Ejemplo n.º 29
0
		/// \brief Constructs a rect on position (top_left.x, top_left.y), with
		///        size bottom_right.x - top_left.x + 1 as width and
		///        bottom_right.y - top_left.x + 1 as height
		constexpr rect(
			point< position_type > const& top_left,
			point< position_type > const& bottom_right
		):
			top_left_(top_left),
			size_(
				bottom_right.x() - top_left.x() + 1,
				bottom_right.y() - top_left.y() + 1
			){}
Foam::point Foam::scaleSearchableSurface::inverseTransform(const point &p) const
{
    return point
        (
            p.x()/scale_.x(),
            p.y()/scale_.y(),
            p.z()/scale_.z()
        );
}