MCPcopy Create free account
hub / github.com/dfranx/SHADERed / isPointInTriangle

Function isPointInTriangle

src/SHADERed/Objects/DebugInformation.cpp:317–329  ·  view source on GitHub ↗

helper functions */

Source from the content-addressed store, hash-verified

315
316/* helper functions */
317bool isPointInTriangle(glm::vec2 p, glm::vec2 p0, glm::vec2 p1, glm::vec2 p2)
318{
319 /* https://stackoverflow.com/questions/2049582/how-to-determine-if-a-point-is-in-a-2d-triangle#:~:text=A%20simple%20way%20is%20to,point%20is%20inside%20the%20triangle. */
320 float s = p0.y * p2.x - p0.x * p2.y + (p2.y - p0.y) * p.x + (p0.x - p2.x) * p.y;
321 float t = p0.x * p1.y - p0.y * p1.x + (p0.y - p1.y) * p.x + (p1.x - p0.x) * p.y;
322
323 if ((s < 0) != (t < 0))
324 return false;
325
326 float a = -p1.y * p2.x + p0.y * (p2.x - p1.x) + p0.x * (p1.y - p2.y) + p1.x * p2.y;
327
328 return a < 0 ? (s <= 0 && s + t >= a) : (s >= 0 && s + t <= a);
329}
330bool isPointOnLine(glm::vec2 p, glm::vec2 p0, glm::vec2 p1)
331{
332 float v = glm::distance(p0, p) + glm::distance(p, p1) - glm::distance(p0, p1);

Callers 1

ExecuteGeometryShaderMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected