示例#1
0
void TopoFace::load_points() { 
    Iterator i;
    float *x = new float[npts()];
    float *y = new float[npts()];
    int counter = 0;
    first(i);
    TopoEdge* first_edge = edge(elem(i));
    TopoEdge* curr_edge = first_edge;
    int numedges = number();
    int edgei = 0;
    do {
	const float *xptr = curr_edge->xpoints();
	const float *yptr = curr_edge->ypoints();
	int edge_npts = curr_edge->npts();
	if (clockwise(curr_edge)) {
	    for (int j=0; j<edge_npts; j++) {
		x[counter] = xptr[j];
		y[counter] = yptr[j];
		counter++;
	    }
	} else {
	    for (int j=edge_npts-1; j>=0; j--) {
		x[counter] = xptr[j];
		y[counter] = yptr[j];
		counter++;
	    }
	}
	const TopoNode* next_node = clockwise(curr_edge) ? curr_edge->end_node() : curr_edge->start_node();
	curr_edge = next_node->next_edge(curr_edge, this);
	edgei++;
    } while (curr_edge && curr_edge != first_edge && edgei < numedges);

    insert_pointers(npts(), x, y, nil, true);
}
示例#2
0
uint16_t CustomStepper::step( char *name ) {
	
	constantCount++;
	int test = constantCount % stepEveryXFrames;
	if( test == 0){
 	 	if(userSpeed > 0 ){
		    clockwise( count );
				count++;
		  } else if (userSpeed < 0) {
		    anticlockwise( count );
				count--;
		  } else {
		    // stand still
			}

			// make sure the count stays within bounds
			if (count > countsperrev){
			    count = 0;
			} else if (count < 0){
					count = countsperrev;
			}
	}
	
	return count;
}
示例#3
0
/** tests a point for being inside (or on the boundary of) a convex (!) polygon
 *  \param the test point
 *  \param the polygon, represented as a ordered sequence of edge points
 *  \return true if the point is in the polygon or on its boundary
 */
bool GeometryUtilities::pointInPolygon(const cv::Vec2f point, const std::vector<cv::Vec2f> &polygon) {
	unsigned int lastPolyPoint = polygon.size()-1;
	int indicator = clockwise(point, polygon[lastPolyPoint], polygon[0]);

	// point is on the line, but outside the edge of this polygon?
	if (indicator == 0) {
		return (pointOnEdge(point, polygon[lastPolyPoint], polygon[0])) ? true : false;
	}

	for (unsigned int i = 0; i < lastPolyPoint; ++i) {
		int tmp = clockwise(point, polygon[i], polygon[i+1]);
		if (tmp == 0) {
			// point is on the line, but outside the edge of this polygon?
			return (pointOnEdge(point, polygon[i], polygon[i+1])) ?  true : false;
		} else {
			// outside the poly if the point is clockwise with two points,
			// counterclockwise with others
			if (indicator != tmp) return false;
		}
	}
	return true;
}
/*ajusta a posicao zero da mesa xy*/
void calibraZero(){
	//move a mesa ate atingir as duas chaves de fim de curso
	int i;
	TM_HD44780_Clear();
	TM_HD44780_Puts(0, 0, "Calibrando...");
	while(!(readEnd('x')&&readEnd('y'))){
		if(!readEnd('x')){
			counterclockwise('x');
		}
		if(!readEnd('y')){
			counterclockwise('y');
		}
	}
	//apos o ajuste de zero, volta um pouco para liberar as chaves
	for(i=15; i--;){
		clockwise('x');
		clockwise('y');
	}
	TM_HD44780_Clear();
	TM_HD44780_Puts(0, 0, "Mesa calibrada");
	Delayms(250);
	posit_x=0;
	posit_y=0;
}
示例#5
0
/** tests a point for being on an edge delimited by two points
 */
bool GeometryUtilities::pointOnEdge(const cv::Vec2f point, const cv::Vec2f edge_point1, const cv::Vec2f edge_point2) {
	// triangle? -> point not on the edge
	if (clockwise(point, edge_point1, edge_point2) != 0) return false;

	cv::Vec2f edge = edge_point1 - edge_point2;
	cv::Vec2f connection = edge_point1 - point;

	// oops, identical to first point?
	if ( (fabs(connection[0]) <= std::numeric_limits<float>::epsilon()) && (fabs(connection[1]) <= std::numeric_limits<float>::epsilon()) ) return true;

	// ratio < 1? -> point on edge
	if (fabs(connection[0]) > std::numeric_limits<float>::epsilon()) {
		double ratio = connection[0] / edge[0];
		return ((ratio >= 0) && (ratio <= 1));
	} else {
		// connection[1] must be non-zero now 
		double ratio = connection[1] / edge[1];
		return ((ratio >= 0) && (ratio <= 1));
	}
}
示例#6
0
int TopoFace::npts() const { 
  if (_npts < 0  && !is_empty()) {
    Iterator i;
    int counter = 0;
    first(i);
    TopoEdge* first_edge = edge(elem(i));
    TopoEdge* curr_edge = first_edge;
    int numedges = number();
    int edgei = 0;
    do {
      int edge_npts = curr_edge->npts();
      counter += edge_npts;
      const TopoNode* next_node = clockwise(curr_edge) ?
	curr_edge->end_node() : curr_edge->start_node();
      curr_edge = next_node->next_edge(curr_edge, this);
      edgei++;
    } while (curr_edge && curr_edge != first_edge && edgei < numedges);
    ((TopoFace*)this)->_npts = counter;
  }
  return _npts; 
}
示例#7
0
文件: dice.c 项目: samael65535/ITjob
int main()
{
  int dice1[6], dice2[6];
  int i = 0, is_same = 0, j = 0;
  for(i = 0; i < 6; i++){
    scanf("%d", &dice1[i]);
    printf("%d\t", dice1[i]);
  }
  printf("\n");
  for(i = 0; i < 6; i++){
    scanf("%d", &dice2[i]);
    printf("%d\t", dice2[i]);
  }
  printf("\n");
  for(j = 0; j < 4; j++){
    vertical(dice1);
    if(is_same == 0)
      is_same = judge(dice1, dice2);
    for(i = 0; i < 4; i++){
      horizontal(dice1);
      if(is_same == 0)
        is_same = judge(dice1, dice2);
    }
    vertical(dice1);
    for(i = 0; i < 4; i++){
      clockwise(dice1);
      if(is_same == 0)
        is_same = judge(dice1, dice2);
    }
  }
  if(is_same == 0)
    printf("\nNO\n");
  else
    printf("\nYES\n");
  return 0;
}
示例#8
0
int main(){
	scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
	printf("%lf %d",area(x1,y1,x2,y2,x3,y3),clockwise(x1,y1,x2,y2,x3,y3));
	return 0;
}
示例#9
0
bool GeometryUtilities::isCounterClockwise(const cv::Vec2f p1, const cv::Vec2f p2, const cv::Vec2f p3)
{
	return clockwise(p1, p2, p3) > 0;
}
示例#10
0
static void
triangle_to_trapezoids (const pixman_triangle_t *tri, pixman_trapezoid_t *traps)
{
    const pixman_point_fixed_t *top, *left, *right, *tmp;

    top = &tri->p1;
    left = &tri->p2;
    right = &tri->p3;

    if (greater_y (top, left))
    {
	tmp = left;
	left = top;
	top = tmp;
    }

    if (greater_y (top, right))
    {
	tmp = right;
	right = top;
	top = tmp;
    }

    if (clockwise (top, right, left))
    {
	tmp = right;
	right = left;
	left = tmp;
    }
    
    /*
     * Two cases:
     *
     *		+		+
     *	       / \             / \
     *	      /   \           /	  \
     *	     /     +         +	   \
     *      /    --           --    \
     *     /   --               --   \
     *    / ---                   --- \
     *	 +--                         --+
     */

    traps->top = top->y;
    traps->left.p1 = *top;
    traps->left.p2 = *left;
    traps->right.p1 = *top;
    traps->right.p2 = *right;

    if (right->y < left->y)
	traps->bottom = right->y;
    else
	traps->bottom = left->y;

    traps++;

    *traps = *(traps - 1);
    
    if (right->y < left->y)
    {
	traps->top = right->y;
	traps->bottom = left->y;
	traps->right.p1 = *right;
	traps->right.p2 = *left;
    }
    else
    {
	traps->top = left->y;
	traps->bottom = right->y;
	traps->left.p1 = *left;
	traps->left.p2 = *right;
    }
}
示例#11
0
void loop()
{
	
	if(!switch_1.getState() && millis()-sw1_last_click_time > BUTTON_DEBOUNCE_INTERVAL)
	{	
		powerToggle();
		while(!switch_1.getState());	//wait until switch release.
		sw1_last_click_time = millis();
	}
	
	
	if(powerFlag)	//main body code
	{
		if(!switch_2.getState() && millis()-sw2_last_click_time > BUTTON_DEBOUNCE_INTERVAL)
		{
			directionToggle();
			while(!switch_2.getState());	//wait until switch released.
			sw2_last_click_time = millis();
		}
		
		motorEnable.High();
		
		
		
		if(soft_start_flag)
		{
			uint8_t currentPwmVal = map(analogRead(POT),0,1023,0,255);
			
			if(incrementer < currentPwmVal && millis() - softStartInterval > STARTUP_INTERVAL_DELAY)
			{
				incrementer+=10;
				pwmValue = incrementer;
				softStartInterval = millis();
			}
			
			else if(incrementer >= currentPwmVal)
			{	
				soft_start_flag = 0;
				incrementer = INCREMENTER_INIT_VALUE;
			}
		}
		
		else
		{
			pwmValue = map(analogRead(POT),0,1023,0,255);
		}
		
		
		if(!directionFlag)
			clockwise();
		else
			anti_clockwise();
		
		Serial.println(analogRead(SHUNT_RES));
		
		if(analogRead(SHUNT_RES)>=14)
		{
		//	uint32_t startCheck = millis();
			Serial.println("OverCurrent_detected");
		/*	while(millis() - startCheck < 500 && analogRead(SHUNT_RES) >= 10);
			
			if (millis()-startCheck >= 300)
			{
				Serial.println("stop");
				motorEnable.Low();
				delay(1000);
			}
		*/
			
			delay(400);
			if(analogRead(SHUNT_RES)>=14)
			{
				ledRed.High();
				Serial.println("stop");
				motorEnable.Low();
				delay(2000);
				soft_start_flag=1;
			}
			
		}
		else
		{
			//soft_start_flag = 1;
			motorEnable.High();
			ledRed.Low();
		}
	}
	else
	{
		//power down all , blue led is controlled in powerToggle().
		motorEnable.Low();
		ledRed.Low();
		ledGreen.Low();
		ledYellow.Low();
		digitalWrite(MOTOR_PWM_1,LOW);
		digitalWrite(MOTOR_PWM_2,LOW);
	}
	
}
示例#12
0
void RTI()

{	
	int temp;//temporary storage
	
	
	
	//4 tick approximately 1 second
	counter++;//do clock ticking  
	SetOptCount++;//do clock ticking
	
	
	
	//obstacle when user press '5'
	if(obstacle==1)
	{
		RTIcounter++; //start count the RTI
		
		//Initialize 3 second delay
		if(RTIcounter==1)
		{
				duty=0;
				printf("DC motor off, Delay 3 second\n");
		}
		
		//After 3 second Rotate the stepper motor to the right
		//(12 RTI counter= 3 second)
		if(RTIcounter==12)
		{
				printf("Rotate 90 degree right\n");					
				clockwise(1);//assume its rotate 90 degree right
				printf("wait 2 second\n");
		}
		
		
		//After 5 second reset RTI counter and collision value to 0, then continue straight
		//(20 RTI counter = 5 second)
		if(RTIcounter==20)//
		{
		 		duty=20;
				printf("Continue straight\n");
		
				PWMDTY7 = duty;
				RTIcounter=0;//reset RTI timer set to 0
				obstacle=0;//reset collision to 0
				// clear RTI flag
		}
	}//end obstacle
	
	
	
	//when heater is on, first LED from top is on and turn heater on
	if(heaterOn==1)
	{	
	
		//heater on		   
		DDRM=0xff;
		PTM=0x81;//heater on
		delay(100);//delay 100ms allow heater to operate
		
		//LED on
		DDRK=0xff;
		PORTK=0x01;
		
		
	}
	
	else
	{
	 	//heater off
	 	DDRM=0xff;
		PTM=0x00;//heater off
		
		//first LED from top off
		DDRK=0xff;
		PORTK=0x00;
	}
	
	
	//for RTI, 4 tick is equal to 1 second
	if(SetOptCount==4)
	{
	optCount=0;
	}

	
	//refresh LCD every 3 second
	if(SetOptCount==12)
	{	
		//refresh LCD, then print motor speed and temperature			  
		LCD_instruction(0x00);						
		Lcd2PP_Init();
		printString(optCount,temperature);		
		SetOptCount=0;//reset RPS counter to 0
	}
	
	//get temperature every 5 second
	if(counter==20)
	{ 
	  //initialize interrupt for temperature sensor
	  runTemperature();
	
	  			//if temperature over 85, buzzer on, overheat LED on & turn off heater
				if(temperature>=85)
				{		//turn on buzzer
				 		DDRK=0xff;
						PORTK=0x22;
						delay(100);//give time to buzzer to operate
						heaterOn=0;
						
						//turn off buzzer
						PORTK=0x00;
						DDRK=0x00;
						
						//heater off automatically
						DDRM=0xff;
						PTM=0x00;
						
				}
	  				
						counter=0;//reset counter for RTI
	}
	 	DDRM=0x00;//set DDRM on, to read  from keypad 
		CRGFLG=CRGFLG;//Acknowledge interrupt
											 
}
示例#13
0
void Polygon::getIndices()
{
	isConvex = true;
	for (int i = 0;i<pointList.size();i++)
		if (!clockwise(pointList[i],pointList[nextPointIndex(i)],pointList[nextPointIndex(i,2)]))
		{
			isConvex = false;
			break;
		}
	if (isConvex)
	{
		LOGI("isCONvex");
		for (int i = 1;i<pointList.size()-1;i++)
		{
			indices.push_back(0);
			indices.push_back(i);
			indices.push_back(i+1);
		}
	}
	else
	{
		LOGI("notConvex");
		vector<int> next(pointList.size());
		int now = 0;
		for (int i = 0;i<pointList.size();i++)
			next[i] = nextPointIndex(i);
		for (int i = 0;i<pointList.size()-2;i++)
		{
			int old_now = now;
			while (true)
			{
				int index1 = now,index2 = next[now],index3 = next[index2];
				if (!clockwise(pointList[index1],pointList[index2],pointList[index3]))
				{
					now = next[now];
					if (now == old_now)
					{
						LOGI("error,cannot find valid vertex %f %f",center.x,center.y);
						break;
					}
					continue;
				}
				int otherPoint = next[index3];
				bool findInner = false;
				while (index1!=otherPoint)
				{
					if (innerPoint(pointList[otherPoint],pointList[index1],pointList[index2],pointList[index3]))
					{
						findInner = true;
						break;
					}
					otherPoint = next[otherPoint];
				}
				if (findInner == false)
				{
					indices.push_back(index1);
					indices.push_back(index2);
					indices.push_back(index3);
					next[index1] = index3;
					break;
				}
				now = next[now];
				if (now == old_now)
				{
					LOGI("error,cannot find valid vertex1");
					break;
				}
			}
		}
		next.clear();
	}
}
示例#14
0
 void floodFillFinder(coord block, unsigned int Distance[MazeDefinitions::MAZE_LEN][MazeDefinitions::MAZE_LEN],
                      BitVector256 horizontal, BitVector256 vertical){
     std::stack<coord> coords;
     BitVector256 visited;
     
     visited.clearAll();
     coords.push(block);
     while(!coords.empty())
     {
         
         unsigned int row = (coords.top()).y;
         unsigned int col = (coords.top()).x;
         coords.pop();
         
         visited.set(row,col);
         
         if(Distance[col][row] == 0 || Distance[col][row] == infinity)
             continue;
         
         unsigned int shortest = ~0;
         
         Dir face = NORTH;
         for(int i = 0; i < 4; i++, face = clockwise(face))
         {
             unsigned int nextX = col;
             unsigned int nextY = row;
             bool hasWall = false;
             
             switch(face){
                 case NORTH:
                     nextY += 1;
                     hasWall = horizontal.get(nextY, nextX);
                     break;
                 case EAST:
                     nextX += 1;
                     hasWall = vertical.get(nextY, nextX);
                     break;
                 case SOUTH:
                     nextY -= 1;
                     hasWall = horizontal.get(row,col);
                     break;
                 case WEST:
                     nextX -= 1;
                     hasWall = vertical.get(row,col);
                     break;
             }
             
             if(((int)nextX < 0 || nextX >= MazeDefinitions::MAZE_LEN)
                || ((int)nextY < 0 || nextY >= MazeDefinitions::MAZE_LEN))
                 continue;
             
             
             if(!hasWall){
                 if(Distance[nextX][nextY] < shortest)
                     shortest = Distance[nextX][nextY];
                 if(!visited.get(nextY, nextX)){
                     coord n;
                     n.x = nextX;
                     n.y = nextY;
                     coords.push(n);
                 }
             }
         }
         
         if(shortest == infinity || Distance[col][row] == (shortest + 1))
             continue;
         
         Distance[col][row] = shortest + 1;
         
         
         coord n;
         n.x = col;
         n.y = row+1;
         coords.push(n);
         
         n.x = col+1;
         n.y = row;
         coords.push(n);
         
         n.x = col;
         n.y = row-1;
         if(row != 0)
             coords.push(n);
         
         n.x = col-1;
         n.y = row;
         if(col != 0)
             coords.push(n);
         
     }
 }
示例#15
0
    MouseMovement nextMovement(unsigned x, unsigned y, const Maze& maze)
    {
        
        
        coord block;
        block.x = x;
        block.y = y;

        //todo: CREATE IR (so we can tell if there's walls in front or not)
        bool front = maze.wallInFront();
        bool left = maze.wallOnLeft();
        bool right = maze.wallOnRight();
        
        //todo: reverse the goal and reset the values. 
        if(isAtCenter(x, y))
            return Finish;
        
        
        switch(heading)
        {
            case NORTH:
            {
                if(front)
                    horizontal.set(y+1,x);
                if(left)
                    vertical.set(y,x);
                if(right)
                    vertical.set(y,x+1);
                break;
            }
            case EAST:
            {
                if(front)
                    vertical.set(y,x+1);
                if(left)
                    horizontal.set(y+1,x);
                if(right)
                    horizontal.set(y,x);
                break;
            }
            case WEST:
            {
                
                if(front)
                    vertical.set(y,x);
                if(left)
                    horizontal.set(y,x);
                if(right)
                    horizontal.set(y+1,x);
                break;
            }
            case SOUTH:
            {
                if(front)
                    horizontal.set(y,x);
                if(left)
                    vertical.set(y,x+1);
                if(right)
                    vertical.set(y,x);
                break;
            }
            case INVALID:
            //cry
            {
            }
        }
        
        
        if((getDistance(x,y) <= getDistance(x,y+1) || horizontal.get(y+1,x))
           && (getDistance(x,y) <= getDistance(x,y-1) || horizontal.get(y,x))
           && (getDistance(x,y) <= getDistance(x+1,y) || vertical.get(y,x+1))
           && (getDistance(x,y) <= getDistance(x-1,y) || vertical.get(y,x)) ){
            floodFillFinder(block, Distance, horizontal, vertical);
        }
        else if(front && left && right)
            floodFillFinder(block, Distance, horizontal, vertical);
        
        
        if(maze.wallInFront()){
            if(left && right){
                heading = opposite(heading);
                return TurnAround;
            }
            else if(left){
                heading = clockwise(heading);
                return TurnClockwise;
            }
            else{
                heading = counterClockwise(heading);
                return TurnCounterClockwise;
            }
        }
        
        
        if(!coords.get(y,x)){
            coords.set(y,x);
            return MoveForward;
        }
        
        left = maze.wallOnLeft();
        right = maze.wallOnRight();
        unsigned int shortest;
        MouseMovement dir = MoveForward;
        switch(heading){
            case NORTH:
                shortest = Distance[x][y+1];
                if(!left){
                    if(shortest > Distance[x-1][y]){
                        shortest = Distance[x-1][y];
                        heading = counterClockwise(heading);
                        dir = TurnCounterClockwise;
                    }
                }
                if(!right){
                    if(shortest > Distance[x+1][y]){
                        shortest = Distance[x+1][y];
                        heading = clockwise(heading);
                        dir = TurnClockwise;
                    }
                }
                break;
            case EAST:
                shortest = Distance[x+1][y];
                if(!left){
                    if(shortest > Distance[x][y+1]){
                        shortest = Distance[x][y+1];
                        heading = counterClockwise(heading);
                        dir = TurnCounterClockwise;
                    }
                }
                if(!right){
                    if(shortest > Distance[x][y-1]){
                        shortest = Distance[x][y-1];
                        heading = clockwise(heading);
                        dir = TurnClockwise;
                    }
                }
                break;
                
            case WEST:
                shortest = Distance[x-1][y];
                if(!left){
                    if(shortest > Distance[x][y-1]){
                        shortest = Distance[x][y-1];
                        heading = counterClockwise(heading);
                        dir = TurnCounterClockwise;
                    }
                }
                if(!right){
                    if(shortest > Distance[x][y+1]){
                        shortest = Distance[x][y+1];
                        heading = clockwise(heading);
                        dir = TurnClockwise;
                    }
                }
                break;
            case SOUTH:
                shortest = Distance[x][y-1];
                if(!left){
                    if(shortest > Distance[x+1][y]){
                        shortest = Distance[x+1][y];
                        heading = counterClockwise(heading);
                        dir = TurnCounterClockwise;
                    }
                }
                if(!right){
                    if(shortest > Distance[x-1][y]){
                        shortest = Distance[x-1][y];
                        heading = clockwise(heading);
                        dir = TurnClockwise;
                    }
                }
                break;
        }
        
        return dir;
        
    }