Member Function Documentation
QTriangle3D::QTriangle3D()
Constructs a default triangle which lies in the x-z plane, with the three vertices (0, 0, 0), (1, 0, 0), and (0, 1, 0).
QTriangle3D::QTriangle3D(const QVector3D & p, const QVector3D & q, const QVector3D & r)
Constructs a triangle with the supplied p, q and r vertices.
QVector3D QTriangle3D::center() const
Returns the center of the triangle, which is the geometric average of the three vertices.
bool QTriangle3D::contains(const QVector3D & point) const
Returns true if this triangle contains point; false otherwise. To contain the point means that:
- the point lies on the same plane as the triangle, and
- the point
- lies either wholly within the triangle, or
- lies on one of the sides, or
- coincides with one of the 3 vertices
See also intersects().
QVector3D QTriangle3D::faceNormal() const
Returns the vector normal to this triangle, computed from the cross-product of P-Q and Q-R. The result is not normalized.
qreal QTriangle3D::intersection(const QRay3D & ray) const
Returns the t value at which ray intersects this triangle, or not-a-number if there is no intersection.
When the ray intersects this triangle, the return value is a parametric value that can be passed to QRay3D::point() to determine the actual intersection point, as shown in the following example:
qreal t = triangle.intersection(ray);
QVector3D pt;
if (qIsNaN(t)) {
qWarning("no intersection occurred");
else
pt = ray.point(t);
See also intersects(), contains(), and QRay3D::point().
bool QTriangle3D::intersects(const QRay3D & ray) const
Returns true if the ray intersects this triangle; false otherwise.
This function will return false if the triangle is degenerate.
See also contains() and intersection().
QVector3D QTriangle3D::p() const
Returns the value of the P vertex on the triangle.
See also q(), r(), and setP().
QPlane3D QTriangle3D::plane() const
Returns the plane in which the triangle lies.
See also QPlane3D.
QVector3D QTriangle3D::q() const
Returns the value of the Q vertex on the triangle.
See also p(), r(), and setQ().
QVector3D QTriangle3D::r() const
Returns the value of the R vertex on the triangle.
See also p(), q(), and setR().
void QTriangle3D::setP(const QVector3D & point)
Sets the value of the P vertex on the triangle to point.
See also setQ(), setR(), and p().
void QTriangle3D::setQ(const QVector3D & point)
Sets the value of the Q vertex on the triangle point.
See also setP(), setR(), and q().
void QTriangle3D::setR(const QVector3D & point)
Sets the value of the R vertex on the triangle point.
See also setP(), setQ(), and r().
void QTriangle3D::transform(const QMatrix4x4 & matrix)
Transforms the points of this triangle according to matrix.
See also transformed().
QTriangle3D QTriangle3D::transformed(const QMatrix4x4 & matrix) const
Returns a new triangle that results from transforming this one using matrix.
See also transform().
QVector2D QTriangle3D::uv(const QVector3D & point) const
Returns the (u, v) barycentric co-ordinates of point within this triangle.
The returned barycentric co-ordinates will be (1, 0) at p(), (0, 1) at q(), and (0, 0) at r(). Technically, barycentric co-ordinates have three components with the corners at (1, 0, 0), (0, 1, 0), and (0, 0, 1). However, the third component is always equal to (1 - u - v) so we do not return it.
The typical use case for this function is to convert an intersection point on a triangle into the texture co-ordinate corresponding to that point. If p, q, and r are the points on the triangle, with corresponding texture co-ordinates tp, tq, and tr, then the texture co-ordinate tc of point can be determined by the following code:
QTriangle3D triangle(p, q, r);
QVector2D uv = triangle.uv(point);
QVector2D tc = uv.x() * tp + uv.y() * tq + (1 - uv.x() - uv.y()) * tr;
See also contains() and intersection().
bool QTriangle3D::operator!=(const QTriangle3D & other)
Returns true if this triangle is not the same as other; false otherwise.
See also operator==().
bool QTriangle3D::operator==(const QTriangle3D & other)
Returns true if this triangle is the same as other; false otherwise.
See also operator!=().