Enumerations | Functions
vgl_triangle_3d.h File Reference

Some helpful functions when working with triangles. More...

#include <algorithm>
#include <utility>
#include <cmath>
#include <vgl/vgl_line_segment_3d.h>
#include <vgl/vgl_point_3d.h>

Go to the source code of this file.

Enumerations

enum  vgl_triangle_3d_intersection_t { None =0, Skew, Coplanar }
 

Functions

std::vector< std::pair< unsigned, unsigned > > vgl_triangle_3d_coincident_edges (const vgl_point_3d< double > &a_p1, const vgl_point_3d< double > &a_p2, const vgl_point_3d< double > &a_p3, const vgl_point_3d< double > &b_p1, const vgl_point_3d< double > &b_p2, const vgl_point_3d< double > &b_p3)
 Check for coincident edges of triangles a and b. More...
 
bool vgl_triangle_3d_test_inside (const vgl_point_3d< double > &i_pnt, const vgl_point_3d< double > &p1, const vgl_point_3d< double > &p2, const vgl_point_3d< double > &p3)
 Check if the given point is inside the triangle. More...
 
bool vgl_triangle_3d_test_inside (const vgl_point_3d< double > &i_pnt, const vgl_point_3d< double > &p1, const vgl_point_3d< double > &p2, const vgl_point_3d< double > &p3, double coplanar_tolerance)
 Check if the given point is inside the triangle. More...
 
bool vgl_triangle_3d_test_inside_simple (const vgl_point_3d< double > &i_pnt, const vgl_point_3d< double > &p1, const vgl_point_3d< double > &p2, const vgl_point_3d< double > &p3)
 Check if point i_pnt is inside the triangle. More...
 
vgl_triangle_3d_intersection_t vgl_triangle_3d_line_intersection (const vgl_line_segment_3d< double > &line, const vgl_point_3d< double > &p1, const vgl_point_3d< double > &p2, const vgl_point_3d< double > &p3, vgl_point_3d< double > &i_pnt, bool ignore_coplanar=false)
 Compute the intersection point between the line segment and triangle. More...
 
vgl_triangle_3d_intersection_t vgl_triangle_3d_triangle_intersection (const vgl_point_3d< double > &a_p1, const vgl_point_3d< double > &a_p2, const vgl_point_3d< double > &a_p3, const vgl_point_3d< double > &b_p1, const vgl_point_3d< double > &b_p2, const vgl_point_3d< double > &b_p3)
 Compute if the given triangles a and b intersect. More...
 
vgl_triangle_3d_intersection_t vgl_triangle_3d_triangle_intersection (const vgl_point_3d< double > &a_p1, const vgl_point_3d< double > &a_p2, const vgl_point_3d< double > &a_p3, const vgl_point_3d< double > &b_p1, const vgl_point_3d< double > &b_p2, const vgl_point_3d< double > &b_p3, vgl_line_segment_3d< double > &i_line)
 Compute the intersection line of the given triangles. More...
 
vgl_triangle_3d_intersection_t vgl_triangle_3d_triangle_intersection (const vgl_point_3d< double > &a_p1, const vgl_point_3d< double > &a_p2, const vgl_point_3d< double > &a_p3, const vgl_point_3d< double > &b_p1, const vgl_point_3d< double > &b_p2, const vgl_point_3d< double > &b_p3, vgl_line_segment_3d< double > &i_line, unsigned &i_line_point1_edge, unsigned &i_line_point2_edge)
 compute the intersection line of the given triangles. More...
 
vgl_triangle_3d_intersection_t vgl_triangle_3d_plane_intersection (const vgl_point_3d< double > &p1, const vgl_point_3d< double > &p2, const vgl_point_3d< double > &p3, const vgl_plane_3d< double > &i_plane, vgl_line_segment_3d< double > &i_line)
 Compute the line of intersection of the given triangle and plane. More...
 
double vgl_triangle_3d_longest_side (const vgl_point_3d< double > &p1, const vgl_point_3d< double > &p2, const vgl_point_3d< double > &p3)
 Compute the longest side of the given triangle. More...
 
double vgl_triangle_3d_shortest_side (const vgl_point_3d< double > &p1, const vgl_point_3d< double > &p2, const vgl_point_3d< double > &p3)
 Compute the shortest side of the given triangle. More...
 
vgl_point_3d< double > vgl_triangle_3d_closest_point (const vgl_point_3d< double > &q, const vgl_point_3d< double > &p1, const vgl_point_3d< double > &p2, const vgl_point_3d< double > &p3)
 Compute the closest point on a triangle to a reference point. More...
 
double vgl_triangle_3d_distance (const vgl_point_3d< double > &q, const vgl_point_3d< double > &p1, const vgl_point_3d< double > &p2, const vgl_point_3d< double > &p3)
 Compute the distance to the closest point on a triangle from a reference point. More...
 
bool vgl_triangle_3d_triangle_coplanar (const vgl_point_3d< double > &a_p1, const vgl_point_3d< double > &a_p2, const vgl_point_3d< double > &a_p3, const vgl_point_3d< double > &b_p1, const vgl_point_3d< double > &b_p2, const vgl_point_3d< double > &b_p3)
 Check if the two triangles are coplanar. More...
 
double vgl_triangle_3d_area (const vgl_point_3d< double > &p0, const vgl_point_3d< double > &p1, const vgl_point_3d< double > &p2)
 Compute the area of a triangle. More...
 
double vgl_triangle_3d_aspect_ratio (const vgl_point_3d< double > &p0, const vgl_point_3d< double > &p1, const vgl_point_3d< double > &p2)
 Compute the aspect ratio of a triangle. More...
 

Detailed Description

Some helpful functions when working with triangles.

Author
Kieran O'Mahony
Date
21 June 2007

Definition in file vgl_triangle_3d.h.

Enumeration Type Documentation

◆ vgl_triangle_3d_intersection_t

Enumerator
None 
Skew 
Coplanar 

Definition at line 19 of file vgl_triangle_3d.h.

Function Documentation

◆ vgl_triangle_3d_area()

double vgl_triangle_3d_area ( const vgl_point_3d< double > &  p0,
const vgl_point_3d< double > &  p1,
const vgl_point_3d< double > &  p2 
)

Compute the area of a triangle.

The triangle is represented by its vertices p1, p2, p3

Definition at line 1541 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_aspect_ratio()

double vgl_triangle_3d_aspect_ratio ( const vgl_point_3d< double > &  p0,
const vgl_point_3d< double > &  p1,
const vgl_point_3d< double > &  p2 
)

Compute the aspect ratio of a triangle.

The triangle is represented by its vertices p1, p2, p3

Compute the aspect ratio of a triangle.

The triangle is represented by its vertices p1, p2, p3

Definition at line 1563 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_closest_point()

vgl_point_3d<double> vgl_triangle_3d_closest_point ( const vgl_point_3d< double > &  q,
const vgl_point_3d< double > &  p1,
const vgl_point_3d< double > &  p2,
const vgl_point_3d< double > &  p3 
)

Compute the closest point on a triangle to a reference point.

The triangle is represented by its vertices p1, p2, p3.

Parameters
qThe reference point.
Returns
The closest point on the triangle. This may be inside the triangle, or it may be a point on one of the triangle edges.

Definition at line 1436 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_coincident_edges()

std::vector<std::pair<unsigned,unsigned> > vgl_triangle_3d_coincident_edges ( const vgl_point_3d< double > &  a_p1,
const vgl_point_3d< double > &  a_p2,
const vgl_point_3d< double > &  a_p3,
const vgl_point_3d< double > &  b_p1,
const vgl_point_3d< double > &  b_p2,
const vgl_point_3d< double > &  b_p3 
)

Check for coincident edges of triangles a and b.

Returns
a vector of the coincident edges

Definition at line 58 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_distance()

double vgl_triangle_3d_distance ( const vgl_point_3d< double > &  q,
const vgl_point_3d< double > &  p1,
const vgl_point_3d< double > &  p2,
const vgl_point_3d< double > &  p3 
)

Compute the distance to the closest point on a triangle from a reference point.

The triangle is represented by its vertices p1, p2, p3.

Parameters
qThe reference point.
Returns
The distance to the closest point on the triangle. (The closest point may be inside the triangle, or it may be a point on one of the triangle edges.)

Definition at line 1512 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_line_intersection()

vgl_triangle_3d_intersection_t vgl_triangle_3d_line_intersection ( const vgl_line_segment_3d< double > &  line,
const vgl_point_3d< double > &  p1,
const vgl_point_3d< double > &  p2,
const vgl_point_3d< double > &  p3,
vgl_point_3d< double > &  i_pnt,
bool  ignore_coplanar 
)

Compute the intersection point between the line segment and triangle.

The triangle is represented by its vertices p1, p2, p3

Returns
true if line intersects triangle

The triangle is represented by its vertices p1, p2, p3

Returns
intersection type

Definition at line 272 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_longest_side()

double vgl_triangle_3d_longest_side ( const vgl_point_3d< double > &  p1,
const vgl_point_3d< double > &  p2,
const vgl_point_3d< double > &  p3 
)
inline

Compute the longest side of the given triangle.

The triangle is represented by its vertices p1, p2, p3

Returns
length of the longest side

Definition at line 137 of file vgl_triangle_3d.h.

◆ vgl_triangle_3d_plane_intersection()

vgl_triangle_3d_intersection_t vgl_triangle_3d_plane_intersection ( const vgl_point_3d< double > &  p1,
const vgl_point_3d< double > &  p2,
const vgl_point_3d< double > &  p3,
const vgl_plane_3d< double > &  i_plane,
vgl_line_segment_3d< double > &  i_line 
)

Compute the line of intersection of the given triangle and plane.

The triangle is represented by its vertices p1, p2, p3

Returns
intersection type
Note
an intersection line is not defined (NaN) for a coplanar intersection

The triangle is represented by its vertices p1, p2, p3

Returns
intersection type
Note
an intersection line is not defined (vgl_vgl_nan) for a coplanar intersection

Definition at line 1342 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_shortest_side()

double vgl_triangle_3d_shortest_side ( const vgl_point_3d< double > &  p1,
const vgl_point_3d< double > &  p2,
const vgl_point_3d< double > &  p3 
)
inline

Compute the shortest side of the given triangle.

The triangle is represented by its vertices p1, p2, p3

Returns
length of the longest side

Definition at line 150 of file vgl_triangle_3d.h.

◆ vgl_triangle_3d_test_inside() [1/2]

bool vgl_triangle_3d_test_inside ( const vgl_point_3d< double > &  i_pnt,
const vgl_point_3d< double > &  p1,
const vgl_point_3d< double > &  p2,
const vgl_point_3d< double > &  p3 
)

Check if the given point is inside the triangle.

The triangle is represented by its vertices p1, p2, p3

Returns
true if point is inside

Definition at line 203 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_test_inside() [2/2]

bool vgl_triangle_3d_test_inside ( const vgl_point_3d< double > &  i_pnt,
const vgl_point_3d< double > &  p1,
const vgl_point_3d< double > &  p2,
const vgl_point_3d< double > &  p3,
double  coplanar_tolerance 
)

Check if the given point is inside the triangle.

The triangle is represented by its vertices p1, p2, p3

Returns
true if point is inside
Parameters
coplanar_toleranceis used to dismiss points because they are outside the plane. This doesn't widen the triangle, just thickens it.

The triangle is represented by its vertices p1, p2, p3

Returns
true if point is inside
Parameters
coplanar_toleranceused to dismiss points because they are outside the plane. This doesn't widen the triangle, just thickens it.

Definition at line 115 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_test_inside_simple()

bool vgl_triangle_3d_test_inside_simple ( const vgl_point_3d< double > &  i_pnt,
const vgl_point_3d< double > &  p1,
const vgl_point_3d< double > &  p2,
const vgl_point_3d< double > &  p3 
)

Check if point i_pnt is inside the triangle.

The triangle is represented by its vertices p1, p2, p3

Returns
true if point is inside
Note
this method uses the less efficient 'angles' method which requires 3 calls to acos()

Definition at line 218 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_triangle_coplanar()

bool vgl_triangle_3d_triangle_coplanar ( const vgl_point_3d< double > &  a_p1,
const vgl_point_3d< double > &  a_p2,
const vgl_point_3d< double > &  a_p3,
const vgl_point_3d< double > &  b_p1,
const vgl_point_3d< double > &  b_p2,
const vgl_point_3d< double > &  b_p3 
)

Check if the two triangles are coplanar.

The triangles are represented by their respective vertices a_p1, a_p2, a_p3 and b_p1, b_p2, b_p3

Definition at line 1525 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_triangle_intersection() [1/3]

vgl_triangle_3d_intersection_t vgl_triangle_3d_triangle_intersection ( const vgl_point_3d< double > &  a_p1,
const vgl_point_3d< double > &  a_p2,
const vgl_point_3d< double > &  a_p3,
const vgl_point_3d< double > &  b_p1,
const vgl_point_3d< double > &  b_p2,
const vgl_point_3d< double > &  b_p3 
)

Compute if the given triangles a and b intersect.

The triangles are represented by their respective vertices a_p1, a_p2, a_p3 and b_p1, b_p2, b_p3

Returns
intersection type

The triangle are represented by their respective vertices a_p1, a_p2, a_p3 and b_p1, b_p2, b_p3

Returns
intersection type

Definition at line 992 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_triangle_intersection() [2/3]

vgl_triangle_3d_intersection_t vgl_triangle_3d_triangle_intersection ( const vgl_point_3d< double > &  a_p1,
const vgl_point_3d< double > &  a_p2,
const vgl_point_3d< double > &  a_p3,
const vgl_point_3d< double > &  b_p1,
const vgl_point_3d< double > &  b_p2,
const vgl_point_3d< double > &  b_p3,
vgl_line_segment_3d< double > &  i_line 
)

Compute the intersection line of the given triangles.

See also
vgl_triangle_3d_triangle_intersection()
Note
an intersection line is not computed for a coplanar intersection

Definition at line 971 of file vgl_triangle_3d.cxx.

◆ vgl_triangle_3d_triangle_intersection() [3/3]

vgl_triangle_3d_intersection_t vgl_triangle_3d_triangle_intersection ( const vgl_point_3d< double > &  a_p1,
const vgl_point_3d< double > &  a_p2,
const vgl_point_3d< double > &  a_p3,
const vgl_point_3d< double > &  b_p1,
const vgl_point_3d< double > &  b_p2,
const vgl_point_3d< double > &  b_p3,
vgl_line_segment_3d< double > &  i_line,
unsigned &  i_line_point1_edge,
unsigned &  i_line_point2_edge 
)

compute the intersection line of the given triangles.

See also
vgl_triangle_3d_triangle_intersection()
Note
an intersection line is not computed for a coplanar intersection
Return values
i_line_point1_edgeA number [0-5] indicating which edge of the two triangles point1 of i_line lies on. 0 indicates [a_p1,a_p2], 1 - [a_p2,a_p3], 2 - [a_p3,a_p1], 3 - [b_p1,b_p2], 4 - [b_p2,b_p3], 5 - [b_p3,b_p1]
i_line_point2_edge.As i_line_point1_edge, but for the other end of the intersection.
Note
if i_line_point1_edge==i_line_point2_edge, this indicates that due to coplanarity, or some other corner case, there were more than two edges involved in the intersection boundaries. The returned edge is one of those edges.

compute the intersection line of the given triangles.

See also
vgl_triangle_3d_triangle_intersection()
Note
an intersection line is not computed for a coplanar intersection
Return values
i_line_point1_edgeA number [0-5] indicating which edge of the two triangles point1 of i_line lies on. 0 indicates [a_p1,a_p2], 1 - [a_p2,a_p3], 2 - [a_p3,a_p1], 3 - [b_p1,b_p2], 4 - [b_p2,b_p3], 5 - [b_p3,b_p1]
i_line_point2_edge.As i_line_point1_edge, but for the other end of the intersection.
Note
if i_line_point1_edge==i_line_point2_edge, this indicates that due to coplanarity, or some other corner case, there were more than two edges involved in the intersection boundaries. The returned edge is one of those edges.

Definition at line 404 of file vgl_triangle_3d.cxx.