Created
May 12, 2015 00:47
-
-
Save ialhashim/39f9e2a439effa13d979 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/libigl/libigl/blob/master/include/igl/project_to_line.cpp | |
auto projectionOnSegment = [&](const Vector3 & p, const Vector3 & s, const Vector3 & d){ | |
Real px = p[0], py = p[1], pz = p[2]; | |
Real sx = s[0], sy = s[1], sz = s[2]; | |
Real dx = d[0], dy = d[1], dz = d[2]; | |
Real dms[3], smp[3]; | |
dms[0] = dx-sx; dms[1] = dy-sy; dms[2] = dz-sz; | |
Real v_sqrlen = dms[0]*dms[0] + dms[1]*dms[1] + dms[2]*dms[2]; assert(v_sqrlen != 0); | |
smp[0] = sx-px; smp[1] = sy-py; smp[2] = sz-pz; | |
t = -(dms[0]*smp[0]+dms[1]*smp[1]+dms[2]*smp[2])/v_sqrlen; | |
return t; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment