Core 1.0
KTope Class Reference

Convex polytopes with fixed normals, also referred to as k-topes. More...

#include <ktope.h>

Public Member Functions

 KTope ()
 Empty.
 KTope (const Vector &)
 Creates a single vertex k-tope.
 KTope (const Box &)
 Creates a k-tope bounding a box.
KTope & operator+= (const Vector &)
 Adds a vertex to the k-tope structure.
Vector Normal (int) const
 Returns the i-th normal of the k-tope.
bool Intersect (const Ray &, double &, double &) const
 Compute the intersection between a k-tope and a ray parametrized by its origin and direction vectors. Sorted intersection depths are returned if intersection occurs.
bool Inside (const Vector &) const
 Check if a point is inside the KTope.
bool Intersect (const KTope &) const
 Check if two k-topes intersect.
KTope operator+ (const KTope &) const
 Computes the bounding k-tope of the union of two k-topes.
KTope Scale (const double &) const
 Scale a k-tope.

Protected Attributes

double c [18] = { 0.0 }
 Array of constants defining the planes.

Detailed Description

Convex polytopes with fixed normals, also referred to as k-topes.

This version implements a 18-polytope, which performs the fastest for a variety of applications. Refer to Klosowki, Efficient collision detection using bounding volumes hierarchies of k-dops, IEEE Transactions on Visualisation and Computer Graphics, 4(1), 1998.

The class stores the offset corresponding to the fixed normal directions.

This class implements some useful functions, such as the intersection between a k-tope and a ray.

Constructor & Destructor Documentation

◆ KTope() [1/2]

KTope::KTope ( const Vector & v)
explicit

Creates a single vertex k-tope.

Parameters
vPoint.

◆ KTope() [2/2]

KTope::KTope ( const Box & box)
explicit

Creates a k-tope bounding a box.

The offsets of the 18 planes are tight: the offset of the plane of normal n is the opposite of the largest value of n.p over the eight vertices of the box, so that the diagonal planes touch the box along its edges. Planes which are not set would pass through the origin.

Parameters
boxThe box.

Member Function Documentation

◆ Inside()

bool KTope::Inside ( const Vector & p) const

Check if a point is inside the KTope.

Parameters
pPoint.

◆ Intersect() [1/2]

bool KTope::Intersect ( const KTope & k) const

Check if two k-topes intersect.

The planes come in pairs with opposite normals: the projection of a k-tope on the direction normals[i+1] is the interval [c[i],-c[i+1]] (for i even), which is the slab defined by the two planes. Two k-topes cannot intersect if the intervals of one of the pairs of planes are disjoint. The k-topes are therefore intersecting if all the intervals overlap, which is a conservative test: it never misses an intersection, but may accept k-topes which are disjoint although none of the slabs separates them.

Parameters
kArgument k-tope.

◆ Intersect() [2/2]

bool KTope::Intersect ( const Ray & ray,
double & tmin,
double & tmax ) const

Compute the intersection between a k-tope and a ray parametrized by its origin and direction vectors. Sorted intersection depths are returned if intersection occurs.

Parameters
rayThe ray.
tmin,tmaxIntersection depths.

◆ operator+()

KTope KTope::operator+ ( const KTope & b) const

Computes the bounding k-tope of the union of two k-topes.

This is not the Minkowski sum: for every plane, the less restrictive coefficient of the two k-topes is kept.

Parameters
bArgument k-topes.

◆ operator+=()

KTope & KTope::operator+= ( const Vector & p)

Adds a vertex to the k-tope structure.

This function does not modify the k-tope if the point lies inside the k-tope, otherwise plane coefficients are updated accordingly.

Parameters
pPoint.

◆ Scale()

KTope KTope::Scale ( const double & a) const

Scale a k-tope.

Parameters
aReal.