Simbody  3.5
SimTK::Geo::Triangle_< P > Class Template Reference

A geometric primitive representing a triangle by its vertices as points in some unspecified frame, and a collection of triangle-related utility methods. More...

Public Member Functions

 Triangle_ ()
 Construct an uninitialized Triangle object; the vertices will be garbage. More...
 
 Triangle_ (const Vec3P &v0, const Vec3P &v1, const Vec3P &v2)
 Construct a triangle from its vertices. More...
 
 Triangle_ (const Vec3P *vertices)
 Construct a triangle from vertices stored in array which is presumed to contain at least three points. More...
 
 Triangle_ (const Vec3P **vertexPointers)
 Construct a triangle from an indirect list of vertices stored in array which is presumed to contain at least three pointers to points. More...
 
Triangle_setVertex (int i, const Vec3P &p)
 Change one vertex of this triangle. More...
 
Triangle_setVertices (const Vec3P &v0, const Vec3P &v1, const Vec3P &v2)
 Change the vertices of this triangle. More...
 
Triangle_setVertices (const Vec3P *vertices)
 Change the vertices of this triangle, taking the new ones from an array which is presumed to contain at least three points. More...
 
const Vec3PgetVertex (int i) const
 Access a vertex by index. Order is the same as construction. More...
 
Vec3PupdVertex (int i)
 Get writable access to a vertex by index. Order is the same as construction. More...
 
const Vec3Poperator[] (int i) const
 Access a vertex by indexing the triangle. More...
 
Vec3Poperator[] (int i)
 Get writable access to a vertex by indexing the triangle. More...
 
LineSeg_< P > getEdge (int i) const
 Return a LineSeg_ containing an edge of this triangle, with edges numbered in a counterclockwise direction so that edge0 is v0v1, edge1 is v1v2, and edge2 is v2v0. More...
 
Vec3P findPoint (const Vec2P &uv) const
 Return a point on the triangle's face given by its (u,v) coordinates. More...
 
Vec3P findCentroid () const
 Return the centroid point on the triangle's face; this is the same as findPoint(1/3,1/3) but faster. More...
 
UnitVec3P calcUnitNormal () const
 Calculate the unit normal to the triangle face taking the vertices in counterclockwise order. More...
 
Sphere_< P > calcBoundingSphere () const
 Calculate the smallest bounding sphere enclosing the three vertices of this triangle. More...
 
RealP calcArea () const
 Return the area of this triangle. More...
 
RealP calcAreaSqr () const
 Return the square of the area of this triangle. More...
 
Vec3P findNearestPoint (const Vec3P &position, Vec2P &uv) const
 Given a location in space, find the point of this triangular face that is closest to that location. More...
 
bool intersectsRay (const Vec3P &origin, const UnitVec3P &direction, RealP &distance, Vec2P &uv) const
 Determine whether a given ray intersects this triangle. More...
 
bool overlapsTriangle (const Triangle_< P > &other) const
 Determine yes/no whether this triangle overlaps another one. More...
 
bool intersectsTriangle (const Triangle_< P > &other, LineSeg_< P > &seg, bool &isCoplanar) const
 Determine whether this triangle intersects another one, and if so then if they are not coplanar return the line segment representing their intersection. More...
 

Detailed Description

template<class P>
class SimTK::Geo::Triangle_< P >

A geometric primitive representing a triangle by its vertices as points in some unspecified frame, and a collection of triangle-related utility methods.

We support a u-v barycentric parameterization for the triangle.

Constructor & Destructor Documentation

template<class P>
SimTK::Geo::Triangle_< P >::Triangle_ ( )
inline

Construct an uninitialized Triangle object; the vertices will be garbage.

template<class P>
SimTK::Geo::Triangle_< P >::Triangle_ ( const Vec3P v0,
const Vec3P v1,
const Vec3P v2 
)
inline

Construct a triangle from its vertices.

template<class P>
SimTK::Geo::Triangle_< P >::Triangle_ ( const Vec3P vertices)
inlineexplicit

Construct a triangle from vertices stored in array which is presumed to contain at least three points.

template<class P>
SimTK::Geo::Triangle_< P >::Triangle_ ( const Vec3P **  vertexPointers)
inlineexplicit

Construct a triangle from an indirect list of vertices stored in array which is presumed to contain at least three pointers to points.

Member Function Documentation

template<class P>
Triangle_& SimTK::Geo::Triangle_< P >::setVertex ( int  i,
const Vec3P p 
)
inline

Change one vertex of this triangle.

template<class P>
Triangle_& SimTK::Geo::Triangle_< P >::setVertices ( const Vec3P v0,
const Vec3P v1,
const Vec3P v2 
)
inline

Change the vertices of this triangle.

template<class P>
Triangle_& SimTK::Geo::Triangle_< P >::setVertices ( const Vec3P vertices)
inline

Change the vertices of this triangle, taking the new ones from an array which is presumed to contain at least three points.

template<class P>
const Vec3P& SimTK::Geo::Triangle_< P >::getVertex ( int  i) const
inline

Access a vertex by index. Order is the same as construction.

You can use operator[] instead for a more compact notation.

template<class P>
Vec3P& SimTK::Geo::Triangle_< P >::updVertex ( int  i)
inline

Get writable access to a vertex by index. Order is the same as construction.

You can use operator[] instead for a more compact notation.

template<class P>
const Vec3P& SimTK::Geo::Triangle_< P >::operator[] ( int  i) const
inline

Access a vertex by indexing the triangle.

template<class P>
Vec3P& SimTK::Geo::Triangle_< P >::operator[] ( int  i)
inline

Get writable access to a vertex by indexing the triangle.

template<class P>
LineSeg_<P> SimTK::Geo::Triangle_< P >::getEdge ( int  i) const
inline

Return a LineSeg_ containing an edge of this triangle, with edges numbered in a counterclockwise direction so that edge0 is v0v1, edge1 is v1v2, and edge2 is v2v0.

template<class P>
Vec3P SimTK::Geo::Triangle_< P >::findPoint ( const Vec2P uv) const
inline

Return a point on the triangle's face given by its (u,v) coordinates.

Cost is 17 flops.

template<class P>
Vec3P SimTK::Geo::Triangle_< P >::findCentroid ( ) const
inline

Return the centroid point on the triangle's face; this is the same as findPoint(1/3,1/3) but faster.

Cost is 9 flops.

template<class P>
UnitVec3P SimTK::Geo::Triangle_< P >::calcUnitNormal ( ) const
inline

Calculate the unit normal to the triangle face taking the vertices in counterclockwise order.

Cost is about 50 flops.

template<class P>
Sphere_<P> SimTK::Geo::Triangle_< P >::calcBoundingSphere ( ) const
inline

Calculate the smallest bounding sphere enclosing the three vertices of this triangle.

We guarantee that no vertex is outside the sphere, but for numerical reasons it is possible for the sphere to be a little too big.

template<class P>
RealP SimTK::Geo::Triangle_< P >::calcArea ( ) const
inline

Return the area of this triangle.

Cost is about 40 flops.

template<class P>
RealP SimTK::Geo::Triangle_< P >::calcAreaSqr ( ) const
inline

Return the square of the area of this triangle.

Cost is 23 flops.

template<class P>
Vec3P SimTK::Geo::Triangle_< P >::findNearestPoint ( const Vec3P position,
Vec2P uv 
) const
inline

Given a location in space, find the point of this triangular face that is closest to that location.

If the answer is not unique then one of the equidistant points is returned.

template<class P>
bool SimTK::Geo::Triangle_< P >::intersectsRay ( const Vec3P origin,
const UnitVec3P direction,
RealP &  distance,
Vec2P uv 
) const
inline

Determine whether a given ray intersects this triangle.

TODO: is a perfect hit on the boundary an intersection?

template<class P>
bool SimTK::Geo::Triangle_< P >::overlapsTriangle ( const Triangle_< P > &  other) const

Determine yes/no whether this triangle overlaps another one.

Note that exactly touching is not overlapping.

template<class P>
bool SimTK::Geo::Triangle_< P >::intersectsTriangle ( const Triangle_< P > &  other,
LineSeg_< P > &  seg,
bool &  isCoplanar 
) const

Determine whether this triangle intersects another one, and if so then if they are not coplanar return the line segment representing their intersection.

If the triangles are coplanar and intersect we'll return true and set isCoplanar true, but not return a line segment. Note that the triangles may meet at a point so the line segment may be degenerate in any case.


The documentation for this class was generated from the following files: