Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QTriangle3D Class

The QTriangle3D class represents a triangle as three points in 3D space. More...

 #include <QTriangle3D>

This class was introduced in Qt 4.8.

Public Functions

QTriangle3D()
QTriangle3D(const QVector3D & p, const QVector3D & q, const QVector3D & r)
QVector3D center() const
bool contains(const QVector3D & point) const
QVector3D faceNormal() const
qreal intersection(const QRay3D & ray) const
bool intersects(const QRay3D & ray) const
QVector3D p() const
QPlane3D plane() const
QVector3D q() const
QVector3D r() const
void setP(const QVector3D & point)
void setQ(const QVector3D & point)
void setR(const QVector3D & point)
void transform(const QMatrix4x4 & matrix)
QTriangle3D transformed(const QMatrix4x4 & matrix) const
QVector2D uv(const QVector3D & point) const
bool operator!=(const QTriangle3D & other)
bool operator==(const QTriangle3D & other)

Related Non-Members

bool qFuzzyCompare(const QTriangle3D & triangle1, const QTriangle3D & triangle2)

Detailed Description

The QTriangle3D class represents a triangle as three points in 3D space.

A triangle is defined by 3 points in 3D space. Since any 3 points define a plane, the triangle can be thought of as defining a plane, and forming a geometric region in that plane.

If you need a simple plane, with no particular geometry, then QPlane3D is a more compact and mathematically sufficient class.

The three points are labelled p(), q() and r() for consistency with textbook treatments. It is recommended that the points be supplied in counter-clockwise order for correct orientation of the triangle's plane().

See also QPlane3D.

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!=().

Related Non-Members

bool qFuzzyCompare(const QTriangle3D & triangle1, const QTriangle3D & triangle2)

Returns true if triangle1 and triangle2 are almost equal; false otherwise.

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web