コード例 #1
0
void ofxGrahamsScan::scan(LinkedPoint *linkedPoint)
{
    LinkedPoint *tempPrev, *tempNext;
    
    if (linkedPoint==firstPoint) //IF RETURNED TO FIRST POINT, DONE
        return;
    
    if (!isConvexPoint(linkedPoint)) //IF POINT IS CONCAVE, ELIMINATE FROM PERIMETER
    {
        tempPrev=linkedPoint->prev; 
        tempNext=linkedPoint->next;
        tempPrev->next=tempNext;
        tempNext->prev=tempPrev;
		// drawLine(tempPrev, tempNext,3); //DRAW LINE SHOWING NEW EDGE
        delete linkedPoint; //FREE MEMORY
        scan(tempPrev); //RUN GRAHAM'S SCAN ON PREVIOUS POINT TO CHECK IF CONVEXITY HAS CHANGED IT
		
    } 
	else //POINT IS CONVEX
	{
		scan(linkedPoint->next); //PROCEED TO NEXT POINT
	}
}
コード例 #2
0
ファイル: convexhullM.c プロジェクト: merlintang/sgb
/**
 *remove the no convex points when the new point is comming
 */
void unionConvex(convexhull *convex, tuple *newpoint, int eps) {

	if (convex == NULL ) {
		return;
	}

	if (convex->numofconvex == 0) {
		convex->convexheader = newpoint;
		convex->convexheader->next = NULL;
		convex->numofconvex++;
		return;

	} else if (convex->numofconvex == 1) {

		convex->convexheader->next = newpoint;
		newpoint->next = convex->convexheader;
		convex->numofconvex++;
		return;

	} else if (convex->numofconvex == 2) {
		tuple *tmp = convex->convexheader->next;
		tmp->next = newpoint;
		newpoint->next = convex->convexheader;
		convex->numofconvex++;
		return;

	} else {
		int i = 0;
		tuple *header = convex->convexheader;
		tuple *current = header->next;
		tuple *previous = header;
		tuple *beginpoint = current;
		tuple *tangleOne = NULL;
		tuple *tangleTwo = NULL;
		bool firstone = false;
		bool secondone = false;

		bool shouldchangeTangle = false;

		while (i <= convex->numofconvex) {

			tuple *nextone = current->next;

			//print_onetuple(current);

			if (nextone == NULL || previous == NULL )
				break;

			if (isTangentPoint(newpoint, previous, current, nextone)) {
				if (firstone == false ) {

					tangleOne = current;
					firstone = true;

				} else {

					if (current != tangleOne) {
						tangleTwo = current;
						secondone = true;
					}

				}
			} else if (firstone == true && secondone == false ) {
				if (isConvexPoint(newpoint, previous, current, nextone)) {
					shouldchangeTangle = true;
				}
			}

			previous = current;
			current = current->next;

			/*if(current==beginpoint)
			 break;*/

			i++;
		}

		int lostnumber = 0;
		if (tangleTwo != NULL && tangleOne != NULL ) {
			//int value=crossproduct(newpoint, tangleOne, tangleTwo);
			//printf("inner product value %d \n", value);

			//printf("tangle point one: ");
			//print_onetuple(tangleOne);

			//printf("tangle point two: ");
			//print_onetuple(tangleTwo);

			//printf("should change %d \n", shouldchangeTangle);
			if (shouldchangeTangle) {
				tuple *tmp = tangleTwo;
				tangleTwo = tangleOne;
				tangleOne = tmp;
			}

			lostnumber = delete_from_to_connect(convex, tangleOne, tangleTwo,newpoint);
			convex->numofconvex = convex->numofconvex - lostnumber + 1;

		} else {
			//printf("problem \n");
		}

	}

}