Defines | Functions
core/vgl/vgl_triangle_3d.cxx File Reference

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

#include "vgl_triangle_3d.h"
#include <vgl/vgl_distance.h>
#include <vgl/vgl_intersection.h>
#include <vgl/vgl_line_3d_2_points.h>
#include <vgl/vgl_plane_3d.h>
#include <vgl/vgl_point_3d.h>
#include <vgl/vgl_vector_3d.h>
#include <vgl/vgl_closest_point.h>
#include <vcl_limits.h>
#include <vcl_cassert.h>

Go to the source code of this file.

Defines

#define UINT_MAX   0xffffffffU

Functions

vcl_vector< vcl_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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 ration of a triangle.

Detailed Description

Some helpful functions when working with triangles.

Author:
Kieran O'Mahony
Date:
21 June 2007

Definition in file vgl_triangle_3d.cxx.


Define Documentation

#define UINT_MAX   0xffffffffU

Definition at line 373 of file vgl_triangle_3d.cxx.


Function Documentation

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 1538 of file vgl_triangle_3d.cxx.

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 ration of a triangle.

Compute the aspect ratio of a triangle.

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

Definition at line 1560 of file vgl_triangle_3d.cxx.

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 1433 of file vgl_triangle_3d.cxx.

vcl_vector<vcl_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 55 of file vgl_triangle_3d.cxx.

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 1509 of file vgl_triangle_3d.cxx.

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:
intersection type

Definition at line 269 of file vgl_triangle_3d.cxx.

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 (vgl_vgl_nan) for a coplanar intersection

Definition at line 1339 of file vgl_triangle_3d.cxx.

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_toleranceused to dismiss points because they are outside the plane. This doesn't widen the triangle, just thickens it.

Definition at line 112 of file vgl_triangle_3d.cxx.

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 200 of file vgl_triangle_3d.cxx.

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 215 of file vgl_triangle_3d.cxx.

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 1522 of file vgl_triangle_3d.cxx.

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.

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 401 of file vgl_triangle_3d.cxx.

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 968 of file vgl_triangle_3d.cxx.

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 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 989 of file vgl_triangle_3d.cxx.