示例#1
0
	void realign::realignPeriodically()
	{


		vector <baseType> along(vl->size());
				baseType timeFirstRun;
			  in >> timeFirstRun;
		//		cout << "timeFirstRun: " << timeFirstRun << endl;
		//		cout << "time: " << dynNode::time << endl;

		for (unsigned int i = 0; i < vl->size(); i++ )
			in >>along[i];

		meanVar dist = calculateDist(along);
		if (counter==skip)
		{
			counter = 0;
			out << dynNode::time << " " << setprecision(20) << dist.mean << " " << sqrt(dist.var) << endl;
			cout << "vorher:" << setprecision(20) << dist.mean << " " << sqrt(dist.var) << endl;
			realignNow(along, eps, dist);
			meanVar newDist = calculateDist(along);
			cout << "nachher:" << setprecision(20) << newDist.mean << " " << sqrt(newDist.var) << endl;
		}
		else
		{
			counter++;
			out << "#" << setprecision(20) << dynNode::time <<  " " << dist.mean << " " << sqrt(dist.var) << endl;

		}

	}
void SDFRenderer::CreateSDF(bool* data) {

	// check if required values are set
	if (width == 0) {
		return;
	}

	if (height == 0) {
		return;
	}

	// allocate distance buffer
	if (distances == nullptr) {
		distances = new float[width * height];
	} else {
		// check dimensions of current buffer
		if (allocatedWidth != width || allocatedHeight != height) {
			delete[] distances;
			distances = new float[width * height];
		}
	}

	allocatedWidth = width;
	allocatedHeight = height;

	// do the magic
	calculateDist(data);
	clampDist();
}
示例#3
0
inline double ColorEdge::calcDistToOtherVector(std::vector<VecDist> &vec, int num)
{
    double value = 0.0;
    for(int i = 0; i < vec.size(); ++i)
    {
        if(num != i)
        {
            value += calculateDist(vec[i].first, vec[num].first);
        }
    }

    return value;
}
bool instructionToCommands(int startX, int startY, int degree, int endX, int endY, char**** commands)
{
	printf("\nEntered instuctionToCommands! Parameters are:\n");
	printf("startX: %d, startY: %d, degree: %d, endX: %d, endY: %d\n", startX, startY, degree, endX, endY);

	bool result = false;
	
	//Allocate the 2-D array of strings
	*commands = malloc(MAX_COMMANDS * sizeof(char**));
	int m, n;
	for (m = 0; m < MAX_COMMANDS; m++) 
	{
		(*commands)[m] = malloc(3 * sizeof(char*));
		for (n = 0; n < 3; n++)
		{
			(*commands)[m][n] = malloc(INSTRUCTION_SIZE * sizeof(char));
            strcpy((*commands)[m][n], "END0");
		}
	}
	
	printf("MAX_COMMANDS: %d\n", MAX_COMMANDS);
	
//Turning Phase
	int turningAngle = calculateTurn(startX, startY, endX, endY, degree);
	printf("The turn angle is: %d\n", turningAngle);
	
	//Convert -180 to 180 scale turn value to an absolute value + a direction
	int direction = 0;
	if (turningAngle > 0) direction = 1;
	turningAngle = abs(turningAngle);
	
	//Calculate how long the turning phase lasts
	int time = round((turningAngle/15) * INTERVAL_15);
	if (10 > time) time = 10;
	
	//Add instruction: Turn sensitivity MAX, speed 32, time milliseconds
	if (1 == direction) strcpy((*commands)[0][0], "81 3f");		//Right turn
	else strcpy((*commands)[0][0], "81 40");						//Left turn
	strcpy((*commands)[0][1], "82 1f");
	sprintf((*commands)[0][2], "%d", time);
	
//Linear Phase
	int distance = calculateDist(startX, startY, endX, endY);
	printf("Distance = %d\n", distance);
	
	//Add instruction: Turn sensitivity 0, SPEED, distance*10 milliseconds
	//We're assuming here that it takes 10 milliseconds to travel 1 unit (it probably doesn't)
	int trueDist = distance*10;

	//This shouldn't happen (and thus we'd probably need to recalibrate the speed, as its taking >10 seconds for one movement command)
	if (9999 < trueDist) trueDist = 9000;
	
	strcpy((*commands)[1][0], "81 00");
	strcpy((*commands)[1][1], "82 1f");
	sprintf((*commands)[1][2], "%d", trueDist % 9999);
	
	if (NULL != (*commands)) result = true;
	
	printf("Exiting instructionToCommands!\n");
	return result;
}