1 // This is brl/bbas/bmsh3d/bmsh3d_triangle.h
2 #ifndef bmsh3d_triangle_h_
3 #define bmsh3d_triangle_h_
4 //:
5 // \file
6 // \brief  Basic triangle geometric.
7 // \author Ming-Ching Chang (mcchang@lems.brown.edu)
8 // \date   May/31/2005
9 //
10 // \verbatim
11 //         Modify on Mar 07, 2007.
12 // \endverbatim
13 //
14 //-----------------------------------------------------------------------------
15 
16 #include <vgl/vgl_point_3d.h>
17 #include <vgl/vgl_vector_3d.h>
18 #include <vgl/vgl_distance.h>
19 #include "bmsh3d_dist.h"
20 #include "bmsh3d_fuzzy_boolean.h"
21 
22 //: return true for acute triangle or obtuse triangle.
23 //  the right triangle is treated as non-acute triangle.
bmsh3d_is_tri_non_acute(const vgl_point_3d<double> & v0,const vgl_point_3d<double> & v1,const vgl_point_3d<double> & v2)24 inline bool bmsh3d_is_tri_non_acute(const vgl_point_3d<double>& v0,
25                                     const vgl_point_3d<double>& v1,
26                                     const vgl_point_3d<double>& v2)
27 {
28   double dasq = bmsh3d_sqdist_3d (v0, v1);
29   double dbsq = bmsh3d_sqdist_3d (v1, v2);
30   double dcsq = bmsh3d_sqdist_3d (v0, v2);
31 
32   return bmsh3d_leq_m(dasq + dbsq, dcsq) ||
33          bmsh3d_leq_m(dbsq + dcsq, dasq) ||
34          bmsh3d_leq_m(dasq + dcsq, dbsq);
35 }
36 
bmsh3d_footpt_on_line(const vgl_point_3d<double> & P,const vgl_point_3d<double> & A,const vgl_point_3d<double> & B)37 inline bool bmsh3d_footpt_on_line(const vgl_point_3d<double>& P,
38                                   const vgl_point_3d<double>& A,
39                                   const vgl_point_3d<double>& B)
40 {
41   vgl_vector_3d<double> AP = P-A;
42   vgl_vector_3d<double> AB = B-A;
43   double l = vgl_distance (A, B);
44   double t = dot_product (AP, AB) / l;
45 
46   return 0<=t && t<=l;
47 }
48 
bmsh3d_footpt_on_line(const vgl_point_3d<double> & P,const vgl_point_3d<double> & A,const vgl_point_3d<double> & B,double & t,double & l)49 inline bool bmsh3d_footpt_on_line(const vgl_point_3d<double>& P,
50                                   const vgl_point_3d<double>& A,
51                                   const vgl_point_3d<double>& B,
52                                   double& t, double& l)
53 {
54   vgl_vector_3d<double> AP = P-A;
55   vgl_vector_3d<double> AB = B-A;
56   l = vgl_distance (A, B);
57   t = dot_product (AP, AB) / l;
58 
59   return 0<=t && t<=l;
60 }
61 
62 #endif // bmsh3d_triangle_h_
63