00001 #ifndef VGL_TRIANGLE_3D_H_
00002 #define VGL_TRIANGLE_3D_H_
00003
00004
00005
00006
00007
00008
00009 #include <vcl_algorithm.h>
00010 #include <vcl_utility.h>
00011 #include <vcl_cmath.h>
00012
00013 #include <vgl/vgl_line_segment_3d.h>
00014 #include <vgl/vgl_point_3d.h>
00015
00016 enum vgl_triangle_3d_intersection_t
00017 {
00018 None=0,
00019 Skew,
00020 Coplanar
00021 };
00022
00023
00024
00025 vcl_vector<vcl_pair<unsigned,unsigned> > vgl_triangle_3d_coincident_edges(
00026 const vgl_point_3d<double>& a_p1,
00027 const vgl_point_3d<double>& a_p2,
00028 const vgl_point_3d<double>& a_p3,
00029 const vgl_point_3d<double>& b_p1,
00030 const vgl_point_3d<double>& b_p2,
00031 const vgl_point_3d<double>& b_p3);
00032
00033
00034
00035
00036 bool vgl_triangle_3d_test_inside(
00037 const vgl_point_3d<double>& i_pnt,
00038 const vgl_point_3d<double>& p1,
00039 const vgl_point_3d<double>& p2,
00040 const vgl_point_3d<double>& p3);
00041
00042
00043
00044
00045
00046
00047 bool vgl_triangle_3d_test_inside(const vgl_point_3d<double>& i_pnt,
00048 const vgl_point_3d<double>& p1,
00049 const vgl_point_3d<double>& p2,
00050 const vgl_point_3d<double>& p3,
00051 double coplanar_tolerance );
00052
00053
00054
00055
00056
00057 bool vgl_triangle_3d_test_inside_simple(
00058 const vgl_point_3d<double>& i_pnt,
00059 const vgl_point_3d<double>& p1,
00060 const vgl_point_3d<double>& p2,
00061 const vgl_point_3d<double>& p3 );
00062
00063
00064
00065
00066
00067 vgl_triangle_3d_intersection_t vgl_triangle_3d_line_intersection(
00068 const vgl_line_segment_3d<double>& line,
00069 const vgl_point_3d<double>& p1,
00070 const vgl_point_3d<double>& p2,
00071 const vgl_point_3d<double>& p3,
00072 vgl_point_3d<double>& i_pnt,
00073 bool ignore_coplanar = false);
00074
00075
00076
00077
00078
00079 vgl_triangle_3d_intersection_t vgl_triangle_3d_triangle_intersection(
00080 const vgl_point_3d<double>& a_p1,
00081 const vgl_point_3d<double>& a_p2,
00082 const vgl_point_3d<double>& a_p3,
00083 const vgl_point_3d<double>& b_p1,
00084 const vgl_point_3d<double>& b_p2,
00085 const vgl_point_3d<double>& b_p3);
00086
00087
00088
00089
00090 vgl_triangle_3d_intersection_t vgl_triangle_3d_triangle_intersection(
00091 const vgl_point_3d<double>& a_p1,
00092 const vgl_point_3d<double>& a_p2,
00093 const vgl_point_3d<double>& a_p3,
00094 const vgl_point_3d<double>& b_p1,
00095 const vgl_point_3d<double>& b_p2,
00096 const vgl_point_3d<double>& b_p3,
00097 vgl_line_segment_3d<double>& i_line);
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 vgl_triangle_3d_intersection_t vgl_triangle_3d_triangle_intersection(
00110 const vgl_point_3d<double>& a_p1,
00111 const vgl_point_3d<double>& a_p2,
00112 const vgl_point_3d<double>& a_p3,
00113 const vgl_point_3d<double>& b_p1,
00114 const vgl_point_3d<double>& b_p2,
00115 const vgl_point_3d<double>& b_p3,
00116 vgl_line_segment_3d<double>& i_line,
00117 unsigned &i_line_point1_edge,
00118 unsigned &i_line_point2_edge);
00119
00120
00121
00122
00123
00124 vgl_triangle_3d_intersection_t vgl_triangle_3d_plane_intersection(
00125 const vgl_point_3d<double>& p1,
00126 const vgl_point_3d<double>& p2,
00127 const vgl_point_3d<double>& p3,
00128 const vgl_plane_3d<double>& i_plane,
00129 vgl_line_segment_3d<double>& i_line);
00130
00131
00132
00133
00134 inline double vgl_triangle_3d_longest_side(
00135 const vgl_point_3d<double>& p1,
00136 const vgl_point_3d<double>& p2,
00137 const vgl_point_3d<double>& p3)
00138 {
00139 double side_length_max = vcl_max( (p2 - p1).sqr_length(), (p3 - p2).sqr_length());
00140 side_length_max = vcl_max( side_length_max, (p1 - p3).sqr_length());
00141 return vcl_sqrt(side_length_max);
00142 }
00143
00144
00145
00146
00147 inline double vgl_triangle_3d_shortest_side(
00148 const vgl_point_3d<double>& p1,
00149 const vgl_point_3d<double>& p2,
00150 const vgl_point_3d<double>& p3)
00151 {
00152 double side_length_min = vcl_min( (p2 - p1).sqr_length(), (p3 - p2).sqr_length());
00153 side_length_min = vcl_min( side_length_min, (p1 - p3).sqr_length());
00154 return vcl_sqrt(side_length_min);
00155 }
00156
00157
00158
00159
00160
00161 vgl_point_3d<double> vgl_triangle_3d_closest_point(
00162 const vgl_point_3d<double>& q,
00163 const vgl_point_3d<double>& p1,
00164 const vgl_point_3d<double>& p2,
00165 const vgl_point_3d<double>& p3);
00166
00167
00168
00169
00170
00171 double vgl_triangle_3d_distance(
00172 const vgl_point_3d<double>& q,
00173 const vgl_point_3d<double>& p1,
00174 const vgl_point_3d<double>& p2,
00175 const vgl_point_3d<double>& p3);
00176
00177
00178
00179
00180 bool vgl_triangle_3d_triangle_coplanar(
00181 const vgl_point_3d<double>& a_p1,
00182 const vgl_point_3d<double>& a_p2,
00183 const vgl_point_3d<double>& a_p3,
00184 const vgl_point_3d<double>& b_p1,
00185 const vgl_point_3d<double>& b_p2,
00186 const vgl_point_3d<double>& b_p3);
00187
00188
00189
00190
00191
00192 double vgl_triangle_3d_area(
00193 const vgl_point_3d<double> &p0,
00194 const vgl_point_3d<double> &p1,
00195 const vgl_point_3d<double> &p2 );
00196
00197
00198
00199
00200 double vgl_triangle_3d_aspect_ratio(
00201 const vgl_point_3d<double> &p0,
00202 const vgl_point_3d<double> &p1,
00203 const vgl_point_3d<double> &p2 );
00204
00205 #endif // VGL_TRIANGLE_3D_H_