Exemplo n.º 1
0
Vector2 closestPointOnTriangle(Vector2 p, Vector2 v[3]) {

	if (pointInTriangle(p, v))
		return p;

	float maxDist = 10000.f;
	Vector2 closest;

	for (int i = 0; i < 3; ++i)
	{
		Vector2 temp = closestPointOnSegment(p, v[i], v[(i + 1) % 3]);
		float dist = (temp - p).lengthSq();

		if (dist < maxDist)
		{
			maxDist = dist;
			closest = temp;
		}

	}
	return closest;
}
Exemplo n.º 2
0
qreal distanceToSegment(const QVector3D& pt, const QVector3D& from, const QVector3D& to)
{
    return (closestPointOnSegment(pt, from, to) - pt).length();
}