bool operator<(const Point2D & p1, const Point2D & p2) { if(p1.getY() < p2.getY()) return true; if(p2.getY() < p1.getY()) return false; return p1.getX() < p2.getX(); }
Line2D::Line2D(Point2D pointA, Point2D pointB) { Point2D b = pointA; Point2D a = pointB; y_intercept = -a.getX()*((b.getY() - a.getY()) / (b.getX() - a.getX())) + a.getY(); slope = (b.getY() - a.getY()) / (b.getX() - a.getX()); }
void GhostCell::draw(Point2D cell) { if (cell.getX() < 0 || cell.getY() < 0) return; appearance->apply(); glPushMatrix(); glTranslatef(-10, 0.251, -10); glRotatef(-90, 1, 0, 0); glTranslatef(cell.getY() * 2.5, cell.getX() * -2.5, 0); glBegin(GL_QUADS); glTexCoord2d(0, 0); glVertex3d(0, -size, 0); glTexCoord2d(1, 0); glVertex3d(size, -size, 0); glTexCoord2d(1, 1); glVertex3d(size, 0, 0); glTexCoord2d(0, 1); glVertex3d(0, 0, 0); glEnd(); glPopMatrix(); }
bool contains(Point2D point) { double ri = this->slope*point.getX() + this->y_intercept; if (point.getY() < ri+0.00001 && point.getY() > ri - 0.00001) return true; return false; }
Math::Point Projector::getZOfPoint(Point2D point) { GLfloat pointZ; glReadPixels(point.getX(), currentDimensions.getY() - point.getY(), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pointZ); return Math::Point(point.getX(), point.getY(), pointZ); }
// Method for testing collision/intersection with a 2D point bool Rectangle::checkCollision(Point2D& p) { if ((bottomLeft.getX() <= p.getX() && bottomRight.getX() >= p.getX()) && (bottomLeft.getY() <= p.getY() && topLeft.getY() >= p.getY())) { return true; } else { return false; } }
double DoubleImage::getBestDivide(const Point2D& first, const Point2D& second, Channel channel) const { if (dType == T_MIDDLE) { return .5; } bool high = (dType == T_HIGHENTROPY); if (!this->hasEdges()) { throw logic_error("Edges not generated!"); } double initialXDiff = second.getX() - first.getX(); double initialYDiff = second.getY() - first.getY(); Point2D point1(first.getX() + MIN_SUBDIVIDE_RATIO*(initialXDiff), first.getY() + MIN_SUBDIVIDE_RATIO*(initialYDiff)); Point2D point2(first.getX() + (1-MIN_SUBDIVIDE_RATIO)*(initialXDiff), first.getY() + (1-MIN_SUBDIVIDE_RATIO)*(initialYDiff)); vector<Point2D> points = getPointsOnLine(point1, point2); double bestVal = -1; double bestR = -1; for (vector<Point2D>::const_iterator it = points.begin(); it != points.end(); it++) { const double val = edgeAt(*it, channel); if ( ((high)?(bestVal < val):(bestVal > val)) || bestR < 0) { const double rx = (it->getX() - first.getX())/initialXDiff; const double ry = (it->getY() - first.getY())/initialYDiff; double r; if (doublesEqual(initialXDiff, 0)) { r = ry; } else if (doublesEqual(initialYDiff, 0)) { r = rx; } else { r = (rx+ry)/2.; } if (r > MIN_SUBDIVIDE_RATIO && r < 1-MIN_SUBDIVIDE_RATIO) { bestR = r; bestVal = val; } } } if (bestR < 0) { return 1/2.0; } else { return bestR; } }
IntensityImageStudent ImageUtils::subimage(const IntensityImage * image, const Point2D<double> left_top, const Point2D<double> right_down) { int left_x = 0; int right_x = image->getWidth(); int left_y = 0; int right_y = image->getHeight(); if (left_top.getX() > right_down.getX()){ left_x = right_down.getX(); right_x = left_top.getX(); } else if (left_top.getX() < right_down.getX()){ left_x = left_top.getX(); right_x = right_down.getX(); } if (left_top.getY() > right_down.getY()){ left_y = right_down.getY(); right_y = left_top.getY(); } else if (left_top.getY() < right_down.getY()){ left_y = left_top.getY(); right_y = right_down.getY(); } IntensityImageStudent result(right_x - left_x, right_y - left_y); for (int y = left_y; y < right_y; y++) { for (int x = left_x; x < right_x; x++) { result.setPixel(x - left_x, y - left_y, image->getPixel(x, y)); } } return result; }
Point2D Point2D::operator*(Point2D &p) { Point2D producto; producto.x=x*p.getX(); producto.y=y*p.getY(); return producto; }
//Draw a line from a given position, with given length and angle Point2D<double> StudentLocalization::drawLine(double angle, int len, Point2D<double> point) const{ angle = angle * M_PI / HALF_CIRCLE; // Convert degrees to radians Point2D<double> point1; point1.setX(point.getX() + len * cos(angle)); point1.setY(point.getY() + len * sin(angle)); return point1; }
void MotionExecutor::setPosition(MotionCommand* _motionCommand){ SetPosition* command=(SetPosition*)_motionCommand; debug(command->getSource()+" Received: Set position"); Point2D previousPosition =driver.getPosition(); currentMotionInstruction.Set(_motionCommand, lastState); std::stringstream ss; debug(ss.str()); pfLock.lock(); driver.setPositionAndOrientation(command->getPoint(),command->getOrientation()); for(int i=0;i<2;++i){ if (detectedEnemies[i].Id!=-1){ pathFinder->removeObstacle(detectedEnemies[i].Id); detectedEnemies[i].Position.setX(detectedEnemies[i].Position.getX()+previousPosition.getX()); detectedEnemies[i].Position.setY(detectedEnemies[i].Position.getY()+previousPosition.getY()); detectedEnemies[i].CentralPosition.setX(detectedEnemies[i].CentralPosition.getX()+previousPosition.getX()); detectedEnemies[i].CentralPosition.setY(detectedEnemies[i].CentralPosition.getY()+previousPosition.getY()); // detectedEnemies[i].Id=dodajSestougao(detectedEnemies[i].Position.getX(), // detectedEnemies[i].Position.getY(), // triangleSide,driver.getOrientation()); detectedEnemies[i].Id=dodajCustomOblik(detectedEnemies[i].Position.getX(), detectedEnemies[i].Position.getY(), driver.getOrientation()); } } pfLock.unlock(); }
Point2D Point2D::operator+(Point2D &p) { Point2D r; r.x = x + p.getX(); r.y = y + p.getY(); return r; }
Point2D Point2D::operator-(Point2D &p) { Point2D r; r.x = x - p.getX(); r.y = y - p.getY(); return r; }
Math::Point Projector::screenToGL(Point2D point) { Math::Point offset; double orthoDim = Math::minimum( currentDimensions.getX(), currentDimensions.getY()); // offset is the value that translates by half the screen in the X and Y // dimensions. Since due to resizeGL() above the viewport is set // differently when width > height as when height > width, this complex // code is necessary. // // offset is used to change the origin (0, 0) from the upper-left corner // to the centre of the screen as is expected in OpenGL unit coordinates. if(currentDimensions.getX() > currentDimensions.getY() || true) { offset = Math::Point( double(currentDimensions.getX()) / currentDimensions.getY(), -1.0); } else { offset = Math::Point(1.0, -double(currentDimensions.getY()) / currentDimensions.getX()); } Math::Point unitPos( point.getX() / orthoDim, -point.getY() / orthoDim); return 2.0 * unitPos - offset; }
bool Rectangle::pointInside(const Point2D& point) const { double px = point.getX(); double py = point.getY(); return (((px >= this->x || doublesEqual(px, this->x)) && (px <= this->x+this->w || doublesEqual(px, this->x+this->w))) && ((py >= this->y || doublesEqual(py, this->y)) && (px <= this->y+this->h || doublesEqual(py, this->y+this->h)))); }
/*! * \note Currently, only the Manhatten distance is implemented. */ int Point2D::dist(Point2D a, unsigned int type) { switch(type) { case Point2D::MANHATTEN : return abs(x-a.getX()) + abs(y-a.getY()); case Point2D::EUCLID : default: return 0; } }
Agent::Agent( Point2D& p ) { this->_location = Point2D( p ); this->setPosition( p.getX(), p.getY(), 0 ); this->_destination = Point2D(); this->_heading = Vector2D(); this->_speed = 0; this->_radius = 0; }
int CrossingNumberAlgorithm::pointInPolygon(const Point2D & p, const vector<Point2D> & polygon){ int n = polygon.size(); int crossing = 0; for(int i=0; i<n; i++){ int next = (i + 1) % n; // Verfica se a aresta eh uma linha horizontal if(fabs(polygon[i].getY() - polygon[next].getY()) < EPS){ double maxX = max(polygon[i].getX(), polygon[next].getX()); double minX = min(polygon[i].getX(), polygon[next].getX()); // Verifica se o ponto p pertence a aresta, i.e. p.y == poly[i].y && minX <= p.x <= maxX if(fabs(polygon[i].getY() - p.getY()) < EPS && (p.getX() >= minX && p.getX() <= maxX) ){ return 0; // Ponto esta na fronteira } continue; } // Determinar intersecção // s = p + s(1,0) - linha infinita horizontal partindo do ponto p // t = poly[i] + t (poly[next] - poly[i]) - segmento da aresta do poligono double deltaX = polygon[next].getX() - polygon[i].getX(); double deltaY = polygon[next].getY() - polygon[i].getY(); // t = (p.y - poly[i].y) / deltaY double t = (p.getY() - polygon[i].getY()) / deltaY; // checando se 0 <= t <= 1 para determinar se os segmentos se cruzam if(t < 0.0 || t > 1.0) continue; // s = poly[i].x - p.x + t * deltaX double s = polygon[i].getX() - p.getX() + t * deltaX; // Verifica se p está na fronteira, i.e. s == 0 if(fabs(s) < EPS) return 0; // verifica se interseção ocorre e incrementa crossing se a mesma não ocorreu no ponto de mínimo double minY = min(polygon[i].getY(), polygon[next].getY()); if(s > 0.0 && p.getY() > minY) crossing++; } // se N é ímpar, retorne que p0 é interior a P, senão retorne que p0 é exterior a P. return (crossing % 2) ? -1: 1; }
vector<QPoint> BlurredSegment::getListeQPoint(){ vector<QPoint> vectResult; vector<Point2D>::iterator iter = vectorPixel.begin(); while( iter !=vectorPixel.end()){ Point2D p = *iter; vectResult.push_back(QPoint(p.getX(),p.getY())); iter++; } return vectResult; }
vector<Point2D> DoubleImage::getPointsOnLine(const Point2D& point1, const Point2D& point2) const { vector<Point2D> result; double xDiff = point2.getX() - point1.getX(); double yDiff = point2.getY() - point1.getY(); if (abs(xDiff) > abs(yDiff)) { double xStep = getXInc(); if (xDiff < 0) { xStep *= -1; } double xMin = (point1.getX() < point2.getX())?floorXToGrid(point1.getX()):ceilXToGrid(point1.getX()); double xMax = (point2.getX() < point1.getX())?floorXToGrid(point2.getX()):ceilXToGrid(point2.getX()); for (double x = xMin; (xDiff < 0)?(x > xMax):(x < xMax); x += xStep) { double r = (x - point1.getX())/xDiff; double y = snapYToGrid( r * yDiff + point1.getY()); result.push_back(Point2D(x,y)); } } else { double yStep = getYInc(); if (yDiff < 0) { yStep *= -1; } double yMin = (point1.getY() < point2.getY())?floorYToGrid(point1.getY()):ceilYToGrid(point1.getY()); double yMax = (point2.getY() < point1.getY())?floorYToGrid(point2.getY()):ceilYToGrid(point2.getY()); for (double y = yMin; (yDiff < 0)?(y > yMax):(y < yMax); y += yStep) { double r = (y - point1.getY())/yDiff; double x = snapXToGrid( r * xDiff + point1.getX()); result.push_back(Point2D(x,y)); } } return result; }
// Method for constructing rectangles using two points Rectangle::Rectangle(Point2D& pOne, Point2D& pTwo) { width = abs(pOne.getX() - pTwo.getX()); height = abs(pOne.getY() - pTwo.getY()); // Find the coordinates of the rectangle if (pOne.getX() <= pTwo.getX()) { if (pOne.getY() <= pTwo.getY()) { bottomLeft = pOne; topRight = pTwo; bottomRight = Point2D(topRight.getX(), bottomLeft.getY()); topLeft = Point2D(bottomLeft.getX(), topRight.getY()); } else { topLeft = pOne; bottomRight = pTwo; bottomLeft = Point2D(topLeft.getX(), bottomRight.getY()); topRight = Point2D(bottomRight.getX(), topLeft.getY()); } } else { if (pOne.getY() <= pTwo.getY()) { bottomRight = pOne; topLeft = pTwo; bottomLeft = Point2D(topLeft.getX(), bottomRight.getY()); topRight = Point2D(bottomRight.getX(), topLeft.getY()); } else { topRight = pOne; bottomLeft = pTwo; bottomRight = Point2D(topRight.getX(), bottomLeft.getY()); topLeft = Point2D(bottomLeft.getX(), topRight.getY()); } } }
bool MotionExecutor::isInField(Point2D& enemyPosition){ static int xMinC=minX+margin; static int xMaxC=maxX-margin; static int yMinC=minY+margin; static int yMaxC=maxY-margin; static int xStairsMin=0-stairsWidth; static int xStairsMax=0+stairsWidth; static int yStairsMin=2000-stairsHeight; static int yStairsMax=2000; //TODO: proveri da nije slucajno na stepenklicama if (((enemyPosition.getX()>xStairsMin) && (enemyPosition.getX()<xStairsMax)) && ((enemyPosition.getY()>yStairsMin) && (enemyPosition.getY()<yStairsMax))){ debug("Enemy is on stairs"); return false; } if ((enemyPosition.getY()<yMinC) || (enemyPosition.getY()>yMaxC)){ return false; } if ((enemyPosition.getX()<xMinC) || (enemyPosition.getX()>xMaxC)){ return false; } if ((enemyPosition.getY()<yMinC) || (enemyPosition.getY()>yMaxC)){ return false; } return true; }
void ObjRenderer::render(vector<float> vertices, Colour colour, float angle, GLenum mode, float scale_offset) { // Change renderer glUseProgram(_program); checkGlError("glUseProgram"); /* Matrix transformations -------- */ // Model matrix glm::mat4 model_mat; model_mat = glm::rotate(model_mat, static_cast<float>(angle*PI/180), glm::vec3(0.0f, 0.0f, 1.0f)); // View matrix Point2D ctr = Point2D(Game::getScreenWidth()/2, Game::getScreenHeight()/2); Point2D anchor_pt = _cam->getPos(); glm::mat4 view_mat; view_mat = glm::translate(view_mat, glm::vec3(ctr.getX(), ctr.getY(), 0)); view_mat = glm::rotate(view_mat, static_cast<float>(_cam->getRotAngle()*PI/180), glm::vec3(0.0f, 0.0f, 1.0f)); view_mat = glm::scale(view_mat, glm::vec3(_cam->getScale() + scale_offset, _cam->getScale() + scale_offset, _cam->getScale() + scale_offset)); view_mat = glm::translate(view_mat, glm::vec3(-anchor_pt.getX(), -anchor_pt.getY(), 0)); // MVP glm::mat4 MVP_mat = _proj_mat * view_mat * model_mat; /* ------------------------------- */ // Pass MVP to shader glUniformMatrix4fv(_mMVP_handle, 1, GL_FALSE, glm::value_ptr(MVP_mat)); checkGlError("glUniformMatrix4fv, mMVP"); float col[4] { colour.r, colour.g, colour.b, colour.a }; glUniform4fv(_vColor_handle, 1, col); checkGlError("glUniformMatrix4fv, vColour"); glVertexAttribPointer(_vPos_handle, 2, GL_FLOAT, GL_FALSE, 0, &vertices[0]); checkGlError("glVertexAttrib"); glEnableVertexAttribArray(_vPos_handle); checkGlError("glEnableVertexAttribArray"); // Pass attributes to shader glDrawArrays(mode, 0, vertices.size()/2); checkGlError("glDrawArrays"); }
CohenSutherlandStep(Drawer *drawer, vector<Point2D> *points, vector<Point2D> *auxPoints, double xMin, double yMin, double xMax, double yMax){ this->drawer = drawer; this->points = points; this->auxPoints = auxPoints; this->xMin = xMin; this->yMin = yMin; this->xMax = xMax; this->yMax = yMax; Point2D a = points->at(0); Point2D b = points->at(1); x0 = a.getX(); y0 = a.getY(); x1 = b.getX(); y1 = b.getY(); // compute outcodes for P0, P1, and whatever point lies outside the clip rectangle outcode0 = computeOutCode(x0, y0); outcode1 = computeOutCode(x1, y1); }
void Eximo::moveChecker(Point2D src, Point2D dest) { vector<Point3D*> vec; Point3D* realSrc = new Point3D(originY + src.getY() * cellSize, 0, originX + src.getX() * cellSize); Point3D* realDest = new Point3D(originY + dest.getY() * cellSize, 0, originX + dest.getX() * cellSize); Point3D* realMiddle = new Point3D( realSrc->getX() + (realDest->getX() - realSrc->getX()) / 2.0, 1, realSrc->getZ() + (realDest->getZ() - realSrc->getZ()) / 2.0); vec.push_back(realSrc); vec.push_back(realMiddle); vec.push_back(realDest); moveCheckerAnim = new LinearAnimation("moveCheckerAnim", 1, vec); movingCheckerDest = dest; movingCheckerOwner = eximoGame->currentPlayer; moveCheckerAnim->restart(); }
int main() { ListPriorityQueue<Point2D, LeftRight> points; points.insert(Point2D(3.5, 5.1)); points.insert(Point2D(8.1, 6.7)); points.insert(Point2D(1.5, 0.3)); cout << points.size() << endl; while (!points.isEmpty()) { Point2D p = points.min(); cout << "X = " << p.getX() << ", Y = " << p.getY() << endl; points.removeMin(); } return 0; }
bool StudentLocalization::stepFindChinContours(const IntensityImage &image, FeatureMap &features) const { //Get the position of the mouth Feature Mouth = features.getFeature(Feature::FEATURE_MOUTH_TOP); Point2D<double> MouthPosition; //Initialise the chin feature std::vector<Point2D<double>> ChinPositions; Feature Chin = Feature(Feature::FEATURE_CHIN); Feature ChinContour = Feature(Feature::FEATURE_CHIN_CONTOUR); int y = 0; int m = 0; //Draw a half circle starting from the center of the mouth for (int j = HALF_CIRCLE; j > 0; j -= DEGREE_STEP){ //reset the position of the mouth MouthPosition.set(Mouth.getX(), Mouth.getY()); MouthPosition.set(drawLine(j, START_POSITION, MouthPosition)); m = m + 1; for (int i = 0; i < MEASURE_RANGE; i++){ MouthPosition.set(drawLine(j, MEASURE_STEP, MouthPosition)); Intensity pixel = image.getPixel(MouthPosition.getX(), MouthPosition.getY()); // If the intensity of the current pixel is lower than 2 (which means it is black) if (pixel < 2){ // If the current angle is within the bounds of the half circle if (j < RIGHT_HALF && j > LEFT_HALF){ ChinContour.addPoint(drawLine(j, 2, MouthPosition)); } else{ //Draw a point on the mouth position, to indicate the detection failed. ChinContour.addPoint(MouthPosition); } break; } } } features.putFeature(ChinContour); return true; }
void DoubleImage::mapPoint(gdImagePtr to, const TriFit& fit, const Point2D& source, const Point2D& dest, Channel channel) { const int d_x = doubleToIntX(dest.getX()); const int d_y = doubleToIntY(dest.getY()); double newVal = (valueAt(source, channel) * fit.saturation) + fit.brightness; const int d_a = gdImageAlpha(to, gdImageGetPixel(to, d_x, d_y)); const int newAlpha = d_a+1; if (newAlpha > 1) { const double oldVal = getPixel(to, d_x, d_y, channel, false); newVal = ((oldVal*d_a)+newVal)/(newAlpha); } const int newColor = boundColor(round(newVal)); setPixel(to, d_x, d_y, newColor, channel, (newAlpha>=gdAlphaTransparent)?gdAlphaTransparent:newAlpha); }
Point2D* Stage::getStart() { double x, y; if (startIndex_ >= numStarts_) { x = SHIP_RADIUS + (rand() % (width_ - SHIP_SIZE)); y = SHIP_RADIUS + (rand() % (height_ - SHIP_SIZE)); } else { Point2D *p = starts_[startIndex_++]; x = p->getX(); y = p->getY(); } while (isShipInWall(x, y)) { x = limit(SHIP_RADIUS, x + (rand() % SHIP_SIZE) - SHIP_RADIUS, width_ - SHIP_RADIUS); y = limit(SHIP_RADIUS, y + (rand() % SHIP_SIZE) - SHIP_RADIUS, height_ - SHIP_RADIUS); } return new Point2D(x, y); }
double doubleSignedTriangleArea(const Point2D & p0, const Point2D & p1, const Point2D & p2){ return ( (p1.getX() - p0.getX()) * (p2.getY() - p0.getY()) - (p2.getX() - p0.getX()) * (p1.getY() - p0.getY()) ); }