Recently in the work of leaf reconstruction, the construction of the Leaf tin algorithm will be used to 3-dimensional midpoint to the line of the distance equation, a beginning to think like a two-dimensional formula and so on, and then find a bit did not find, wrote a function, to share
Double dis_3d (Point a,point b,point s) {
double ab=sqrt (POW (a.x-b.x), 2.0) +pow ((A.Y-B.Y), 2.0) +pow ((A.Z-B.Z), 2.0) );
Double as=sqrt (POW (a.x-s.x), 2.0) +pow ((A.Y-S.Y), 2.0) +pow ((A.Z-S.Z), 2.0));
Double bs=sqrt (POW (s.x-b.x), 2.0) +pow ((S.Y-B.Y), 2.0) +pow ((S.Z-B.Z), 2.0));
Double cos_a= (POW (as,2.0) +pow (ab,2.0)-pow (bs,2.0))/(2*ab*as);
Double Sin_a=sqrt (1-pow (cos_a,2.0));
return as*sin_a;
}
The basic mathematical principle is to use the cosine theorem to find the angle, and then to find the sine, and then the high,
That is, the distance from the point to the line.