1 #ifndef SimTK_SIMMATH_GEO_TRIANGLE_H_ 2 #define SimTK_SIMMATH_GEO_TRIANGLE_H_ 49 class Geo::Triangle_ {
51 typedef Vec<2,P> Vec2P;
52 typedef Vec<3,P> Vec3P;
53 typedef UnitVec<P,1> UnitVec3P;
68 {
setVertices(*vertexPointers[0], *vertexPointers[1], *vertexPointers[2]); }
72 { assert(0<=i && i<3); v[i] = p;
return *
this; }
75 { v[0]=v0; v[1]=v1; v[2]=v2;
return *
this; }
79 { v[0]=vertices[0]; v[1]=vertices[1]; v[2]=vertices[2];
return *
this; }
107 {
return uv[0]*v[0] + uv[1]*v[1] + (1-uv[0]-uv[1])*v[2]; }
112 {
return (v[0]+v[1]+v[2]) / RealP(3); }
117 {
return UnitVec3P((v[1]-v[0]) % (v[2]-v[0])); }
127 {
return ((v[1]-v[0]) % (v[2]-v[0])).norm() / 2; }
131 {
return ((v[1]-v[0]) % (v[2]-v[0])).normSqr() / 4; }
138 "Geo::Triangle_::findNearestPoint(): Not implemented yet.");
144 RealP& distance,
Vec2P& uv)
const 146 "Geo::Triangle_::intersectsRay(): Not implemented yet.");
return false;}
158 bool& isCoplanar)
const;
173 #endif // SimTK_SIMMATH_GEO_TRIANGLE_H_ Vec3P findPoint(const Vec2P &uv) const
Return a point on the triangle's face given by its (u,v) coordinates.
Definition: Geo_Triangle.h:106
A geometric primitive representing a triangle by its vertices as points in some unspecified frame...
Definition: Geo.h:64
const Vec3P & operator[](int i) const
Access a vertex by indexing the triangle.
Definition: Geo_Triangle.h:93
Triangle_ & setVertex(int i, const Vec3P &p)
Change one vertex of this triangle.
Definition: Geo_Triangle.h:71
Sphere_< P > calcBoundingSphere() const
Calculate the smallest bounding sphere enclosing the three vertices of this triangle.
Definition: Geo_Triangle.h:122
Triangle_ & setVertices(const Vec3P &v0, const Vec3P &v1, const Vec3P &v2)
Change the vertices of this triangle.
Definition: Geo_Triangle.h:74
UnitVec3P calcUnitNormal() const
Calculate the unit normal to the triangle face taking the vertices in counterclockwise order...
Definition: Geo_Triangle.h:116
Triangle_()
Construct an uninitialized Triangle object; the vertices will be garbage.
Definition: Geo_Triangle.h:57
This class is a Vec3 plus an ironclad guarantee either that:
Definition: UnitVec.h:40
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
#define SimTK_ASSERT_ALWAYS(cond, msg)
Definition: ExceptionMacros.h:349
Vec3P & operator[](int i)
Get writable access to a vertex by indexing the triangle.
Definition: Geo_Triangle.h:95
Triangle_(const Vec3P &v0, const Vec3P &v1, const Vec3P &v2)
Construct a triangle from its vertices.
Definition: Geo_Triangle.h:59
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...
Definition: Geo_Triangle.h:136
Includes internal headers providing declarations for the basic SimTK Core classes, including Simmatrix.
Defines geometric primitive shapes and algorthms.
A 3d line segment primitive represented by its end points in an unspecified frame, and a collection of line segment-related utility methods.
Definition: Geo.h:57
Vec3P & updVertex(int i)
Get writable access to a vertex by index. Order is the same as construction.
Definition: Geo_Triangle.h:88
Collects primitive operations involving line segments.
bool intersectsRay(const Vec3P &origin, const UnitVec3P &direction, RealP &distance, Vec2P &uv) const
Determine whether a given ray intersects this triangle.
Definition: Geo_Triangle.h:143
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 retur...
This is the header file that every Simmath compilation unit should include first. ...
RealP calcArea() const
Return the area of this triangle.
Definition: Geo_Triangle.h:126
Triangle_(const Vec3P *vertices)
Construct a triangle from vertices stored in array which is presumed to contain at least three points...
Definition: Geo_Triangle.h:63
Defines primitive computations involving points.
Triangle_ & setVertices(const Vec3P *vertices)
Change the vertices of this triangle, taking the new ones from an array which is presumed to contain ...
Definition: Geo_Triangle.h:78
#define SimTK_INDEXCHECK(ix, ub, where)
Definition: ExceptionMacros.h:145
A geometric primitive representing a sphere by its radius and center point, and a collection of spher...
Definition: Geo.h:56
Vec3P findCentroid() const
Return the centroid point on the triangle's face; this is the same as findPoint(1/3,1/3) but faster.
Definition: Geo_Triangle.h:111
const Vec3P & getVertex(int i) const
Access a vertex by index. Order is the same as construction.
Definition: Geo_Triangle.h:83
LineSeg_< P > getEdge(int i) const
Return a LineSeg_ containing an edge of this triangle, with edges numbered in a counterclockwise dire...
Definition: Geo_Triangle.h:100
Triangle_(const Vec3P **vertexPointers)
Construct a triangle from an indirect list of vertices stored in array which is presumed to contain a...
Definition: Geo_Triangle.h:67
#define SimTK_SIMMATH_EXPORT
Definition: SimTKmath/include/simmath/internal/common.h:64
bool overlapsTriangle(const Triangle_< P > &other) const
Determine yes/no whether this triangle overlaps another one.
RealP calcAreaSqr() const
Return the square of the area of this triangle.
Definition: Geo_Triangle.h:130
static Sphere_< P > calcBoundingSphere(const Vec3P &p)
Create a tiny bounding sphere around a single point.
Definition: Geo_Point.h:333