MCPcopy Create free account
hub / github.com/FreeFem/FreeFem-sources / isInsideTriangle

Function isInsideTriangle

plugin/seq/plotPDF.cpp:2056–2079  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2054 st << "c\n";
2055 }
2056 st << "S\n";
2057 } // k
2058 return;
2059}
2060
2061bool isInsideTriangle( const double px, const double py, const double *const vx, const double *const vy )
2062{
2063 // Find a, b \in \Real such that [px;py]-v0 = a (v1-v0) + b (v2-v0).
2064 // if (0 < a < 1) && (0 < b < 1) && (0 < a+b < 1), then p is inside triangle v0--v1--v2
2065
2066 // solve (v1x-v0x) * a + (v2x-v0x) * b = px-v0x
2067 // (v1y-v0y) * a + (v2y-v0y) * b = py-v0y
2068 const double EPS = 1e-10;
2069 const double m00 = vx[1] - vx[0];
2070 const double m01 = vx[2] - vx[0];
2071 const double rhs0 = px - vx[0];
2072
2073 const double m10 = vy[1] - vy[0];
2074 const double m11 = vy[2] - vy[0];
2075 const double rhs1 = py - vy[0];
2076
2077 const double det = m00*m11 - m01*m10;
2078 assert( fabs(det) > EPS );
2079
2080 const double a = ( m11 * rhs0 - m01 * rhs1) / det;
2081 const double b = (-m10 * rhs0 + m00 * rhs1) / det;
2082

Callers 3

trackParabolaCoreFunction · 0.85
trackEllipseFunction · 0.85
trackHyperbolaCoreFunction · 0.85

Calls 1

fabsFunction · 0.50

Tested by

no test coverage detected