用向量计算点到直线的距离
https://blog.csdn.net/tracing/article/details/46563383
https://learn.microsoft.com/en-us/previous-versions/ms969920(v=msdn.10)?redirectedfrom=MSDN
typedef struct tagVECTOR2D { double x; double y; } VECTOR2D, *PVECTOR2D; double vGetLengthOfNormal(PVECTOR2D a, PVECTOR2D b) { VECTOR2D c, vNormal; // //Obtain projection vector. // //c = ((a * b)/(|b|^2))*b // c.x = b->x * (vDotProduct(a, b)/vDotProduct(b, b)); c.y = b->y * (vDotProduct(a, b)/vDotProduct(b, b)); // //Obtain perpendicular projection : e = a - c // vSubtractVectors(a, &c, &vNormal); // //Fill PROJECTION structure with appropriate values. // return (vVectorMagnitude(&vNormal)); }
先求出向量a在b上的投影c
然后计算垂直投影e
然后再计算e的长度(模)