Member Function Documentation
QSphere3D::QSphere3D()
Constructs a default sphere with a center() of (0, 0, 0) and radius() of 1.
QSphere3D::QSphere3D(const QVector3D & center, qreal radius)
Constructs a sphere with the specified center and radius.
QVector3D QSphere3D::center() const
Returns the center of this sphere.
See also setCenter() and radius().
bool QSphere3D::contains(const QVector3D & point) const
Returns true if point is contained within the bounds of this sphere; false otherwise.
bool QSphere3D::intersection(const QRay3D & ray, qreal * minimum_t, qreal * maximum_t) const
Finds the minimum_t and maximum_t values where ray intersects this sphere. Returns true if intersections were found; or false if there is no intersection.
If minimum_t and maximum_t are set to the same value, then ray touches the surface of the sphere at a single point. If the t values are negative, then the intersection occurs before the ray's origin point in the reverse direction of the ray.
The minimum_t and maximum_t values can be passed to QRay3D::point() to determine the actual intersection points, as shown in the following example:
qreal minimum_t, maximum_t;
if (sphere.intersection(ray, &minimum_t, &maximum_t)) {
qDebug() << "intersections at"
<< ray.point(minimum_t) << "and"
<< ray.point(maximum_t);
}
See also intersects() and QRay3D::point().
qreal QSphere3D::intersection(const QRay3D & ray) const
Returns the t value at which ray first intersects the surface of this sphere, or not-a-number if there is no intersection.
When the ray intersects this sphere, 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 = sphere.intersection(ray);
QVector3D pt;
if (qIsNaN(t)) {
qWarning("no intersection occurred");
else
pt = ray.point(t);
The ray might intersect at two points - as the ray passes through the sphere - one on the near side, one on the far side; where near and far are relative to the origin point of the ray. This function only returns the near intersection point.
Only positive values on the ray are considered. This means that if the origin point of the ray is inside the sphere, there is only one solution, not two. To get the other solution, simply change the sign of the ray's direction vector. If the origin point of the ray is outside the sphere, and the direction points away from the sphere, then there will be no intersection.
When the ray does not intersect the sphere in the positive direction, then the return value is not-a-number.
See also intersects() and QRay3D::point().
bool QSphere3D::intersects(const QRay3D & ray) const
Returns true if this sphere intersects ray; false otherwise.
See also intersection().
bool QSphere3D::intersects(const QSphere3D & sphere) const
Returns true if this sphere intersects sphere; false otherwise.
See also contains().
bool QSphere3D::intersects(const QBox3D & box) const
Returns true if this sphere intersects box; false otherwise.
bool QSphere3D::intersects(const QPlane3D & plane) const
Returns true if this sphere intersects plane; false otherwise.
qreal QSphere3D::radius() const
Returns the radius of this sphere.
See also setRadius() and center().
void QSphere3D::setCenter(const QVector3D & center)
Sets the center of this sphere.
See also center() and setRadius().
void QSphere3D::setRadius(qreal radius)
Sets the radius of this sphere.
See also radius() and setCenter().
void QSphere3D::transform(const QMatrix4x4 & matrix)
Transforms this sphere's center() and radius() according to matrix.
It is assumed that matrix contains a uniform scale factor in the x, y, and z directions. Otherwise the radius() in the result is undefined.
See also transformed().
QSphere3D QSphere3D::transformed(const QMatrix4x4 & matrix) const
Returns the result of transforming this sphere's center() and radius() according to matrix.
It is assumed that matrix contains a uniform scale factor in the x, y, and z directions. Otherwise the radius() in the result is undefined.
See also transform().
bool QSphere3D::operator!=(const QSphere3D & sphere) const
Returns true if this sphere is not the same as sphere; false otherwise.
See also operator==().
bool QSphere3D::operator==(const QSphere3D & sphere) const
Returns true if this sphere is the same as sphere; false otherwise.
See also operator!=().