Esempio 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;
}
Esempio 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()))
        );
    }
Esempio 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;
}
Esempio 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();
}
Esempio n. 5
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;
}
Esempio n. 6
0
File: main.cpp Progetto: 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;
}
Esempio 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);
  }
Esempio 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
Esempio n. 9
0
void Point::SetPoint(Point point)
{
    float x = point.GetX();
    float y = point.GetY();
    
    SetPoint(x, y);
}
Esempio n. 10
0
File: Point.cpp Progetto: 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;
}
Esempio n. 11
0
TEST(PointTest, TranslateYMovesPointInNegativeYDirection)
{
	Point p;
	p.TranslateY(-2);
	EXPECT_EQ(0, p.GetX());
	EXPECT_EQ(-2, p.GetY());
}
Esempio n. 12
0
TEST(PointTest, TranslateYMovesPointInPositiveYDirection)
{
	Point p;
	p.TranslateY(2);
	EXPECT_EQ(0, p.GetX());
	EXPECT_EQ(2, p.GetY());
}
Esempio 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
Esempio 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;
}
Esempio 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);
}
Esempio n. 16
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));
	}
Esempio n. 17
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;
}
Esempio n. 18
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;
}
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;
}
Esempio n. 20
0
void Point::GetY( 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->GetY() ) );
}
Esempio n. 21
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);
}
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);
}
Esempio n. 23
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
Esempio n. 24
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;
}
Esempio n. 25
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');
}
Esempio n. 26
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;
}
Esempio n. 27
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);
}
Esempio n. 28
0
bool getDir(const vector<Point>& vp){
  // determine the direction of cycle
  int min = 0;
  for(unsigned int i=1;i<vp.size();i++){
    if(vp[i] < vp[min]){
       min = i;
    }
  }

  bool cw;
  int s = vp.size();
  if(AlmostEqual(vp[0],vp[vp.size()-1])){
    s--;
  }

  Point a = vp[ (min - 1 + s ) % s ];
  Point p = vp[min];
  Point b = vp[ (min+1) % s];
  if(AlmostEqual(a.GetX(),p.GetX())){ // a -> p vertical
    if(a.GetY()>p.GetY()){
       cw = false;
    } else {
       cw = true;
    }
  } else if(AlmostEqual(p.GetX(), b.GetX())){ //p -> b vertical
    if(p.GetY()>b.GetY()){
       cw = false;
    } else {
       cw = true;
    }
  } else { // both segments are non-vertical
    double m_p_a = (a.GetY() - p.GetY()) / (a.GetX() - p.GetX());
    double m_p_b = (b.GetY() - p.GetY()) / (b.GetX() - p.GetX());
    if(m_p_a > m_p_b){
        cw = false;
    } else {
        cw = true;
    }
  }
  return cw;
}
Esempio n. 29
0
void CameraNode::GetScreenProjectPoint( Vec3& start, Vec3& end, const Point& screenPosition, float distance )
   {
   float revScreenLocX = ( ( float ) screenPosition.GetX() / ( float ) g_pApp->GetScreenSize().GetX() - 0.5f ) * 2.0f;
   float revScreenLocY = ( ( float ) screenPosition.GetY() / ( float ) g_pApp->GetScreenSize().GetY() - 0.5f ) * -2.0f;
   // The near plane maps to Z=-1 in Normalized Device Coordinates
   
   Mat4x4 invV = m_View.Inverse();
   Mat4x4 invP = m_Projection.Inverse();
   
   Mat4x4 inv_MP = Mat4x4( m_Projection * m_View ).Inverse();

   Vec4 rayStart_NDC = Vec4( revScreenLocX, revScreenLocY, -1.0f, 1.0f );
   Vec4 rayStart_Wor = inv_MP.Xform( rayStart_NDC );
   rayStart_Wor /= rayStart_Wor.w;
   start = rayStart_Wor;

   Vec4 rayEnd_NDC = Vec4( revScreenLocX, revScreenLocY, 0.0f, 1.0f );
   Vec4 rayEnd_Wor = inv_MP.Xform( rayEnd_NDC );
   rayEnd_Wor /= rayEnd_Wor.w;
   Vec3 dir = rayEnd_Wor - rayStart_Wor;
   dir.Normalize();
   end = start + dir * distance;
   }
Esempio n. 30
0
 double Slope()
 {
     return ((p2.GetY() - p1.GetY()) / (p2.GetX() - p1.GetX()));
 }