Inserting a find_location() function
Closed this issue · 3 comments
mllobera commented
I have the following function that could be inserted into triangulator.cpp and *.h but I am having difficulties updating these files in order to extend your bindings to include this possibility. I was wondering if you could help me achieve this.
Here are the functions,
// Private Function to check if a point is inside a triangle using barycentric coordinates by M.Llobera
bool PointInTriangle(const glm::ivec2 p, const glm::ivec2 a, const glm::ivec2 b, const glm::ivec2 c) const {
auto sign = [](const glm::ivec2 p1, const glm::ivec2 p2, const glm::ivec2 p3) {
return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);
};
bool d1 = sign(p, a, b) < 0.0f;
bool d2 = sign(p, b, c) < 0.0f;
bool d3 = sign(p, c, a) < 0.0f;
return ((d1 == d2) && (d2 == d3));
}
// Public function to triangle contianing point pt by M.Llobera
int locatePoint(const glm::ivec2 pt) const {
for (int i = 0; i < m_Queue.size(); ++i) {
const int t = m_Queue[i];
const int e0 = t * 3;
const int e1 = e0 + 1;
const int e2 = e0 + 2;
const int p0 = m_Triangles[e0];
const int p1 = m_Triangles[e1];
const int p2 = m_Triangles[e2];
const glm::ivec2 a = m_Points[p0];
const glm::ivec2 b = m_Points[p1];
const glm::ivec2 c = m_Points[p2];
if (PointInTriangle(pt, a, b, c)) {
return t;
}
}
return -1; // Point is not inside any triangle
}
kylebarron commented
triangulator.cpp
is vendored from https://github.com/fogleman/hmm, so any changes would need to be made upstream there.
mllobera commented
Thanks Kyle,
I will propose this to the creator of hmm
…On Thu, Dec 14, 2023 at 10:08 AM Kyle Barron ***@***.***> wrote:
triangulator.cpp is vendored from https://github.com/fogleman/hmm
<https://urldefense.com/v3/__https://github.com/fogleman/hmm__;!!K-Hz7m0Vt54!nV5XPBRfXFEV98b-sgX9rFIoUfbKNxFYTxJpGfQ5ErnrAwK17pxsqQWDfdVmQGFSIojHSaTEFrPhE8843IEn1Bo$>,
so any changes would need to be made upstream there.
—
Reply to this email directly, view it on GitHub
<https://urldefense.com/v3/__https://github.com/kylebarron/pydelatin/issues/32*issuecomment-1856345694__;Iw!!K-Hz7m0Vt54!nV5XPBRfXFEV98b-sgX9rFIoUfbKNxFYTxJpGfQ5ErnrAwK17pxsqQWDfdVmQGFSIojHSaTEFrPhE884ugywzSY$>,
or unsubscribe
<https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AANCY3U4BLUUHONMSHVKZR3YJM6CBAVCNFSM6AAAAABAUDXIFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJWGM2DKNRZGQ__;!!K-Hz7m0Vt54!nV5XPBRfXFEV98b-sgX9rFIoUfbKNxFYTxJpGfQ5ErnrAwK17pxsqQWDfdVmQGFSIojHSaTEFrPhE8842WECOHI$>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
___________________
Marcos Llobera
Assoc. Prof. in Anthropology
Digital Archaeology Research Lab (DigAR Lab <https://www.digarlab.uw.edu/>)
University of Washington
pronouns: *he/his/him*
kylebarron commented
No worries, I'll close this here