Exemplo n.º 1
0
double Line::GetDeviationAngle(const Line &l) const {
    // const double PI = 3.14159258;
#define DEBUG 0
    Point P = _point1;
    Point Goal = _point2;

    Point L = l._point1;
    Point R = l._point2;

    double dist_Goal_L = (Goal - L).NormSquare();
    double dist_Goal_R = (Goal - R).NormSquare();

    double angle, angleL, angleR;
    // we don't need to calculate both angles, but for debugging purposes we do it.
    angleL = atan((Goal - P).CrossProduct(L - P) / (Goal - P).ScalarProduct(L - P));
    angleR = atan((Goal - P).CrossProduct(R - P) / (Goal - P).ScalarProduct(R - P));

    angle = (dist_Goal_L < dist_Goal_R) ? angleL : angleR;
#if DEBUG
     printf("Enter GetAngel()\n");
     printf("\tP=[%f,%f]\n",P.GetX(), P.GetY());
     printf("\tGoal=[%f,%f]\n",Goal.GetX(), Goal.GetY());
     printf("\tL=[%f,%f]\n",L.GetX(), L.GetY());
     printf("\tR=[%f,%f]\n",R.GetX(), R.GetY());
     printf("\t\tdist_Goal_L=%f\n",dist_Goal_L);
     printf("\t\tdist_Goal_R=%f\n",dist_Goal_R);
     printf("\t\t --> angleL=%f\n",angleL);
     printf("\t\t --> angleR=%f\n",angleR);
     printf("\t\t --> angle=%f\n",angle);
     printf("Leave GetAngel()\n");
#endif
    return angle;
}
Exemplo n.º 2
0
// ------------------------------------------------------------------------------------------------------ PUBLIC METHODS
    //Public methods
    const bool Rectangle::Hits(Point aPoint)
    {
        return(
                ((aPoint.GetX()>=points[0].GetX() && aPoint.GetX()<=points[1].GetX()) || (aPoint.GetX()<=points[0].GetX() && aPoint.GetX()>=points[1].GetX()))
        &&
                ((aPoint.GetY()>=points[0].GetY() && aPoint.GetY()<=points[1].GetY()) || (aPoint.GetY()<=points[0].GetY() && aPoint.GetY()>=points[1].GetY()))
        );
    }
Exemplo n.º 3
0
bool fncomp (Point lhs, Point rhs) 
{if(lhs.GetX()<rhs.GetX())return true;
  else if(lhs.GetX()==rhs.GetX())
  {
       if(lhs.GetY()<rhs.GetY())return true;
       else return false;
  }
  else return false;
}
Exemplo n.º 4
0
void DrawWall(Point color, Point a, Point b, Point c, Point d)
{
  GLfloat mat_amb_diff[] = { color.GetX(), color.GetY(), color.GetZ(), 1.0 };
  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff);
  glBegin(GL_QUADS);
  glVertex3f(a.GetX(), a.GetY(), a.GetZ());
  glVertex3f(b.GetX(), b.GetY(), b.GetZ());
  glVertex3f(c.GetX(), c.GetY(), c.GetZ());
  glVertex3f(d.GetX(), d.GetY(), d.GetZ());
  glEnd();
}
Exemplo n.º 5
0
Arquivo: main.cpp Projeto: Ometeo/Math
Point intersect(float t, Point A, Point B)
{
    // [AB] : Q(t) = (1 - t)A + tB, 0 <= t <= 1

    Point I;
    Point tmpA = Point((1 - t) * A.GetX(), (1 - t) * A.GetY());
    Point tmpB = Point(t * B.GetX(), t * B.GetY());

    I = tmpA + tmpB;

    return I;
}
Exemplo n.º 6
0
bool Rectangle::Contains(const Point& point) const
{
	if((point.GetX() >= GetX()) && (point.GetX() <= (GetX() + GetWidth())))
	{
		if((point.GetY() >= GetY()) && (point.GetY() <= (GetY() + GetHeight())))
		{
			return true;
		}
	}
	
	return false;
}
Exemplo n.º 7
0
void MCircle::RotateSecondPoint(Point i_center, double i_angle)
  {
  double pi = 3.141592654;
  double angle = (i_angle)* (pi / 180);
  double rotated_x = cos(angle) * (m_second_point.GetX() - i_center.GetX()) -
    sin(angle) * (m_second_point.GetY() - i_center.GetY()) + i_center.GetX();

  double rotated_y = sin(angle) * (m_second_point.GetX() - i_center.GetX()) +
    cos(angle) * (m_second_point.GetY() - i_center.GetY()) + i_center.GetY();

  m_second_point.SetX(rotated_x);
  m_second_point.SetY(rotated_y);
  }
Exemplo n.º 8
0
bool Rectangle::Appartient( Point p)
// Algorithme :
//
{
	if ( p.GetX() >= listePoints.front().GetX() && p.GetX() <= listePoints.back().GetX()
		&& p.GetY() >= listePoints.front().GetY() && p.GetY() <= listePoints.back().GetY())
	{
		return true;
	}
	else
	{
		return false;
	}
} //----- Fin de Appartient
Exemplo n.º 9
0
void Point::SetPoint(Point point)
{
    float x = point.GetX();
    float y = point.GetY();
    
    SetPoint(x, y);
}
Exemplo n.º 10
0
Arquivo: Point.cpp Projeto: KhvedY/Cat
void main()

{
	Point a;
	Point b(2, 3);
	cout << a.GetX() << "  " << a.GetY() << endl;
	cout << b.GetX() << "  " << b.GetY() << endl;

	a.SetX(9);
	a.SetY(-9);
	cout << a.GetX() << "  " << a.GetY() << endl;

	Point * p = new Point(1, 7);
	cout << p->GetX() << "  " << p->GetY() << endl;
	delete p;
}
Exemplo n.º 11
0
TEST(PointTest, TranslateYMovesPointInNegativeYDirection)
{
	Point p;
	p.TranslateY(-2);
	EXPECT_EQ(0, p.GetX());
	EXPECT_EQ(-2, p.GetY());
}
Exemplo n.º 12
0
TEST(PointTest, TranslateYMovesPointInPositiveYDirection)
{
	Point p;
	p.TranslateY(2);
	EXPECT_EQ(0, p.GetX());
	EXPECT_EQ(2, p.GetY());
}
Exemplo n.º 13
0
bool Segment::Appartient( Point p )
// Algorithme :
// On vérifie que les extrémités du segment et p sont alignés (produit vectoriel),
// puis que p se trouve bien entre elles (produit scalaire + vérification de norme).
{
	// On définit des "points" représentant en fait les coodonnées de vecteurs
	// utilisés pour le calcul
	Point petitX_grandX = Point(
			listePoints.back().GetX() - listePoints.front().GetX(),
			listePoints.back().GetY() - listePoints.front().GetY() );

	Point petitX_p = Point( p.GetX() - listePoints.front().GetX(),
			p.GetY() - listePoints.front().GetY() );

	int comparaisonNormesCarrees = petitX_grandX.GetX() * petitX_grandX.GetX()
			+ petitX_grandX.GetY() * petitX_grandX.GetY()
			- petitX_p.GetX() * petitX_p.GetX()
			- petitX_p.GetY() * petitX_p.GetY();

	if ( petitX_grandX.ProduitVectoriel( petitX_p ) == 0
			&& petitX_grandX.ProduitScalaire( petitX_p ) >= 0
			&& comparaisonNormesCarrees >= 0 )
	{
		return true;
	}
	else
	{
		return false;
	}
} //----- Fin de Appartient
Exemplo n.º 14
0
bool Point::EqualPoints(Point point)
{
    float x = point.GetX();
    float y = point.GetY();
    
    if (x == mX && y == mY) return true;
    
    return false;
}
Exemplo n.º 15
0
float Point::Distance(Point point)
{  
    float x = DistanceX(point.GetX());
    float y = DistanceY(point.GetY());

    y = abs(y);
    x = abs(x);
    
    return max(y, x);
}
Exemplo n.º 16
0
bool Line::IntersectionWithCircle(const Point &centre, double radius /*cm for pedestrians*/) {

    double r = radius;
    double x1 = _point1.GetX();
    double y1 = _point1.GetY();

    double x2 = _point2.GetX();
    double y2 = _point2.GetY();

    double xc = centre.GetX();
    double yc = centre.GetY();

    //this formula assumes that the circle is centered the origin.
    // so we translate the complete stuff such that the circle ends up at the origin
    x1 = x1 - xc;
    y1 = y1 - yc;
    x2 = x2 - xc;
    y2 = y2 - yc;
    //xc=xc-xc;yc=yc-yc; to make it perfect

    // we first check the intersection of the circle and the  infinite line defined by the segment
    double dr2 = ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
    double D2 = (x1 * y2 - x2 * y1) * (x1 * y2 - x2 * y1);
    double r2 = radius * radius;

    double delta = r2 * dr2 - D2;
    if (delta <= 0.0) return false;


    double a = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
    double b = 2 * ((x1 * (x2 - x1)) + y1 * (y2 - y1));
    double c = x1 * x1 + y1 * y1 - r * r;

    delta = b * b - 4 * a * c;

    if ((x1 == x2) && (y1 == y2)) {
        Log->Write("isLineCrossingCircle: Your line is a point");
        return false;
    }
    if (delta < 0.0) {
        char tmp[CLENGTH];
        sprintf(tmp, "there is a bug in 'isLineCrossingCircle', delta(%f) can t be <0 at this point.", delta);
        Log->Write(tmp);
        Log->Write("press ENTER");
        return false; //fixme
        //getc(stdin);
    }

    double t1 = (-b + sqrt(delta)) / (2 * a);
    double t2 = (-b - sqrt(delta)) / (2 * a);
    if ((t1 < 0.0) || (t1 > 1.0)) return false;
    if ((t2 < 0.0) || (t2 > 1.0)) return false;
    return true;
}
Exemplo n.º 17
0
int main()
{
	srand(time(NULL));
	long n;
	Point* p;
	cout << "Enter number of points\n";
	cin >> n;
	cout << "Creating random points\n";
	vector<Point*> PList(0);
	for (long i = 0; i < n; i++)
	{
   	//p = new Point((((double)(rand() % 2000))/10 - 100) ,(((double)(rand() % 2000))/10 - 100));
   	p=new Point((i*5)%97,(i*97)%87);
   	PList.push_back(p);
	}
	KDTNode* root = BuildKDT(PList,0);
	PrintKDT(root);
	cout<<"\nTree is Constructed\n";

	cout << "Enter point to find nearest neighbour" << endl;
	double x,y;
	cout <<"X: ";
	cin >> x;
	cout << "Y: ";
	cin >> y;
	Point* NN = NearestNew(Point(x,y),root);
	printf("Nearest Neighbours Found is: (%3.1f,%3.1f)\n ",NN->GetX(),NN->GetY());
	
	Divider Rroot(Point(-101,-101),Point(101,101));
    Circle CSearch(40.0,Point(40,40));
    Region* Reg= &CSearch;
    vector<Point>thisans;
    SearchKDT(root,Rroot,0,Reg,thisans);
    cout<<"Sample search yields:\n";printvector(thisans);
    
    vector<Point> ans;
    Region* Re;
    cout<<"\n\nEnter Region to be searched\n0:Rectangle \n1:Circle\n";
    int flag;cin>>flag;
    if(flag==0)
    {cout<<"\nEnter Coordiates of LowerLeft And UpperRight points of Rectangle\n";
		double x1,y1,x2,y2;
		cout<<"LowerLeft corner\n";
		cout <<"X: ";
		cin>>x1;
		cout<<"Y: ";
		cin>>y1;
		cout<<"UpperRight corner\n";
		cout <<"X: ";
		cin>>x2;
		cout<<"Y: ";
		cin>>y2;		
		Re = new Rectangle(Point(x1,y1),Point(x2,y2));
	}
Exemplo n.º 18
0
Point Line::NormalVec() const {
    double nx, ny, norm;
    Point r = GetPoint2() - GetPoint1();

    if (r.GetX() == 0.0) {
        nx = 1;
        ny = 0;
    } else {
        nx = -r.GetY() / r.GetX();
        ny = 1;
        /* Normieren */
        norm = sqrt(nx * nx + ny * ny);
        if (fabs(norm) < J_EPS) {
            Log->Write("ERROR: \tLine::NormalVec() norm==0\n");
            exit(0);
        }
        nx /= norm;
        ny /= norm;
    }
    return Point(nx, ny);
}
Exemplo n.º 19
0
void WaypointsManager::setNextWayPoint(Point next)
{
	if (!initPointsFirstTime)
	{
		currentWayPoint.SetX(nextWayPoint.GetX());
		currentWayPoint.SetY(nextWayPoint.GetY());
	}

	nextWayPoint.SetX(next.GetX());
	nextWayPoint.SetY(next.GetY());
	initPointsFirstTime = false;
}
Exemplo n.º 20
0
bool GraphicsManager::Initialize(HWND hwnd)
{
	bool result;
	
	Renderer renderImpl = GetRendererImpl();
	if (renderImpl == Renderer_D3D11)
	{
		m_pRenderer = BE_NEW D3DClass11;
	}
	
	if (!m_pRenderer)
	{
		BE_ERROR("Failed to create Renderer");
		return false;
	}

	if (!m_pRenderer->VInitialize(g_pApp->m_options.m_screenSize.x, g_pApp->m_options.m_screenSize.y, g_pApp->m_options.m_bVsync, hwnd, g_pApp->m_options.m_bFullscreen, 1000.0f, 0.1f))
	{
		BE_ERROR("Could not initialize Renderer");
		return FALSE;
	}

	m_pShaderManager = BE_NEW ShaderManager;
	if (!m_pShaderManager)
	{
		BE_ERROR("Could not Allocate the ShaderManager Object!");
		return false;
	}

	result = m_pShaderManager->Initialize(m_pRenderer);
	if (!result)
	{
		BE_ERROR("Could not initialize the ShaderManager Object!");
		return FALSE;
	}

	m_pDeferredRenderingManager = BE_NEW DeferredRenderingManager;
	if (!m_pDeferredRenderingManager)
	{
		BE_ERROR("Could not allocate the Deferred Buffers");
		return false;
	}

	Point screenSize = g_pApp->GetScreenSize();
	result = m_pDeferredRenderingManager->Initialize(m_pRenderer->GetDevice(), screenSize.GetX(), screenSize.GetY());
	if (!result)
	{
		BE_ERROR("Could not initialize the Deferred Buffers");
		return false;
	}

	return true;
}
Exemplo n.º 21
0
Point Mapper::Localize() {
	Point me;
	me.SetX(-1);
	me.SetY(-1);

	if(grid_height != grid.GetGridHeight() 
		|| grid_width != grid.GetGridWidth()) {

		int matches = 0;

		//loop over exisitng map
		for(int i =0; i < map_height - grid.GetGridHeight(); i++) {
			for (int j =0; j < map_width - grid.GetGridWidth(); j++) {

				int count = 0;
				//at each point, check if our grid matches
				for(int k = 0; k < grid.GetGridHeight(); k++) {
					for (int l = 0; l < grid.GetGridWidth(); l++) {
						double mval = mapData[i+k][j+l];
						double gval = grid.GetCell(l,k)->GetValue();

						if((gval == 0 && mval == 0) || (gval > 0 && mval > 0)) {
							count++;
						} else if(gval < 0) {
							count++;
						}
					}
				}

				//if we match every square
				if(count == (grid.GetGridWidth()*grid.GetGridHeight())) {
					Cell* loc = grid.GetCurrentCell();
					me.SetX(loc->GetX()+j);
					me.SetY(loc->GetY()+i);
					matches++;
				}
			}
		}

		grid_width = grid.GetGridWidth();
		grid_height = grid.GetGridHeight();

		cout << matches << endl;

		if(matches == 1) {
			localized = true;
		}
	}

	cout << *grid.GetCurrentCell();
	cout << "Point x: " << me.GetX() << " y: " << me.GetY() << endl;
	return me;
}
Exemplo n.º 22
0
void Point::GetX( Local< String > prop, const PropertyCallbackInfo< Value > &info ) {
	// Enter new scope
	HandleScope scope;

	// Get wrapped object
	Local< Object > self = info.Holder();
	Local< External > wrap = Local< External >::Cast( self->GetInternalField( 0 ) );

	// Set return value
	Point* point = static_cast< Point* >( wrap->Value() );
	info.GetReturnValue().Set( Number::New( point->GetX() ) );
}
Exemplo n.º 23
0
double Line::NormalComp(const Point &v) const {
    // Normierte Vectoren
    Point l = (GetPoint2() - GetPoint1()).Normalized();
    const Point &n = NormalVec();


    double lx = l.GetX();
    double ly = l.GetY();
    double nx = n.GetX();
    double ny = n.GetY();
    double alpha;

    if (fabs(lx) < J_EPS) {
        alpha = v.GetX() / nx;
    } else if (fabs(ly) < J_EPS) {
        alpha = v.GetY() / ny;
    } else {
        alpha = (v.GetY() * lx - v.GetX() * ly) / (nx * ly - ny * lx);
    }

    return fabs(alpha);
}
Exemplo n.º 24
0
Rectangle::Rectangle ( Point coinSuperieurGauche, Point coinInferieutDroit )
// Algorithme :
//
{
#ifdef MAP
    cout << "Appel au constructeur de <Rectangle>" << endl;
#endif

    if ( !(coinSuperieurGauche.GetX() >  coinInferieutDroit.GetX() ||
    		coinSuperieurGauche.GetY() >  coinInferieutDroit.GetY() ) )
    {
    	listePoints.push_back(coinSuperieurGauche);
    	listePoints.push_back(coinInferieutDroit);
    }
    else
    {
    	listePoints.push_back(coinInferieutDroit);
    	listePoints.push_back(coinSuperieurGauche);
    }


}//----- Fin de Rectangle
Exemplo n.º 25
0
void Mapper::Hide() {
	Point hidingSpot;
	vector<vector<double> > rawMap = ml.LoadMap(mapName);
	hidingSpot = ml.FindHidingSpots(mapData);

	grid.LoadValues(rawMap);
	
	threshold = grid.CalculateThreshold();

	Cell* current = grid.GetCurrentCell();
	Cell* goal = grid.GetCell(hidingSpot.GetX(), hidingSpot.GetY());
	MoveToCell(current, goal);
}
Exemplo n.º 26
0
Segment::Segment( Point pointPetitX, Point pointGrandX )
// Algorithme :
//
{
#ifdef MAP
	cout << "Appel au constructeur de <Segment>" << endl;
#endif

	if ( pointPetitX.GetX() <= pointGrandX.GetX() )
	{

		listePoints.push_front( pointPetitX );
		listePoints.push_back( pointGrandX );

	}
	else
	{

		listePoints.push_front( pointGrandX );
		listePoints.push_back( pointPetitX );

	}
} //----- Fin de Segment
Exemplo n.º 27
0
/*
 *  Check the head and the tail with ship's length
 *
 */
bool Ship::IsValidPosition(const Point& head, const Point& tail) const
{
	if (head.GetX() == tail.GetX()) //Horizontal
	{
		if (abs(head.GetY() - tail.GetY()) == GetLength() - 1) return true;
		else return false;
	}
	else							//Vertical
	{
		if (abs(head.GetX() - tail.GetX()) == GetLength() - 1) return true;
		else return false;
	}

	//bool isVertical = m_Position[0].GetX() == m_Position[1].GetX() ? true : false;
	//char min, max;
	//if (isVertical){
	//	min = m_Position[0].GetY();
	//	max = m_Position[0].GetY();
	//	for (int i = 1; i < m_Hp; i++){
	//		if (min > m_Position[i].GetY()) min = m_Position[i].GetY();
	//		if (max < m_Position[i].GetY()) max = m_Position[i].GetY();
	//		if (m_Position[i - 1].GetX() != m_Position[i].GetX()) return false;
	//	}
	//}
	//else{
	//	min = m_Position[0].GetX();
	//	max = m_Position[0].GetX();
	//	for (int i = 1; i < m_Hp; i++){
	//		if (min > m_Position[i].GetX()) min = m_Position[i].GetX();
	//		if (max < m_Position[i].GetX()) max = m_Position[i].GetX();
	//		if (m_Position[i - 1].GetY() != m_Position[i].GetY()) return false;
	//	}
	//}
	//if (max - min != m_Hp - 1) return false;
	//return true;
}
Exemplo n.º 28
0
int getUnusedExtension(const DbArray<HalfSegment>& segs,
                        const int pos,
                        const bool* used){
      HalfSegment hs;
      segs.Get(pos,hs);
      Point dp = hs.GetDomPoint();
      double dpx = dp.GetX();
      bool done = false;
      int pos2=pos-1;
      while(pos2>=0 && !done){
        if(used[pos2]){
          pos2--;
        } else {
          segs.Get(pos2,hs);
          if(AlmostEqual(dp,hs.GetDomPoint())){
             return pos2;
          } else {
             double dpx2 = hs.GetDomPoint().GetX();
             if(AlmostEqual(dpx,dpx2)){
               pos2--;
             } else { // outside the X-Range
               done = true;
             }
          }
        }
      }
      pos2 = pos+1;
      while(pos2<segs.Size() ){
         if(used[pos2]){
             pos2++;
         }else {
            segs.Get(pos2,hs);
            if(AlmostEqual(dp,hs.GetDomPoint())){
              return pos2;
            } else {
              double dpx2 = hs.GetDomPoint().GetX();
              if(AlmostEqual(dpx,dpx2)){
                pos2++;
              }else{
                return -1;
              }
            }
         }
      }
      return -1;
}
Exemplo n.º 29
0
// caca
void Land::initFood()
{
  std::deque<Point> EmptyList;

  // read all cell
  for (int i = 0; i < this->width; i++)
    {
      for (int j = 0; j < this->height; j++)
	{
	  if (((this->land)[i][j]).GetContent() == ' ')
	    {
	      EmptyList.push_back((this->land)[i][j]);
	    }
	}
    }
  // get rand one
  Point p = Randomizer::GetItem<std::deque<Point> >(EmptyList);
  ((this->land)[p.GetX()][p.GetY()]).SetContent('f');
}
Exemplo n.º 30
0
Point* Control::GetAbsoluteScreenPosition()
{
	int x = 0;
	int y = 0;
	Control* child = this;
	Control* parent = this->GetParent();
	x = this->topLeft->GetX();
	y = this->topLeft->GetY();
	Point* result = new Point(x,y);
	while(parent!=0)
	{
		x = result->GetX() + parent->GetTopLeft()->GetX();
		y = result->GetY() + parent->GetTopLeft()->GetY();
		result = new Point(x,y);
		child = parent;
		parent = child->GetParent();
	}
	return result;
}