Skip to content

Instantly share code, notes, and snippets.

@v3c70r
Created March 8, 2016 20:11
Show Gist options
  • Save v3c70r/9f682622d535f28d55b4 to your computer and use it in GitHub Desktop.
Save v3c70r/9f682622d535f28d55b4 to your computer and use it in GitHub Desktop.
static vec findNearestPoint(vector<vec> line1, vector<vec>line2)
{
//vec p_0 = {line1[0](0), line1[0](1), line1[0](2)};
//vec q_0 = {line2[0](0), line2[0](1), line2[0](2)};
vec p_0 = line1[0];
vec q_0 = line2[0];
vec u = line1[1];
vec v = line2[1];
vec w_0 = p_0 - q_0;
double s_c = (dot(u,v)*dot(v,w_0)-dot(u,w_0))/(1-dot(u,v)*dot(u,v));
double t_c = (dot(v,w_0)-dot(u,v)*dot(u, w_0))/(1-dot(u, v)*dot(u, v));
//cout<<"s_c="<<s_c<<endl;
vec p_s = q_0 + t_c * v;
vec q_c = p_0 + s_c * u;
return (p_s + q_c)/2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment