//Display Method
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glPointSize(10);

	if(pts.p1.getX() != 0 || pts.p2.getX() != 0 || pts.p3.getX() != 0) //Reset Struct and set first
		{	a = subtactPoints(pts.p1, pts.p2);
			b = subtactPoints(pts.p2, pts.p3);
			c = subtactPoints(pts.p3, pts.p1);	
			drawPoint(pts.p1.getX(), pts.p1.getY());
			drawPoint(pts.p2.getX(), pts.p2.getY());
			drawPoint(pts.p3.getX(), pts.p3.getY());
			drawTriangle(pts);
			exCenter = calcCenter(pts, a, b, c);
			exRad = radCirc(a, b, c);
			glColor3f(1.0, 1.0, 0.0);
			drawCircle(exCenter.getX(), exCenter.getY(), exRad, 1000);
			inCenter = calcCenterInCirc(pts);
			glColor3f(0.0, 1.0, 0.0);
			drawCircle(inCenter.getX(), inCenter.getY(), inRad, 1000);
			nineCenter = calcNineCirc(pts);
			glColor3f(0.0, 1.0, 1.0);
			drawCircle(nineCenter.getX(), nineCenter.getY(), nineRad, 1000);
		}

}
float dotProduct(Point2 A, Point2 B)
{
	Point2 ret;
	ret.set((A.getX()*B.getX()),(A.getY()*B.getY()));
	int r = ret.getX() + ret.getY();
	return r;
}
Example #3
0
Point2 CohenSutherlandClip(Point2 p1, Point2 p2)	//function to tell us if the line intersects with the rectangle	
{													//returns a set of points if such intersection occurs
	unsigned char code = getCode(p1);			//takes the first point to test the location
	Point2 p(p1.getX(), p1.getY());				//takes the first point and places it into a local variable
	float tempX, tempY;							
	float dely = p2.getY() - p1.getY();			//these values help determine the slope of the line
	float delx = p2.getX() - p1.getX();
	if(code & 8) {								//to the left
		tempY = p.getY() + ((LEFT - p.getX()) * dely / delx);		//obtains the y value where the line crosses
		tempX = LEFT;												//obtains the x value where the line crosses
		p.set(tempX, tempY);									//places these values into p
	}
	if(code & 2) {								//to the right
		tempY = p.getY() + ((RIGHT - p.getX()) * dely / delx);		//obtains the y value where the line crosses
		tempX = RIGHT;												//obtains the x value where the line crosses
		p.set(tempX, tempY);									//places these value into p
	}
	if(code & 1) {								//to the bottom
		if(p.getY()<BOTTOM)										
		{
			tempX = p.getX() + ((BOTTOM - p.getY()) * delx / dely);		//obtains the x value where line crosses
			tempY = BOTTOM;												//obtains the y value where line crosses
			p.set(tempX, tempY);
		}
	}
	if(code & 4) {
		if(p.getY()>TOP)						//to the top
		{
			tempX = p.getX() + ((TOP - p.getY()) * delx / dely);		//obtains the x value where line crosses
			tempY = TOP;												//obtains the y value where line crosses
			p.set(tempX, tempY);
		}
	}
	return p;					//returns the point where the line intersects with the rectangle
}
Point2 addPoints(Point2 A, Point2 B)
{
	int x = B.getX() + A.getX();
	int y = B.getY() + A.getY();
	Point2 ret;
	ret.set(x,y);
	return ret;
}
Point2 subtactPoints(Point2 A, Point2 B)
{
	int x = B.getX() - A.getX();
	int y = B.getY() - A.getY();
	Point2 ret;
	ret.set(x,y);
	return ret;
}
Example #6
0
unsigned char getCode(Point2 p)				//This function returns a bitwise OR value
{
	unsigned char code = 0;
	if(p.getX()<LEFT)   code |= 8;			//if on the left, then TFFF or 1000
	if(p.getY()>TOP)    code |= 4;			//if on the top, then FTFF or 0100
	if(p.getX()>RIGHT)  code |= 2;			//if on the right, then FFTF or 0010
	if(p.getY()<BOTTOM) code |= 1;			//if on the bottom, then FFFT or 0001
	return code;							
}
Example #7
0
void drawArc(Point2 centre, float radius, float startAngle, float sweep)
{
	Turtle t;
	const int n = 30;
	float angle = startAngle * M_PI / 180;
	float angleInc = sweep * M_PI / (180 * n);
	float cx = centre.getX(), cy = centre.getY();
	t.moveTo(Point2(cx + radius*cos(angle), cy + radius*sin(angle)));
	for (int k = 1; k < n; k++, angle += angleInc)
	{
		t.lineTo(Point2(cx + radius*cos(angle), cy + radius*sin(angle)));
	}
}
Example #8
0
void SFAsset::SetPosition(Point2 & point) {
  Vector2 v(point.getX(), point.getY());
  bbox->SetCentre(v);
}
float magnitude(Point2 A)
{
	return sqrt(pow(A.getX(),2) + pow(A.getY(),2));
}
Point2 scalePoint(float A, Point2 B)
{
	Point2 ret;
	ret.set(A*B.getX(), A*B.getY());
	return ret;
}
Point2 getNormal(Point2 A)
{
	Point2 ret;
	ret.set(-A.getY(), A.getX());
	return ret;
}
Example #12
0
	Vector(Point2 pt, Point2 pt2) {
		x = pt.getX() - pt2.getX();
		y = pt.getY() - pt2.getY();	
	}
void Canvas::lineTo( const Point2 & p ) {

	// simply call other variant
	lineTo( p.getX(), p.getY() );

}
Example #14
0
bool equals(Point2 p1, Point2 p2)		//this tests to see if two sets of points are the same
{
	if((p1.getX()==p2.getX()) && (p1.getY()==p2.getY()))
		return  true;
	return false;
}
Example #15
0
void GLView::drawChoice0() {
  /// drawing example

  glColor3f(0,0.5,1);
  ugl::drawText("drawChoice0: "+_choiceText,0,0);

  glPushMatrix();

  glColor3f(1,0,0);

  vector<Point2> points = curve->getPoints();
  vector<Point2> refPoints = curve->getReferencePoints();
  vector<Point2> *curvePoints = curve->getCurvePoints();

  //User-defined polygon
  glLineWidth(1);
  glColor3f(1,0,0);
  glBegin(GL_LINE_STRIP);
  for(int i = 0; i < points.size(); i++){
      Point2 p = points.at(i);
      glVertex2f(p.getX(),p.getY());
  }
  if(closed){
      if(points.size() > 0){
          glVertex2f(points.at(0).getX(),points.at(0).getY());
      }
  }
  glEnd();

  //User-defined points
  glPointSize(5);
  glColor3f(1,0,0);
  glBegin(GL_POINTS);
  for(int i = 0; i < points.size(); i++){
      Point2 p = points.at(i);
      if(!p.isFixed()){
          glVertex2f(p.getX(),p.getY());
      }
  }
  glEnd();

  //Fixed points
  glPointSize(10);
  glColor3f(1,0,0);
  glBegin(GL_POINTS);
  for(int i = 0; i < points.size(); i++){
      Point2 p = points.at(i);
      if(p.isFixed()){
        glVertex2f(p.getX(),p.getY());
      }

  }
  glEnd();



  //Ref points
  glLineWidth(2);
  glColor3f(0,0,1);
  glBegin(GL_LINE_STRIP);
  for(int i = 0; i < refPoints.size(); i++){
      Point2 p = refPoints.at(i);
      glVertex2f(p.getX(), p.getY());
  }
  if(closed){
      if(refPoints.size() > 0){
          glVertex2f(refPoints.at(0).getX(),refPoints.at(0).getY());
      }
  }
  glEnd();



  //Curve
  glLineWidth(2);
  glColor3f(0,1,0);
  glBegin(GL_LINE_STRIP);
  for(int i = 0; i < curvePoints->size(); i++){
      Point2 p = curvePoints->at(i);
      glVertex2f(p.getX(), p.getY());
  }
  if(closed){
      if(curvePoints->size() > 0){
          glVertex2f(curvePoints->at(0).getX(),curvePoints->at(0).getY());
      }
  }
  glEnd();


  //Curve points
  glPointSize(5);
  glColor3f(0,1,0);
  glBegin(GL_POINTS);
  for(int i = 0; i < curvePoints->size(); i++){
      Point2 p = curvePoints->at(i);
      glVertex2f(p.getX(), p.getY());
      ugl::drawText(""+i,p.getX(),p.getY());
  }

  glEnd();

  glPopMatrix();
}