File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -83,6 +83,11 @@ class Plane;
8383 */
8484 double area () const ;
8585
86+ /* ------------------------------------------------------------------------*/
87+ /* * \brief Computes the signed area of the triangle (works for triangles in the plane)
88+ */
89+ double signedArea () const ;
90+
8691 /* ------------------------------------------------------------------------*/
8792 /* * \brief Computes the angle (in rad) of the triangle, as seen by its first vertex
8893 */
Original file line number Diff line number Diff line change @@ -66,6 +66,17 @@ Triangle::~Triangle(){}
6666 return 0.5 * (v1.cross (v2)).norm ();
6767 }
6868 /* ----------------------------------------------------------------------------*/
69+ double Triangle::signedArea () const
70+ {
71+ Vector3d v1 = m_pnts[1 ] - m_pnts[0 ];
72+ Vector3d v2 = m_pnts[2 ] - m_pnts[0 ];
73+ Vector3d cross_prod = v1.cross (v2);
74+ if (cross_prod.Z () >= 0 )
75+ return 0.5 * cross_prod.norm ();
76+ else
77+ return -0.5 * cross_prod.norm ();
78+ }
79+ /* ----------------------------------------------------------------------------*/
6980 double Triangle::angle () const
7081 {
7182 Vector3d v1 = m_pnts[1 ] - m_pnts[0 ];
@@ -105,7 +116,7 @@ Point Triangle::getCircumcenter() const
105116 double yB = B.Y ();
106117 double xC = C.X ();
107118 double yC = C.Y ();
108- double S = area ();
119+ double S = signedArea ();
109120 double xO = ((xA*xA+yA*yA)*(yB-yC)-(xB*xB+yB*yB)*(yA-yC)+(xC*xC+yC*yC)*(yA-yB))*(1 ./(4 .*S));
110121 double yO = -((xA*xA+yA*yA)*(xB-xC)-(xB*xB+yB*yB)*(xA-xC)+(xC*xC+yC*yC)*(xA-xB))*(1 ./(4 .*S));
111122 math::Point Ctr (xO, yO, 0 .);
You can’t perform that action at this time.
0 commit comments