[数学]计算点到线段的距离
Real PointDistanceToLine(Ogre::Vector3 Pos , Ogre::Vector3 begin, Ogre::Vector3 end)
{
Real k,b;
k=(begin.z - end.z)/(begin.x - end.x);
b=begin.z-k*begin.x;
Real s1,s2;
s1=abs(k*Pos.x-Pos.y+b);
s2=sqrt(k*k+1);
return s1/s2;
}
Real PointDistanceToLine(Ogre::Vector3 Pos , Ogre::Vector3 begin, Ogre::Vector3 end)
{
Real k,b;
k=(begin.z - end.z)/(begin.x - end.x);
b=begin.z-k*begin.x;
Real s1,s2;
s1=abs(k*Pos.x-Pos.y+b);
s2=sqrt(k*k+1);
return s1/s2;
}