Example #1
0
int inLine(float *p, float x1, float y1, float x2, float y2)
{
	float d[3];
	d[0] = distanceTwoPoints(x1, y1, x2, y2);
	d[1] = distanceTwoPoints(p[0], p[1], x1, y1);
	d[2] = distanceTwoPoints(p[0], p[1], x2, y2);
	
	return ((d[1]+d[2])-d[0] <= IMPRECISION);
}
Example #2
0
double findMinDis(double Mx, double My, double a, double b, double xLeft, double xRight) {

	int i;
	double left = xLeft;
	double right = xRight;
	double x1, x2;
	double y1, y2;
	double distanceLeft, distanceRight;
	double distance;

	distanceLeft = distanceTwoPoints(left, a * left + b, Mx, My);
	distanceRight = distanceTwoPoints(right, a * right + b, Mx, My);

	distance = distanceLeft > distanceRight ? distanceRight : distanceLeft;

	for (i = 0; i < 1000; i++) {

		x1 = left + (right - left) / 3;
		x2 = right - (right - left) / 3;

		if (x1 > x2) {
			break;
		}

		y1 = a * x1 + b;
		y2 = a * x2 + b;

		distanceLeft = distanceTwoPoints(x1, y1, Mx, My);
		distanceRight = distanceTwoPoints(x2, y2, Mx, My);

		if (distanceLeft > distanceRight) {
			if (distance > distanceRight) {
				distance = distanceRight;
			}
			left = x1;

		} else {
			right = x2;
			if (distance > distanceLeft) {
				distance = distanceLeft;
			}
		}
	}

	return distance;
}
Example #3
0
double findMinDisVertical(double x, double inY1, double inY2, double Mx, double My) {

	int i;
	double left = inY1;
	double right = inY2;
	double y1, y2;
	double distanceLeft, distanceRight;
	double distance;

	distanceLeft = distanceTwoPoints(x, left, Mx, My);
	distanceRight = distanceTwoPoints(x, right, Mx, My);

	distance = distanceLeft > distanceRight ? distanceRight : distanceLeft;

	for (i = 0; i < 1000; i++) {

		y1 = left + 0.333 * (right - left);
		y2 = right - 0.333 * (right - left);

		distanceLeft = distanceTwoPoints(x, y1, Mx, My);
		distanceRight = distanceTwoPoints(x, y2, Mx, My);

		if (distanceLeft > distanceRight) {
			if (distance > distanceRight) {
				distance = distanceRight;
			}
			left = y1;
		} else {
			right = y2;
			if (distance > distanceLeft) {
				distance = distanceLeft;
			} 
		}
	}

	return distance;
}